about summary refs log tree commit diff stats
path: root/tests/test_parser.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-07-14 00:46:56 +0100
committerJames Booth <boothj5@gmail.com>2013-07-14 00:46:56 +0100
commite7478d8cb8c55db91628a059ff9f1065bfb9cf0e (patch)
treee80ad355f954e6f6a8051dc085bc2f0405d2827f /tests/test_parser.c
parent4d35031cb077a3aa03620d9372747dd69229b7da (diff)
downloadprofani-tty-e7478d8cb8c55db91628a059ff9f1065bfb9cf0e.tar.gz
Added parser tests
Diffstat (limited to 'tests/test_parser.c')
-rw-r--r--tests/test_parser.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/tests/test_parser.c b/tests/test_parser.c
index 58e3f3e7..e442baee 100644
--- a/tests/test_parser.c
+++ b/tests/test_parser.c
@@ -279,6 +279,124 @@ parse_cmd_freetext_with_many_quoted_and_many_spaces(void)
     assert_string_equals("and heres the free text", result[2]);
     g_strfreev(result);
 }
+
+void
+count_one_token(void)
+{
+    char *inp = "one";
+    int result = count_tokens(inp);
+
+    assert_int_equals(1, result);
+}
+
+void
+count_one_token_quoted_no_whitespace(void)
+{
+    char *inp = "\"one\"";
+    int result = count_tokens(inp);
+
+    assert_int_equals(1, result);
+}
+
+void
+count_one_token_quoted_with_whitespace(void)
+{
+    char *inp = "\"one two\"";
+    int result = count_tokens(inp);
+
+    assert_int_equals(1, result);
+}
+
+void
+count_two_tokens(void)
+{
+    char *inp = "one two";
+    int result = count_tokens(inp);
+
+    assert_int_equals(2, result);
+}
+
+void
+count_two_tokens_first_quoted(void)
+{
+    char *inp = "\"one and\" two";
+    int result = count_tokens(inp);
+
+    assert_int_equals(2, result);
+}
+
+void
+count_two_tokens_second_quoted(void)
+{
+    char *inp = "one \"two and\"";
+    int result = count_tokens(inp);
+
+    assert_int_equals(2, result);
+}
+
+void
+count_two_tokens_both_quoted(void)
+{
+    char *inp = "\"one and then\" \"two and\"";
+    int result = count_tokens(inp);
+
+    assert_int_equals(2, result);
+}
+
+void
+get_first_of_one(void)
+{
+    char *inp = "one";
+    char *result = get_start(inp, 2);
+
+    assert_string_equals("one", result);
+}
+
+void
+get_first_of_two(void)
+{
+    char *inp = "one two";
+    char *result = get_start(inp, 2);
+
+    assert_string_equals("one ", result);
+}
+
+void
+get_first_two_of_three(void)
+{
+    char *inp = "one two three";
+    char *result = get_start(inp, 3);
+
+    assert_string_equals("one two ", result);
+}
+
+void
+get_first_two_of_three_first_quoted(void)
+{
+    char *inp = "\"one\" two three";
+    char *result = get_start(inp, 3);
+
+    assert_string_equals("\"one\" two ", result);
+}
+
+void
+get_first_two_of_three_second_quoted(void)
+{
+    char *inp = "one \"two\" three";
+    char *result = get_start(inp, 3);
+
+    assert_string_equals("one \"two\" ", result);
+}
+
+void
+get_first_two_of_three_first_and_second_quoted(void)
+{
+    char *inp = "\"one\" \"two\" three";
+    char *result = get_start(inp, 3);
+
+    assert_string_equals("\"one\" \"two\" ", result);
+}
+
 void
 register_parser_tests(void)
 {
@@ -307,4 +425,17 @@ register_parser_tests(void)
     TEST(parse_cmd_freetext_with_quoted_and_space);
     TEST(parse_cmd_freetext_with_quoted_and_many_spaces);
     TEST(parse_cmd_freetext_with_many_quoted_and_many_spaces);
+    TEST(count_one_token);
+    TEST(count_one_token_quoted_no_whitespace);
+    TEST(count_one_token_quoted_with_whitespace);
+    TEST(count_two_tokens);
+    TEST(count_two_tokens_first_quoted);
+    TEST(count_two_tokens_second_quoted);
+    TEST(count_two_tokens_both_quoted);
+    TEST(get_first_of_one);
+    TEST(get_first_of_two);
+    TEST(get_first_two_of_three);
+    TEST(get_first_two_of_three_first_quoted);
+    TEST(get_first_two_of_three_second_quoted);
+    TEST(get_first_two_of_three_first_and_second_quoted);
 }