From cc54f553e0d09ecaa0a15881f1598c33765d2d9c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 24 Mar 2021 14:35:48 -0400 Subject: [PATCH] complete tests for if command booleans --- unittest/commands/test_variables.cpp | 56 ++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 4 deletions(-) diff --git a/unittest/commands/test_variables.cpp b/unittest/commands/test_variables.cpp index 7106867894..37856184eb 100644 --- a/unittest/commands/test_variables.cpp +++ b/unittest/commands/test_variables.cpp @@ -295,19 +295,25 @@ TEST_F(VariableTest, IfCommand) if (!verbose) ::testing::internal::GetCapturedStdout(); ::testing::internal::CaptureStdout(); - command("if 1>0 then 'print \".*bingo!\"'"); + command("if 1>0 then 'print \"bingo!\"'"); auto text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); ::testing::internal::CaptureStdout(); - command("if (1>=0) then 'print \"bingo!\"'"); + command("if 1>2 then 'print \"bingo!\"' else 'print \"nope?\"'"); text = ::testing::internal::GetCapturedStdout(); if (verbose) std::cout << text; - ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); + ASSERT_THAT(text, MatchesRegex(".*nope\?.*")); ::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(); if (verbose) std::cout << text; ASSERT_THAT(text, MatchesRegex(".*bingo!.*")); @@ -324,8 +330,50 @@ TEST_F(VariableTest, IfCommand) if (verbose) std::cout << text; 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.*", 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.*", command("if (1)( then 'print \"bingo!\"'");); TEST_FAILURE(".*ERROR: Invalid Boolean syntax in if command.*",