Skip to content

Commit

Permalink
get_bounds_of_next_potential_var tests changed back to test heuristic…
Browse files Browse the repository at this point in the history
… as intended; Schema no longer uses a similar function and also should have had (and still needs) its own tests instead of hijacking the heuristic tests
  • Loading branch information
SharafMohamed committed Jul 8, 2024
1 parent b3efd94 commit acd8819
Showing 1 changed file with 22 additions and 160 deletions.
182 changes: 22 additions & 160 deletions components/core/tests/test-Grep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,222 +31,84 @@ TEST_CASE("get_bounds_of_next_potential_var", "[get_bounds_of_next_potential_var
str = "";
begin_pos = string::npos;
end_pos = string::npos;
REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== false);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == false);

// Empty string
str = "";
begin_pos = 0;
end_pos = 0;
REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== false);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == false);

// No tokens
str = "=";
begin_pos = 0;
end_pos = 0;
REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== false);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == false);

// No wildcards
str = " MAC address 95: ad ff 95 24 0d ff =-abc- ";
begin_pos = 0;
end_pos = 0;

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("95" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("ad" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("ff" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("95" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("24" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("0d" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("ff" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE("-abc-" == str.substr(begin_pos, end_pos - begin_pos));
REQUIRE(true == is_var);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== false);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == false);
REQUIRE(str.length() == begin_pos);

// With wildcards
str = "~=1\\*x\\?!abc*123;1.2%x:+394/-=-*abc-";
begin_pos = 0;
end_pos = 0;

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "1\\*x");
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "1");
REQUIRE(is_var == true);
// REQUIRE(is_var == true);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);

REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "abc*123");
REQUIRE(is_var == false);
// REQUIRE(is_var == true);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(is_var == true);

REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "1.2");
REQUIRE(is_var == true);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "+394/-");
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "+394");
REQUIRE(is_var == true);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== true);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == true);
REQUIRE(str.substr(begin_pos, end_pos - begin_pos) == "-*abc-");
REQUIRE(is_var == false);

REQUIRE(Grep::get_bounds_of_next_potential_var(
str,
begin_pos,
end_pos,
is_var,
forward_lexer,
reverse_lexer
)
== false);
REQUIRE(Grep::get_bounds_of_next_potential_var(str, begin_pos, end_pos, is_var) == false);
}

0 comments on commit acd8819

Please sign in to comment.