complete tests for if command booleans

This commit is contained in:
Axel Kohlmeyer
2021-03-24 14:35:48 -04:00
parent 51946205ce
commit cc54f553e0

View File

@ -295,19 +295,25 @@ TEST_F(VariableTest, IfCommand)
if (!verbose) ::testing::internal::GetCapturedStdout(); if (!verbose) ::testing::internal::GetCapturedStdout();
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
command("if 1>0 then 'print \".*bingo!\"'"); command("if 1>0 then 'print \"bingo!\"'");
auto text = ::testing::internal::GetCapturedStdout(); auto text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
command("if (1>=0) then 'print \"bingo!\"'"); command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, MatchesRegex(".*nope\?.*"));
::testing::internal::CaptureStdout(); ::testing::internal::CaptureStdout();
command("if (-1.0e-1<0.0E+0) then 'print \"bingo!\"'"); command("if (1<=0) then 'print \"bingo!\"' else 'print \"nope?\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*nope\?.*"));
::testing::internal::CaptureStdout();
command("if (-1.0e-1<0.0E+0)|^(1<0) then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout(); text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
@ -324,8 +330,50 @@ TEST_F(VariableTest, IfCommand)
if (verbose) std::cout << text; if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
command("if (1>=2)&&(0&&1) then 'print \"missed\"' else 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
command("if !1 then 'print \"missed\"' else 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
command("if !(a==b) then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
command("if x==x|^1==0 then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
::testing::internal::CaptureStdout();
command("if x!=x|^a!=b then 'print \"bingo!\"'");
text = ::testing::internal::GetCapturedStdout();
if (verbose) std::cout << text;
ASSERT_THAT(text, MatchesRegex(".*bingo!.*"));
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if () then 'print \"bingo!\"'");); command("if () then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if \"1 1\" then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if 1a then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if 1=<2 then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if 1!=a then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if 1&<2 then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if 1|<2 then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",
command("if (1)( then 'print \"bingo!\"'");); command("if (1)( then 'print \"bingo!\"'"););
TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*", TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",