Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,71 @@ public void jsonType() throws Exception {
runTest();
}

@Test
public void jsonTypeNullConstruction() throws Exception {
// Ok
source = "google.protobuf.Value{null_value: google.protobuf.NullValue.NULL_VALUE}";
runTest();

// Error
source = "google.protobuf.Value{null_value: null}";
runTest();

// Ok
source = "cel.expr.conformance.proto3.TestAllTypes{single_value: null}";
runTest();

// Ok but not expected (int coerced to double/json number 0.0)
source =
"cel.expr.conformance.proto3.TestAllTypes{single_value:"
+ " google.protobuf.NullValue.NULL_VALUE}";
runTest();

// Error
source = "cel.expr.conformance.proto3.TestAllTypes{null_value: null}";
runTest();

// Ok
source =
"cel.expr.conformance.proto3.TestAllTypes{null_value:"
+ " google.protobuf.NullValue.NULL_VALUE}";
runTest();
}

@Test
public void jsonTypeNullAccess() throws Exception {
source = "google.protobuf.Value{null_value: google.protobuf.NullValue.NULL_VALUE} == null";
runTest();

source = "cel.expr.conformance.proto3.TestAllTypes{single_value: null}.single_value == null";
runTest();

source =
"cel.expr.conformance.proto3.TestAllTypes{single_value:"
+ " google.protobuf.NullValue.NULL_VALUE}.single_value == null";
runTest();

// Error
source =
"cel.expr.conformance.proto3.TestAllTypes{null_value:"
+ " google.protobuf.NullValue.NULL_VALUE}.null_value == null";
runTest();

// Ok
source =
"cel.expr.conformance.proto3.TestAllTypes{null_value:"
+ " google.protobuf.NullValue.NULL_VALUE}.null_value == 0";
runTest();

// Error
source = "google.protobuf.NullValue.NULL_VALUE == null";
runTest();

// Ok
source = "google.protobuf.NullValue.NULL_VALUE == 0";
runTest();
}

// Call Style and User Functions
// =============================

Expand Down
54 changes: 54 additions & 0 deletions checker/src/test/resources/jsonTypeNullAccess.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Source: google.protobuf.Value{null_value: google.protobuf.NullValue.NULL_VALUE} == null
=====>
_==_(
google.protobuf.Value{
null_value:google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE
}~dyn^google.protobuf.Value,
null~null
)~bool^equals

Source: cel.expr.conformance.proto3.TestAllTypes{single_value: null}.single_value == null
=====>
_==_(
cel.expr.conformance.proto3.TestAllTypes{
single_value:null~null
}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes.single_value~dyn,
null~null
)~bool^equals

Source: cel.expr.conformance.proto3.TestAllTypes{single_value: google.protobuf.NullValue.NULL_VALUE}.single_value == null
=====>
_==_(
cel.expr.conformance.proto3.TestAllTypes{
single_value:google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE
}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes.single_value~dyn,
null~null
)~bool^equals

Source: cel.expr.conformance.proto3.TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value == null
=====>
ERROR: test_location:1:103: found no matching overload for '_==_' applied to '(int, null)' (candidates: (%A0, %A0))
| cel.expr.conformance.proto3.TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value == null
| ......................................................................................................^

Source: cel.expr.conformance.proto3.TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value == 0
=====>
_==_(
cel.expr.conformance.proto3.TestAllTypes{
null_value:google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE
}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes.null_value~int,
0~int
)~bool^equals

Source: google.protobuf.NullValue.NULL_VALUE == null
=====>
ERROR: test_location:1:38: found no matching overload for '_==_' applied to '(int, null)' (candidates: (%A0, %A0))
| google.protobuf.NullValue.NULL_VALUE == null
| .....................................^

Source: google.protobuf.NullValue.NULL_VALUE == 0
=====>
_==_(
google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE,
0~int
)~bool^equals
35 changes: 35 additions & 0 deletions checker/src/test/resources/jsonTypeNullConstruction.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Source: google.protobuf.Value{null_value: google.protobuf.NullValue.NULL_VALUE}
=====>
google.protobuf.Value{
null_value:google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE
}~dyn^google.protobuf.Value

Source: google.protobuf.Value{null_value: null}
=====>
ERROR: test_location:1:33: expected type of field 'null_value' is 'int' but provided type is 'null'
| google.protobuf.Value{null_value: null}
| ................................^

Source: cel.expr.conformance.proto3.TestAllTypes{single_value: null}
=====>
cel.expr.conformance.proto3.TestAllTypes{
single_value:null~null
}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes

Source: cel.expr.conformance.proto3.TestAllTypes{single_value: google.protobuf.NullValue.NULL_VALUE}
=====>
cel.expr.conformance.proto3.TestAllTypes{
single_value:google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE
}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes

Source: cel.expr.conformance.proto3.TestAllTypes{null_value: null}
=====>
ERROR: test_location:1:52: expected type of field 'null_value' is 'int' but provided type is 'null'
| cel.expr.conformance.proto3.TestAllTypes{null_value: null}
| ...................................................^

Source: cel.expr.conformance.proto3.TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}
=====>
cel.expr.conformance.proto3.TestAllTypes{
null_value:google.protobuf.NullValue.NULL_VALUE~int^google.protobuf.NullValue.NULL_VALUE
}~cel.expr.conformance.proto3.TestAllTypes^cel.expr.conformance.proto3.TestAllTypes
43 changes: 41 additions & 2 deletions runtime/src/test/resources/jsonValueTypes.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,46 @@ bindings: {x=single_value {
}
result: true

Source: google.protobuf.Value{string_value: 'hello'} == 'hello'
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
bindings: {}
result: true

Source: google.protobuf.Value{number_value: 1.1} == 1.1
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
bindings: {}
result: true

Source: google.protobuf.Value{null_value: google.protobuf.NullValue.NULL_VALUE} == null
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
bindings: {}
result: true

Source: TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value == 0
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
bindings: {}
result: true

Source: TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value != dyn(null)
declare x {
value cel.expr.conformance.proto3.TestAllTypes
}
=====>
bindings: {}
result: true

Source: x.single_value[0] == [['hello'], -1.1][0]
declare x {
value cel.expr.conformance.proto3.TestAllTypes
Expand Down Expand Up @@ -148,5 +188,4 @@ bindings: {x=single_struct {
}
}
}
result: {hello=val}

result: {hello=val}
17 changes: 17 additions & 0 deletions testing/src/main/java/dev/cel/testing/BaseInterpreterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1850,6 +1850,23 @@ public void jsonValueTypes() {
source = "x.single_value == 'hello'";
runTest(ImmutableMap.of("x", xString));

// json manual construction
source = "google.protobuf.Value{string_value: 'hello'} == 'hello'";
runTest();

source = "google.protobuf.Value{number_value: 1.1} == 1.1";
runTest();

source = "google.protobuf.Value{null_value: google.protobuf.NullValue.NULL_VALUE} == null";
runTest();

// NULL_VALUE is not the same as null.
source = "TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value == 0";
runTest();
source =
"TestAllTypes{null_value: google.protobuf.NullValue.NULL_VALUE}.null_value != dyn(null)";
runTest();

// JSON list equality.
TestAllTypes xList =
TestAllTypes.newBuilder()
Expand Down
Loading