|
63 | 63 | import dev.cel.checker.ProtoTypeMask; |
64 | 64 | import dev.cel.checker.TypeProvider; |
65 | 65 | import dev.cel.common.CelAbstractSyntaxTree; |
| 66 | +import dev.cel.common.CelErrorCode; |
66 | 67 | import dev.cel.common.CelIssue; |
67 | 68 | import dev.cel.common.CelOptions; |
68 | 69 | import dev.cel.common.CelProtoAbstractSyntaxTree; |
@@ -1961,6 +1962,59 @@ public void program_nativeTypeUnknownsEnabled_asCallArguments() throws Exception |
1961 | 1962 | assertThat(result.attributes()).isEmpty(); |
1962 | 1963 | } |
1963 | 1964 |
|
| 1965 | + @Test |
| 1966 | + @TestParameters("{expression: 'string(123)'}") |
| 1967 | + @TestParameters("{expression: 'string(123u)'}") |
| 1968 | + @TestParameters("{expression: 'string(1.5)'}") |
| 1969 | + @TestParameters("{expression: 'string(\"foo\")'}") |
| 1970 | + @TestParameters("{expression: 'string(b\"foo\")'}") |
| 1971 | + @TestParameters("{expression: 'string(timestamp(100))'}") |
| 1972 | + @TestParameters("{expression: 'string(duration(\"1h\"))'}") |
| 1973 | + public void program_stringConversionDisabled_throws(String expression) throws Exception { |
| 1974 | + Cel cel = |
| 1975 | + CelFactory.standardCelBuilder() |
| 1976 | + .setOptions( |
| 1977 | + CelOptions.current() |
| 1978 | + .enableTimestampEpoch(true) |
| 1979 | + .enableStringConversion(false) |
| 1980 | + .build()) |
| 1981 | + .build(); |
| 1982 | + CelAbstractSyntaxTree ast = cel.compile(expression).getAst(); |
| 1983 | + |
| 1984 | + CelEvaluationException e = |
| 1985 | + assertThrows(CelEvaluationException.class, () -> cel.createProgram(ast).eval()); |
| 1986 | + assertThat(e).hasMessageThat().contains("No matching overload for function 'string'"); |
| 1987 | + assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND); |
| 1988 | + } |
| 1989 | + |
| 1990 | + @Test |
| 1991 | + public void program_stringConcatenationDisabled_throws() throws Exception { |
| 1992 | + Cel cel = |
| 1993 | + CelFactory.standardCelBuilder() |
| 1994 | + .setOptions(CelOptions.current().enableStringConcatenation(false).build()) |
| 1995 | + .build(); |
| 1996 | + CelAbstractSyntaxTree ast = cel.compile("'foo' + 'bar'").getAst(); |
| 1997 | + |
| 1998 | + CelEvaluationException e = |
| 1999 | + assertThrows(CelEvaluationException.class, () -> cel.createProgram(ast).eval()); |
| 2000 | + assertThat(e).hasMessageThat().contains("No matching overload for function '_+_'"); |
| 2001 | + assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND); |
| 2002 | + } |
| 2003 | + |
| 2004 | + @Test |
| 2005 | + public void program_listConcatenationDisabled_throws() throws Exception { |
| 2006 | + Cel cel = |
| 2007 | + CelFactory.standardCelBuilder() |
| 2008 | + .setOptions(CelOptions.current().enableListConcatenation(false).build()) |
| 2009 | + .build(); |
| 2010 | + CelAbstractSyntaxTree ast = cel.compile("[1] + [2]").getAst(); |
| 2011 | + |
| 2012 | + CelEvaluationException e = |
| 2013 | + assertThrows(CelEvaluationException.class, () -> cel.createProgram(ast).eval()); |
| 2014 | + assertThat(e).hasMessageThat().contains("No matching overload for function '_+_'"); |
| 2015 | + assertThat(e.getErrorCode()).isEqualTo(CelErrorCode.OVERLOAD_NOT_FOUND); |
| 2016 | + } |
| 2017 | + |
1964 | 2018 | @Test |
1965 | 2019 | public void toBuilder_isImmutable() { |
1966 | 2020 | CelBuilder celBuilder = CelFactory.standardCelBuilder(); |
|
0 commit comments