aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cursor_test.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-06-03 22:15:53 +0200
committerDavid Robillard <d@drobilla.net>2019-04-13 19:15:32 +0200
commitd77ae556562490d6ce70fed690eca69a18ee4c46 (patch)
treeb1be64c2ce33e7c6fe217503fd173091829133b0 /tests/cursor_test.c
parent1cfecadf30286bb146a9f60154dc9d4e48f8d1cb (diff)
downloadserd-d77ae556562490d6ce70fed690eca69a18ee4c46.tar.gz
serd-d77ae556562490d6ce70fed690eca69a18ee4c46.tar.bz2
serd-d77ae556562490d6ce70fed690eca69a18ee4c46.zip
Add SerdCursor to public API
Diffstat (limited to 'tests/cursor_test.c')
-rw-r--r--tests/cursor_test.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/cursor_test.c b/tests/cursor_test.c
new file mode 100644
index 00000000..243ce5aa
--- /dev/null
+++ b/tests/cursor_test.c
@@ -0,0 +1,58 @@
+/*
+ Copyright 2019 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_get_name(cursor) == node);
+ assert(serd_cursor_get_line(cursor) == 46);
+ assert(serd_cursor_get_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_cursor_free(copy);
+ serd_cursor_free(cursor);
+ serd_node_free(node);
+
+ return 0;
+}