]> www.git.momoyon.org Git - commonlib.git/commitdiff
[tests] New test string_view.c
authorahmedsamyh <ahmedsamyh10@gmail.com>
Fri, 28 Feb 2025 05:55:15 +0000 (10:55 +0500)
committerahmedsamyh <ahmedsamyh10@gmail.com>
Fri, 28 Feb 2025 05:57:19 +0000 (10:57 +0500)
commonlib.h
tests/string_view.c [new file with mode: 0644]
tests/string_view.code.expected [new file with mode: 0644]
tests/string_view.err.expected [new file with mode: 0644]
tests/string_view.out.expected [new file with mode: 0644]

index 357136954dcdc6b0d513a899f093715272ac1e02..916ac3cdcfcb1edc51576c58d3dbd68f1df4f3b9 100644 (file)
@@ -495,7 +495,7 @@ c_String_view c_sv_lpop_until_string(c_String_view* sv, const char *string) {
 \r
     while (sv->count > string_len) {\r
         bool matched = true;\r
-        for (int i = 0; i < string_len; ++i) {\r
+        for (size_t i = 0; i < string_len; ++i) {\r
             if (sv->data[i] != string[i]) matched = false;\r
         }\r
         if (matched) break;\r
diff --git a/tests/string_view.c b/tests/string_view.c
new file mode 100644 (file)
index 0000000..3815616
--- /dev/null
@@ -0,0 +1,26 @@
+#define COMMONLIB_IMPLEMENTATION
+#define COMMONLIB_REMOVE_PREFIX
+#include "../commonlib.h"
+
+int main(void) {
+
+    String_view main = SV("Hello, World!");
+
+    String_view multiline_comment = SV("/*Blah Blah\nBlah Blah2\nTHis is the end*/THIS SHOULD NOT BE VISIBLE");
+
+    String_view mc = sv_lpop_until_string(&multiline_comment, "*/");
+
+    String_view a = sv_lpop_until_char(&main, ' ');
+
+    sv_lremove(&main, 1);
+
+    String_view b = main;
+
+    log_info("main: '"SV_FMT"'", SV_ARG(main));
+    log_info("a: '"SV_FMT"'", SV_ARG(a));
+    log_info("b: '"SV_FMT"'", SV_ARG(b));
+
+    log_info("mc: '"SV_FMT"'", SV_ARG(mc));
+
+    return 0;
+}
diff --git a/tests/string_view.code.expected b/tests/string_view.code.expected
new file mode 100644 (file)
index 0000000..c227083
--- /dev/null
@@ -0,0 +1 @@
+0
\ No newline at end of file
diff --git a/tests/string_view.err.expected b/tests/string_view.err.expected
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/string_view.out.expected b/tests/string_view.out.expected
new file mode 100644 (file)
index 0000000..6c289a1
--- /dev/null
@@ -0,0 +1,6 @@
+[INFO] main: 'World!'
+[INFO] a: 'Hello,'
+[INFO] b: 'World!'
+[INFO] mc: '/*Blah Blah
+Blah Blah2
+THis is the end'