aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_caret.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-07-09 20:23:41 -0400
committerDavid Robillard <d@drobilla.net>2022-01-13 23:03:53 -0500
commitbf72cc408db5244881143619236aee20156f4ffd (patch)
treed8f12781c8050e2ee9c0e9d83488838968480f00 /test/test_caret.c
parenta1c18e5585a1b3edbe62f53e768d270e54e4cac5 (diff)
downloadserd-bf72cc408db5244881143619236aee20156f4ffd.tar.gz
serd-bf72cc408db5244881143619236aee20156f4ffd.tar.bz2
serd-bf72cc408db5244881143619236aee20156f4ffd.zip
Add SerdCaret
Diffstat (limited to 'test/test_caret.c')
-rw-r--r--test/test_caret.c60
1 files changed, 60 insertions, 0 deletions
diff --git a/test/test_caret.c b/test/test_caret.c
new file mode 100644
index 00000000..3683a458
--- /dev/null
+++ b/test/test_caret.c
@@ -0,0 +1,60 @@
+/*
+ Copyright 2019-2020 David Robillard <d@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(SERD_STRING("node"));
+ SerdCaret* const caret = serd_caret_new(node, 46, 2);
+
+ assert(serd_caret_equals(caret, caret));
+ assert(serd_caret_name(caret) == node);
+ assert(serd_caret_line(caret) == 46);
+ assert(serd_caret_column(caret) == 2);
+
+ SerdCaret* const copy = serd_caret_copy(caret);
+
+ assert(serd_caret_equals(caret, copy));
+ assert(!serd_caret_copy(NULL));
+
+ SerdNode* const other_node = serd_new_string(SERD_STRING("other"));
+ SerdCaret* const other_file = serd_caret_new(other_node, 46, 2);
+ SerdCaret* const other_line = serd_caret_new(node, 47, 2);
+ SerdCaret* const other_col = serd_caret_new(node, 46, 3);
+
+ assert(!serd_caret_equals(caret, other_file));
+ assert(!serd_caret_equals(caret, other_line));
+ assert(!serd_caret_equals(caret, other_col));
+ assert(!serd_caret_equals(caret, NULL));
+ assert(!serd_caret_equals(NULL, caret));
+
+ serd_caret_free(other_col);
+ serd_caret_free(other_line);
+ serd_caret_free(other_file);
+ serd_node_free(other_node);
+ serd_caret_free(copy);
+ serd_caret_free(caret);
+ serd_node_free(node);
+
+ return 0;
+}