1 #include <stic.h>
2
3 #include <stdlib.h> /* free() */
4
5 #include "../../src/engine/functions.h"
6 #include "../../src/engine/parsing.h"
7 #include "../../src/engine/var.h"
8
9 #include "asserts.h"
10
11 static var_t dummy(const call_info_t *call_info);
12
TEST(empty_fail)13 TEST(empty_fail)
14 {
15 ASSERT_FAIL("", PE_INVALID_EXPRESSION);
16 }
17
TEST(non_quoted_fail)18 TEST(non_quoted_fail)
19 {
20 ASSERT_FAIL("b", PE_INVALID_EXPRESSION);
21 }
22
TEST(double_dot_fail)23 TEST(double_dot_fail)
24 {
25 ASSERT_FAIL("'a'..'b'", PE_INVALID_EXPRESSION);
26 }
27
TEST(starts_with_dot_fail)28 TEST(starts_with_dot_fail)
29 {
30 ASSERT_FAIL(".'b'", PE_INVALID_EXPRESSION);
31 }
32
TEST(ends_with_dot_fail)33 TEST(ends_with_dot_fail)
34 {
35 ASSERT_FAIL("'a'.", PE_INVALID_EXPRESSION);
36 }
37
TEST(fail_position_correct)38 TEST(fail_position_correct)
39 {
40 ASSERT_FAIL("'b' c", PE_INVALID_EXPRESSION);
41 assert_string_equal("'b' c", get_last_position());
42
43 ASSERT_FAIL("a b", PE_INVALID_EXPRESSION);
44 assert_string_equal("a b", get_last_position());
45 }
46
TEST(spaces_and_fail_position_correct)47 TEST(spaces_and_fail_position_correct)
48 {
49 ASSERT_FAIL(" 'b' c", PE_INVALID_EXPRESSION);
50 assert_string_equal("'b' c", get_last_position());
51
52 ASSERT_FAIL(" a b", PE_INVALID_EXPRESSION);
53 assert_string_equal("a b", get_last_position());
54 }
55
TEST(nothing_but_comment)56 TEST(nothing_but_comment)
57 {
58 ASSERT_FAIL("\"", PE_MISSING_QUOTE);
59 ASSERT_FAIL("\" this is a comment", PE_MISSING_QUOTE);
60 ASSERT_FAIL(" \"this is a comment", PE_MISSING_QUOTE);
61 ASSERT_FAIL(" \"", PE_MISSING_QUOTE);
62 }
63
TEST(expression_and_comment)64 TEST(expression_and_comment)
65 {
66 ASSERT_OK("1\"", "1");
67 ASSERT_OK("'str'\" this is a comment", "str");
68 ASSERT_OK(" 1 && 0 \"this is a comment", "0");
69
70 ASSERT_FAIL(" + \"", PE_MISSING_QUOTE);
71 ASSERT_FAIL(" 4 || \"", PE_MISSING_QUOTE);
72 }
73
TEST(priority_of_operators)74 TEST(priority_of_operators)
75 {
76 ASSERT_OK("1.'0' + 1 > 10 && 1 + 2 != 0 || +0 == -3 + 2 && 0", "1");
77 }
78
TEST(state_is_reset_on_each_parsing)79 TEST(state_is_reset_on_each_parsing)
80 {
81 ASSERT_FAIL("1 1", PE_INVALID_EXPRESSION);
82 assert_true(is_prev_token_whitespace());
83 ASSERT_FAIL("", PE_INVALID_EXPRESSION);
84 assert_false(is_prev_token_whitespace());
85
86 static const function_t function_a = { "a", "adescr", {1,1}, &dummy };
87 assert_success(function_register(&function_a));
88
89 ASSERT_FAIL("a('a'", PE_INVALID_EXPRESSION);
90 assert_int_equal(VTYPE_ERROR, get_parsing_result().type);
91
92 function_reset_all();
93 }
94
95 static var_t
dummy(const call_info_t * call_info)96 dummy(const call_info_t *call_info)
97 {
98 return var_from_str("");
99 }
100
101 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */
102 /* vim: set cinoptions+=t0 filetype=c : */
103