From 2972b37b9b1f2bf3e2f54f7486b6f7d859ec0c72 Mon Sep 17 00:00:00 2001 From: Richardas Kuchinskas Date: Mon, 17 Feb 2025 14:52:03 +0300 Subject: [PATCH] new tests --- src/tests/checkers/null_safety_test.go | 86 ++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/src/tests/checkers/null_safety_test.go b/src/tests/checkers/null_safety_test.go index 57abfff7..bb8ac88a 100644 --- a/src/tests/checkers/null_safety_test.go +++ b/src/tests/checkers/null_safety_test.go @@ -155,3 +155,89 @@ testVariadic(new A(), null); } test.RunAndMatch() } + +// TODO: After realisation Control Flow Graph (CFG) и Data Flow Graph (DFG) this test must fail +func TestIfNullCheckSafe(t *testing.T) { + test := linttest.NewSuite(t) + test.AddFile(`value; +} + +$v = null; +if ($v == null) { + // Correctly assign a new instance when $v is null. + $v = new A(); +} +test($v); // Should be safe. +`) + + test.Expect = []string{ + `not null safety call in function test signature of param`, + } + test.RunAndMatch() +} + +func TestIfNullCheckUnsafe(t *testing.T) { + test := linttest.NewSuite(t) + test.AddFile(`value; +} + +$v = null; +if ($v == null) { + // No assignment is done here – $v remains null. +} +test($v); // Should trigger a null safety error. +`) + test.Expect = []string{ + "not null safety call in function test signature of param", + } + test.RunAndMatch() +} + +func TestIfNotNullCheck(t *testing.T) { + test := linttest.NewSuite(t) + test.AddFile(`value; +} + +$v = new A(); +if ($v !== null) { + // $v is known to be non-null. + test($v); // Should be safe. +} +`) + + test.Expect = []string{} + test.RunAndMatch() +}