Split out tests for binary operators into binary_ops.cc.
PiperOrigin-RevId: 521433966
diff --git a/nullability_verification/test/binary_ops.cc b/nullability_verification/test/binary_ops.cc
new file mode 100644
index 0000000..c956fc2
--- /dev/null
+++ b/nullability_verification/test/binary_ops.cc
@@ -0,0 +1,88 @@
+// Part of the Crubit project, under the Apache License v2.0 with LLVM
+// Exceptions. See /LICENSE for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+
+// Tests for binary operators.
+
+#include "nullability_verification/test/check_diagnostics.h"
+#include "third_party/llvm/llvm-project/third-party/unittest/googletest/include/gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+namespace nullability {
+namespace {
+
+TEST(PointerNullabilityTest, BinaryExpressions) {
+ // x && y
+ EXPECT_TRUE(checkDiagnostics(R"cc(
+ void target(int* _Nullable x, int* _Nullable y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ if (x && y) {
+ *x;
+ *y;
+ } else {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ )cc"));
+
+ // x || y
+ EXPECT_TRUE(checkDiagnostics(R"cc(
+ void target(int* _Nullable x, int* _Nullable y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ if (x || y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ } else {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ )cc"));
+
+ // !x && !y
+ EXPECT_TRUE(checkDiagnostics(R"cc(
+ void target(int* _Nullable x, int* _Nullable y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ if (!x && !y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ } else {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ )cc"));
+
+ // !x || !y
+ EXPECT_TRUE(checkDiagnostics(R"cc(
+ void target(int* _Nullable x, int* _Nullable y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ if (!x || !y) {
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ } else {
+ *x;
+ *y;
+ }
+ *x; // [[unsafe]]
+ *y; // [[unsafe]]
+ }
+ )cc"));
+}
+
+} // namespace
+} // namespace nullability
+} // namespace tidy
+} // namespace clang