1+ #pragma once
2+
3+ #include " pch.h"
4+
5+ #include < util.h>
6+
7+ using namespace std ;
8+
9+ class TestUtil : public ::testing::Test {
10+
11+ };
12+
13+ void TestEscapeAssertion (string s, string res) {
14+ string my_res = EscapeAssertion (s);
15+ EXPECT_EQ (my_res, res);
16+ }
17+
18+ TEST_F (TestUtil, TestEscapeAssertion) {
19+ TestEscapeAssertion (" r.attr.value == p.attr" , " r_attr.value == p_attr" );
20+ TestEscapeAssertion (" r.attp.value || p.attr" , " r_attp.value || p_attr" );
21+ TestEscapeAssertion (" r.attp.value &&p.attr" , " r_attp.value &&p_attr" );
22+ TestEscapeAssertion (" r.attp.value >p.attr" , " r_attp.value >p_attr" );
23+ TestEscapeAssertion (" r.attp.value <p.attr" , " r_attp.value <p_attr" );
24+ TestEscapeAssertion (" r.attp.value +p.attr" , " r_attp.value +p_attr" );
25+ TestEscapeAssertion (" r.attp.value -p.attr" , " r_attp.value -p_attr" );
26+ TestEscapeAssertion (" r.attp.value *p.attr" , " r_attp.value *p_attr" );
27+ TestEscapeAssertion (" r.attp.value /p.attr" , " r_attp.value /p_attr" );
28+ TestEscapeAssertion (" !r.attp.value /p.attr" , " !r_attp.value /p_attr" );
29+ TestEscapeAssertion (" g(r.sub, p.sub) == p.attr" , " g(r_sub, p_sub) == p_attr" );
30+ TestEscapeAssertion (" g(r.sub,p.sub) == p.attr" , " g(r_sub,p_sub) == p_attr" );
31+ TestEscapeAssertion (" (r.attp.value || p.attr)p.u" , " (r_attp.value || p_attr)p_u" );
32+ }
33+
34+ void TestRemoveComments (string s, string res) {
35+ string my_res = RemoveComments (s);
36+ EXPECT_EQ (my_res, res);
37+ }
38+
39+ TEST_F (TestUtil, TestRemoveComments) {
40+ TestRemoveComments (" r.act == p.act # comments" , " r.act == p.act" );
41+ TestRemoveComments (" r.act == p.act#comments" , " r.act == p.act" );
42+ TestRemoveComments (" r.act == p.act###" , " r.act == p.act" );
43+ TestRemoveComments (" ### comments" , " " );
44+ TestRemoveComments (" r.act == p.act" , " r.act == p.act" );
45+ }
46+
47+ void TestArrayEquals (vector<string> a, vector<string> b, bool res) {
48+ bool my_res = ArrayEquals (a, b);
49+ EXPECT_EQ (my_res, res);
50+ }
51+
52+ TEST_F (TestUtil, TestArrayEquals) {
53+ TestArrayEquals (vector<string> {" a" , " b" , " c" }, vector<string> {" a" , " b" , " c" }, true );
54+ TestArrayEquals (vector<string> {" a" , " b" , " c" }, vector<string> {" a" , " b" }, false );
55+ TestArrayEquals (vector<string> {" a" , " b" , " c" }, vector<string> {" a" , " c" , " b" }, false );
56+ TestArrayEquals (vector<string> {" a" , " b" , " c" }, vector<string> {}, false );
57+ }
0 commit comments