File size: 4,576 Bytes
d1be154
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

#include "doctest.h"
#include <ot/utility/utility.hpp>

// Testcase: Tokenizer.IsWord
TEST_CASE("Tokenizer.IsWord") {
  REQUIRE(ot::is_word(" ") == false);
  REQUIRE(ot::is_word("f") == true);
  REQUIRE(ot::is_word("f_") == true);
  REQUIRE(ot::is_word("f_ ") == false);
  REQUIRE(ot::is_word("f1_f") == true);
  REQUIRE(ot::is_word("1_f") == false);
}

// Testcase: Tokenizer.IsArray
TEST_CASE("Tokenizer.IsArray") {
  REQUIRE(ot::is_array("af") == false);
  REQUIRE(ot::is_array("a[0]") == true);
  REQUIRE(ot::is_array("a[]") == false);
  REQUIRE(ot::is_array(" []") == false);
  REQUIRE(ot::is_array(" [98745]") == false);
  REQUIRE(ot::is_array("adf_[98745]") == true);
  REQUIRE(ot::is_array("_[98745]") == true);
  REQUIRE(ot::is_array("as f_[98745]") == false);
  REQUIRE(ot::is_array("B[1][0]") == true);
}

// Testcase: Tokenizer.IsNumeric
TEST_CASE("Tokenizer.IsNumeric") {
  REQUIRE(ot::is_numeric("123") == true);
  REQUIRE(ot::is_numeric("123 ") == false);
  REQUIRE(ot::is_numeric(" 123") == false);
  REQUIRE(ot::is_numeric("123.4") == true);
  REQUIRE(ot::is_numeric("123.") == false);
  REQUIRE(ot::is_numeric("+789") == true);
  REQUIRE(ot::is_numeric("+789 ") == false);
  REQUIRE(ot::is_numeric("+ 789") == false);
  REQUIRE(ot::is_numeric("+789.4") == true);
  REQUIRE(ot::is_numeric("+789.") == false);
  REQUIRE(ot::is_numeric("-456") == true);
  REQUIRE(ot::is_numeric("-456 ") == false);
  REQUIRE(ot::is_numeric("- 456") == false);
  REQUIRE(ot::is_numeric("-456.4") == true);
  REQUIRE(ot::is_numeric("-456.") == false);
}

// Testcase: Tokenizer.Quote
TEST_CASE("Tokenizer.Quote") {
  
  std::string str1 = "no quote";
  std::string str2 = "one quote\"";
  std::string str3 = "one \"quote";
  std::string str4 = "\"quote\"";
  std::string str5 = "1234\"_____\"5678";

  auto [b1, e1] = ot::find_quote_pair(str1.begin(), str1.end());
  REQUIRE((b1 == e1 && b1 == str1.end()));

  auto [b2, e2] = ot::find_quote_pair(str2.begin(), str2.end());
  REQUIRE((b2 == e2 && b2 == str2.end()));

  auto [b3, e3] = ot::find_quote_pair(str3.begin(), str3.end());
  REQUIRE((b3 == e3 && b3 == str3.end()));
  
  auto [b4, e4] = ot::find_quote_pair(str4.begin(), str4.end());
  REQUIRE((b4 == str4.begin() && e4 == str4.begin() + str4.size() - 1));
  
  auto [b5, e5] = ot::find_quote_pair(str5.begin(), str5.end());
  REQUIRE((b5 == str5.begin() + 4 && e5 == str5.begin() + str5.size() - 5));
}

// Testcase: Tokenizer.Brace
TEST_CASE("Tokenizer.Brace") {

  std::string str1 = "{}";
  std::string str2 = "{";
  std::string str3 = "}";
  std::string str4 = "{{[][]{}}}";
  std::string str5 = "56{{[][]{}}}ab";
  std::string str6 = "xyz{[][]{}}}456";

  auto [b1, e1] = ot::find_brace_pair(str1.begin(), str1.end());
  REQUIRE((b1 == str1.begin() && e1 == str1.begin() + 1));

  auto [b2, e2] = ot::find_brace_pair(str2.begin(), str2.end());
  REQUIRE((b2 == str2.end() && e2 == str2.end()));
  
  auto [b3, e3] = ot::find_brace_pair(str3.begin(), str3.end());
  REQUIRE((b3 == str3.end() && e3 == str3.end()));
  
  auto [b4, e4] = ot::find_brace_pair(str4.begin(), str4.end());
  REQUIRE((b4 == str4.begin() && e4 == str4.begin() + str4.size() - 1));
  
  auto [b5, e5] = ot::find_brace_pair(str5.begin(), str5.end());
  REQUIRE((b5 == str5.begin() + 2 && e5 == str5.begin() + str5.size() - 3));
  
  auto [b6, e6] = ot::find_brace_pair(str6.begin(), str6.end());
  REQUIRE((b6 == str6.begin() + 3 && e6 == str6.begin() + str6.size() - 5));
}

// Testcase: Tokenizer.Bracket
TEST_CASE("Tokenizer.Bracket") {

  std::string str1 = "[]";
  std::string str2 = "[";
  std::string str3 = "]";
  std::string str4 = "[[{}{}[]]]";
  std::string str5 = "56[[{}{}[]]]ab";
  std::string str6 = "xyz[{}{}[]]]456";

  auto [b1, e1] = ot::find_bracket_pair(str1.begin(), str1.end());
  REQUIRE((b1 == str1.begin() && e1 == str1.begin() + 1));

  auto [b2, e2] = ot::find_bracket_pair(str2.begin(), str2.end());
  REQUIRE((b2 == str2.end() && e2 == str2.end()));
  
  auto [b3, e3] = ot::find_bracket_pair(str3.begin(), str3.end());
  REQUIRE((b3 == str3.end() && e3 == str3.end()));
  
  auto [b4, e4] = ot::find_bracket_pair(str4.begin(), str4.end());
  REQUIRE((b4 == str4.begin() && e4 == str4.begin() + str4.size() - 1));
  
  auto [b5, e5] = ot::find_bracket_pair(str5.begin(), str5.end());
  REQUIRE((b5 == str5.begin() + 2 && e5 == str5.begin() + str5.size() - 3));
  
  auto [b6, e6] = ot::find_bracket_pair(str6.begin(), str6.end());
  REQUIRE((b6 == str6.begin() + 3 && e6 == str6.begin() + str6.size() - 5));
}