@@ -6,6 +6,7 @@ using namespace attwoodn::expression_tree;
66
77struct test_fixture {
88 std::string some_string;
9+ const std::string some_const_string = " this IS 4 T3s7 $tRing " ;
910 char * some_char_ptr;
1011};
1112
@@ -21,13 +22,140 @@ int main(int argc, char** argv) {
2122
2223void test_string_evaluation () {
2324 test_fixture fixture;
24- fixture.some_string = " hello world!" ;
2525
26- auto node = make_expr (&test_fixture::some_string, &op::equals, std::string (" hello world!" ));
27- assert (node->evaluate (fixture));
26+ // test const string
27+ {
28+ // test equals
29+ {
30+ auto expr1 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" hello world!" ));
31+ assert (!expr1->evaluate (fixture));
32+
33+ auto expr2 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" h" ));
34+ assert (!expr2->evaluate (fixture));
35+
36+ auto expr3 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" t" ));
37+ assert (!expr3->evaluate (fixture));
38+
39+ auto expr4 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" this " ));
40+ assert (!expr4->evaluate (fixture));
41+
42+ auto expr5 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" this IS 4 T3s7 $tRing " ));
43+ assert (!expr5->evaluate (fixture));
44+
45+ auto expr6 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" this IS 4 T3s7 $tRing" ));
46+ assert (!expr6->evaluate (fixture));
47+
48+ auto expr7 = make_expr (&test_fixture::some_const_string, &op::equals, std::string (" this IS 4 T3s7 $tRing " ));
49+ assert (expr7->evaluate (fixture));
50+
51+ auto expr8 = make_expr (&test_fixture::some_const_string, &op::equals, fixture.some_const_string );
52+ assert (expr8->evaluate (fixture));
53+ }
54+
55+ // test not_equals
56+ {
57+ auto expr1 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" hello world!" ));
58+ assert (expr1->evaluate (fixture));
59+
60+ auto expr2 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" h" ));
61+ assert (expr2->evaluate (fixture));
62+
63+ auto expr3 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" t" ));
64+ assert (expr3->evaluate (fixture));
65+
66+ auto expr4 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" this " ));
67+ assert (expr4->evaluate (fixture));
68+
69+ auto expr5 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" this IS 4 T3s7 $tRing " ));
70+ assert (expr5->evaluate (fixture));
71+
72+ auto expr6 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" this IS 4 T3s7 $tRing" ));
73+ assert (expr6->evaluate (fixture));
74+
75+ auto expr7 = make_expr (&test_fixture::some_const_string, &op::not_equals, std::string (" this IS 4 T3s7 $tRing " ));
76+ assert (!expr7->evaluate (fixture));
77+
78+ auto expr8 = make_expr (&test_fixture::some_const_string, &op::not_equals, fixture.some_const_string );
79+ assert (!expr8->evaluate (fixture));
80+ }
81+
82+ // test less_than
83+ {
84+ auto expr1 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" u" ));
85+ assert (expr1->evaluate (fixture));
86+
87+ auto expr2 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" z" ));
88+ assert (expr2->evaluate (fixture));
89+
90+ auto expr3 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" this IS 4 T3s7 $tRing " ));
91+ assert (expr3->evaluate (fixture));
92+
93+ auto expr4 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" 1234567890" ));
94+ assert (!expr4->evaluate (fixture));
95+
96+ auto expr5 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" A" ));
97+ assert (!expr5->evaluate (fixture));
2898
29- fixture.some_string = " hey, world!" ;
30- assert (!node->evaluate (fixture));
99+ auto expr6 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" this " ));
100+ assert (!expr6->evaluate (fixture));
101+
102+ auto expr7 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" stuff" ));
103+ assert (!expr7->evaluate (fixture));
104+
105+ auto expr8 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" abcdefghijklmnopqrstuvwxyz" ));
106+ assert (!expr8->evaluate (fixture));
107+
108+ auto expr9 = make_expr (&test_fixture::some_const_string, &op::less_than, std::string (" this IS 4 T3s7 $tRing " ));
109+ assert (!expr9->evaluate (fixture));
110+
111+ auto expr10 = make_expr (&test_fixture::some_const_string, &op::less_than, fixture.some_const_string );
112+ assert (!expr10->evaluate (fixture));
113+ }
114+
115+ // test greater_than
116+ {
117+ auto expr1 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" u" ));
118+ assert (!expr1->evaluate (fixture));
119+
120+ auto expr2 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" z" ));
121+ assert (!expr2->evaluate (fixture));
122+
123+ auto expr3 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" this IS 4 T3s7 $tRing " ));
124+ assert (!expr3->evaluate (fixture));
125+
126+ auto expr4 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" 1234567890" ));
127+ assert (expr4->evaluate (fixture));
128+
129+ auto expr5 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" A" ));
130+ assert (expr5->evaluate (fixture));
131+
132+ auto expr6 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" this " ));
133+ assert (expr6->evaluate (fixture));
134+
135+ auto expr7 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" stuff" ));
136+ assert (expr7->evaluate (fixture));
137+
138+ auto expr8 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" abcdefghijklmnopqrstuvwxyz" ));
139+ assert (expr8->evaluate (fixture));
140+
141+ auto expr9 = make_expr (&test_fixture::some_const_string, &op::greater_than, std::string (" this IS 4 T3s7 $tRing " ));
142+ assert (!expr9->evaluate (fixture));
143+
144+ auto expr10 = make_expr (&test_fixture::some_const_string, &op::greater_than, fixture.some_const_string );
145+ assert (!expr10->evaluate (fixture));
146+ }
147+ }
148+
149+ // test non-const string
150+ {
151+ fixture.some_string = " hello world!" ;
152+
153+ auto node = make_expr (&test_fixture::some_string, &op::equals, std::string (" hello world!" ));
154+ assert (node->evaluate (fixture));
155+
156+ fixture.some_string = " hey, world!" ;
157+ assert (!node->evaluate (fixture));
158+ }
31159}
32160
33161void test_char_ptr_evaluation () {
0 commit comments