aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 22:15:53 +0200
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit6a91bfca72fc2cfd7ba1002174475d71e35b2969 (patch)
treed1689b03faf96f58ac4c7ca9081a600491d09a02 /tests
parent93e54363f5ae251acee94051f77305f60f0158c8 (diff)
downloadserd-6a91bfca72fc2cfd7ba1002174475d71e35b2969.tar.gz
serd-6a91bfca72fc2cfd7ba1002174475d71e35b2969.tar.bz2
serd-6a91bfca72fc2cfd7ba1002174475d71e35b2969.zip
Add SerdCursor to public API
Diffstat (limited to 'tests')
-rw-r--r--tests/cursor_test.c59
-rw-r--r--tests/free_null_test.c1
-rw-r--r--tests/read_chunk_test.c3
-rw-r--r--tests/serd_test.c3
4 files changed, 64 insertions, 2 deletions
diff --git a/tests/cursor_test.c b/tests/cursor_test.c
new file mode 100644
index 00000000..d9e174ff
--- /dev/null
+++ b/tests/cursor_test.c
@@ -0,0 +1,59 @@
+/*
+ Copyright 2019-2020 David Robillard <http://drobilla.net>
+
+ Permission to use, copy, modify, and/or distribute this software for any
+ purpose with or without fee is hereby granted, provided that the above
+ copyright notice and this permission notice appear in all copies.
+
+ THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#undef NDEBUG
+
+#include "serd/serd.h"
+
+#include <assert.h>
+#include <stddef.h>
+
+int
+main(void)
+{
+ SerdNode* const node = serd_new_string("node");
+ SerdCursor* const cursor = serd_cursor_new(node, 46, 2);
+
+ assert(serd_cursor_name(cursor) == node);
+ assert(serd_cursor_line(cursor) == 46);
+ assert(serd_cursor_column(cursor) == 2);
+
+ SerdCursor* const copy = serd_cursor_copy(cursor);
+
+ assert(serd_cursor_equals(cursor, copy));
+ assert(!serd_cursor_copy(NULL));
+
+ SerdNode* const other_node = serd_new_string("other");
+ SerdCursor* const other_file = serd_cursor_new(other_node, 46, 2);
+ SerdCursor* const other_line = serd_cursor_new(node, 47, 2);
+ SerdCursor* const other_col = serd_cursor_new(node, 46, 3);
+
+ assert(!serd_cursor_equals(cursor, other_file));
+ assert(!serd_cursor_equals(cursor, other_line));
+ assert(!serd_cursor_equals(cursor, other_col));
+ assert(!serd_cursor_equals(cursor, NULL));
+ assert(!serd_cursor_equals(NULL, cursor));
+
+ serd_cursor_free(other_col);
+ serd_cursor_free(other_line);
+ serd_cursor_free(other_file);
+ serd_node_free(other_node);
+ serd_cursor_free(copy);
+ serd_cursor_free(cursor);
+ serd_node_free(node);
+
+ return 0;
+}
diff --git a/tests/free_null_test.c b/tests/free_null_test.c
index 08f2b513..40f72ba7 100644
--- a/tests/free_null_test.c
+++ b/tests/free_null_test.c
@@ -29,6 +29,7 @@ main(void)
serd_env_free(NULL);
serd_reader_free(NULL);
serd_writer_free(NULL);
+ serd_cursor_free(NULL);
return 0;
}
diff --git a/tests/read_chunk_test.c b/tests/read_chunk_test.c
index 7abd865f..6efdc37f 100644
--- a/tests/read_chunk_test.c
+++ b/tests/read_chunk_test.c
@@ -88,7 +88,8 @@ main(void)
"eg:s2 eg:p1 eg:o1 ;\n"
" eg:p2 eg:o2 .\n"
"eg:s3 eg:p1 eg:o1 .\n"
- "eg:s4 eg:p1 [ eg:p3 eg:o1 ] .\n"));
+ "eg:s4 eg:p1 [ eg:p3 eg:o1 ] .\n",
+ NULL));
assert(!serd_reader_read_chunk(reader) && n_prefix == 1);
assert(!serd_reader_read_chunk(reader) && n_base == 1);
diff --git a/tests/serd_test.c b/tests/serd_test.c
index a05606a3..786c92f3 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -214,7 +214,8 @@ test_read_string(void)
assert(!serd_reader_start_string(
reader,
"<http://example.org/s> <http://example.org/p> "
- "<http://example.org/o> ."));
+ "<http://example.org/o> .",
+ NULL));
assert(!serd_reader_read_document(reader));
assert(rt->n_statements == 1);