| 32 | } |
| 33 | |
| 34 | TEST(Exercise3, LogicalOr) { |
| 35 | // Some of these expectations are incorrect. |
| 36 | // If a logical operation can short-circuit a branch that results in an error, |
| 37 | // CEL evaluation will return the logical result instead of propagating the |
| 38 | // error. For logical or, this means if one branch is true, the result will |
| 39 | // always be true, regardless of the other branch. |
| 40 | // Wrong |
| 41 | EXPECT_THAT(TruthTableTest("true || (1 / 0 > 2)"), |
| 42 | StatusIs(absl::StatusCode::kInvalidArgument, "divide by zero")); |
| 43 | EXPECT_THAT(TruthTableTest("false || (1 / 0 > 2)"), |
| 44 | StatusIs(absl::StatusCode::kInvalidArgument, "divide by zero")); |
| 45 | // Wrong |
| 46 | EXPECT_THAT(TruthTableTest("(1 / 0 > 2) || true"), |
| 47 | StatusIs(absl::StatusCode::kInvalidArgument, "divide by zero")); |
| 48 | EXPECT_THAT(TruthTableTest("(1 / 0 > 2) || false"), |
| 49 | StatusIs(absl::StatusCode::kInvalidArgument, "divide by zero")); |
| 50 | EXPECT_THAT(TruthTableTest("(1 / 0 > 2) || (1 / 0 > 2)"), |
| 51 | StatusIs(absl::StatusCode::kInvalidArgument, "divide by zero")); |
| 52 | EXPECT_THAT(TruthTableTest("true || true"), IsOkAndHolds(true)); |
| 53 | EXPECT_THAT(TruthTableTest("true || false"), IsOkAndHolds(true)); |
| 54 | EXPECT_THAT(TruthTableTest("false || true"), IsOkAndHolds(true)); |
| 55 | EXPECT_THAT(TruthTableTest("false || false"), IsOkAndHolds(false)); |
| 56 | } |
| 57 | |
| 58 | TEST(Exercise3, LogicalAnd) { |
| 59 | EXPECT_THAT(TruthTableTest("true && (1 / 0 > 2)"), |
nothing calls this directly
no test coverage detected