Skip to content

Commit 822cd59

Browse files
committed
test: Add more unit-tests
1 parent d1e076c commit 822cd59

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

include/simfil/value.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,8 @@ inline auto valueType2String(ValueType t) -> const char*
8787
case ValueType::TransientObject: return "transient";
8888
case ValueType::Object: return "object";
8989
case ValueType::Array: return "array";
90-
default:
91-
assert(0 && "unreachable");
92-
return "unknown";
9390
}
91+
assert(0 && "unreachable"); return "unknown"; // GCOVR_EXCL_LINE
9492
}
9593

9694

test/completion.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ TEST_CASE("Complete in Expression", "[completion.complete-mid-expression]") {
9999
EXPECT_COMPLETION("sub.ch > 123", 6, "child");
100100
}
101101

102+
TEST_CASE("Complete in unclosed expression", "[completion.complete-in-unclosed-expr]") {
103+
EXPECT_COMPLETION("(field + oth", {}, "other");
104+
EXPECT_COMPLETION("_{field + oth", {}, "other");
105+
EXPECT_COMPLETION("*[field + oth", {}, "other");
106+
}
107+
102108
TEST_CASE("Complete SmartCas", "[completion.smart-case]") {
103109
// Complete both the field and the constants
104110
EXPECT_COMPLETION("cons", {}, "constant", Type::FIELD, 4);

test/token.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,34 @@ TEST_CASE("Token location", "[token.location]") {
158158
REQUIRE(tokens[3].begin == pos); REQUIRE(tokens[3].end == pos+3); pos+=4; /* and */
159159
REQUIRE(tokens[4].begin == pos); REQUIRE(tokens[4].end == pos+4); pos+=4; /* true */
160160
}
161+
162+
TEST_CASE("Token to string", "[token.to-string]") {
163+
auto tokens = tokenize("1 1.5 'Æthervial' re'.* Familiar' abc ()[]{},:._ * ** "
164+
"null true false + - * / % << >> & | ^ ~ not and or "
165+
"== != < <= > >= ? # typeof as ...");
166+
REQUIRE(tokens);
167+
168+
auto i = 0;
169+
#define REQUIRE_STR(expr) do { REQUIRE((*tokens)[i].toString() == (expr)); ++i; } while (false)
170+
171+
REQUIRE_STR("1");
172+
REQUIRE_STR("1.500000");
173+
REQUIRE_STR("'Æthervial'");
174+
REQUIRE_STR("re'.* Familiar'");
175+
REQUIRE_STR("abc");
176+
REQUIRE_STR("("); REQUIRE_STR(")");
177+
REQUIRE_STR("["); REQUIRE_STR("]");
178+
REQUIRE_STR("{"); REQUIRE_STR("}");
179+
REQUIRE_STR(","); REQUIRE_STR(":");
180+
REQUIRE_STR("."); REQUIRE_STR("_");
181+
REQUIRE_STR("*"); REQUIRE_STR("**");
182+
REQUIRE_STR("null"); REQUIRE_STR("true"); REQUIRE_STR("false");
183+
REQUIRE_STR("+"); REQUIRE_STR("-"); REQUIRE_STR("*"); REQUIRE_STR("/");
184+
REQUIRE_STR("%");
185+
REQUIRE_STR("<<"); REQUIRE_STR(">>"); REQUIRE_STR("&"); REQUIRE_STR("|"); REQUIRE_STR("^"); REQUIRE_STR("~");
186+
REQUIRE_STR("not"); REQUIRE_STR("and"); REQUIRE_STR("or");
187+
REQUIRE_STR("=="); REQUIRE_STR("!="); REQUIRE_STR("<");
188+
REQUIRE_STR("<="); REQUIRE_STR(">"); REQUIRE_STR(">=");
189+
REQUIRE_STR("?"); REQUIRE_STR("#"); REQUIRE_STR("typeof");
190+
REQUIRE_STR("as"); REQUIRE_STR("...");
191+
}

0 commit comments

Comments
 (0)