Skip to content

Commit 61f54c2

Browse files
committed
Add string comparison functionality and test.
Single test case taken from #7. Thanks Per.
1 parent 4957772 commit 61f54c2

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

tests/testdatastrcmp.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

tests/testprogstrcmp.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# String comparisons
2+
STRING("1") NEWLINE
3+
SET(x = "abc")
4+
SET(y = "hello")
5+
ASSERT(x < "b")
6+
ASSERT(y >= "helln")
7+
ASSERT(x != y)

value.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,22 @@ class Value {
8282
else if constexpr (op == checktestdataParser::OR)
8383
return Value{a || b};
8484
}
85+
if constexpr (std::is_same_v<T, string> &&
86+
std::is_same_v<U, string>) {
87+
if constexpr (op == checktestdataParser::EQ) {
88+
return Value{a == b};
89+
} else if constexpr (op == checktestdataParser::NE) {
90+
return Value{a != b};
91+
} else if constexpr (op == checktestdataParser::LE) {
92+
return Value{a <= b};
93+
} else if constexpr (op == checktestdataParser::LT) {
94+
return Value{a < b};
95+
} else if constexpr (op == checktestdataParser::GE) {
96+
return Value{a >= b};
97+
} else if constexpr (op == checktestdataParser::GT) {
98+
return Value{a > b};
99+
}
100+
}
85101
if constexpr (!is_numeric<T> || !is_numeric<U>) {
86102
throw std::invalid_argument("invalid operands");
87103
} else {

0 commit comments

Comments
 (0)