Skip to content

Commit

Permalink
Fix the unit tests...
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <johannes.kalmbach@gmail.com>
  • Loading branch information
joka921 committed Jan 21, 2025
1 parent cffe9e6 commit 9fb0848
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/parser/data/Variable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

// ___________________________________________________________________________
Variable::Variable(std::string name, bool checkName) : _name{std::move(name)} {
if (checkName) {
if (checkName || ad_utility::areExpensiveChecksEnabled) {
AD_CONTRACT_CHECK(isValidVariableName(_name), [this]() {
return absl::StrCat("\"", _name, "\" is not a valid SPARQL variable");
});
Expand Down
11 changes: 6 additions & 5 deletions test/SparqlDataTypesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,12 @@ TEST(SparqlDataTypesTest, VariableNormalizesDollarSign) {
}

TEST(SparqlDataTypesTest, VariableInvalidNamesThrowException) {
EXPECT_THROW(Variable{"no_leading_var_or_dollar"}, ad_utility::Exception);
EXPECT_THROW(Variable{""}, ad_utility::Exception);
EXPECT_THROW(Variable{"? var with space"}, ad_utility::Exception);
EXPECT_THROW(Variable{"?"}, ad_utility::Exception);
EXPECT_THROW(Variable{"$"}, ad_utility::Exception);
EXPECT_THROW(Variable("no_leading_var_or_dollar", true),
ad_utility::Exception);
EXPECT_THROW(Variable("", true), ad_utility::Exception);
EXPECT_THROW(Variable("? var with space", true), ad_utility::Exception);
EXPECT_THROW(Variable("?", true), ad_utility::Exception);
EXPECT_THROW(Variable("$", true), ad_utility::Exception);
}

TEST(SparqlDataTypesTest, VariableEvaluatesCorrectlyBasedOnContext) {
Expand Down
10 changes: 5 additions & 5 deletions test/parser/data/VariableTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@

// _____________________________________________________________________________
TEST(Variable, legalAndIllegalNames) {
EXPECT_NO_THROW(Variable("?x"));
EXPECT_NO_THROW(Variable("$x"));
EXPECT_NO_THROW(Variable("?ql_matching_word_thür"));
EXPECT_NO_THROW(Variable("?x", true));
EXPECT_NO_THROW(Variable("$x", true));
EXPECT_NO_THROW(Variable("?ql_matching_word_thür", true));

// No leading ? or $
auto matcher = ::testing::HasSubstr("not a valid SPARQL variable");
AD_EXPECT_THROW_WITH_MESSAGE(Variable("x"), matcher);
AD_EXPECT_THROW_WITH_MESSAGE(Variable("?x spaceInVar"), matcher);
AD_EXPECT_THROW_WITH_MESSAGE(Variable("x", true), matcher);
AD_EXPECT_THROW_WITH_MESSAGE(Variable("?x spaceInVar", true), matcher);
}

// _____________________________________________________________________________
Expand Down

0 comments on commit 9fb0848

Please sign in to comment.