-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also added tests for RD-14684 and RD-14685.
- Loading branch information
Showing
6 changed files
with
248 additions
and
15 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
snapi-compiler/src/test/scala/com/rawlabs/snapi/compiler/tests/regressions/RD10971Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.snapi.compiler.tests.regressions | ||
import com.rawlabs.snapi.compiler.tests.SnapiTestContext | ||
|
||
class RD10971Test extends SnapiTestContext { | ||
|
||
test("Json.Parse(\" \", type int)")( | ||
// Jackson returns an internal error. | ||
_ should runErrorAs("""Internal error: _parseNumericValue called when parser instance closed | ||
| at [Source: (String)" "; line: 1, column: 2]""".stripMargin) | ||
) | ||
|
||
test("[Json.Parse(\" \", type int)]")( | ||
_ should run // it doesn't fail because it's in a list. | ||
) | ||
|
||
test("Json.Parse(\" \", type record(a: int, b: string))")( | ||
// unexpected token. | ||
_ should runErrorAs("expected { but token null found") | ||
) | ||
|
||
test("[Json.Parse(\" \", type record(a: int, b: string))]")( | ||
// Same as above, the tryable should be left in the list. The query doesn't fail. | ||
_ should run // it doesn't fail because it's in a list. | ||
) | ||
|
||
test("Json.Parse(\" \", type list(record(a: int, b: string))) // RD-10971")( | ||
// unexpected token. | ||
_ should runErrorAs("expected [ but token null found") | ||
) | ||
|
||
test("[Json.Parse(\" \", type list(record(a: int, b: string)))] // RD-10971")( | ||
_ should run // it doesn't fail because it's in a list. | ||
) | ||
|
||
} |
142 changes: 142 additions & 0 deletions
142
snapi-compiler/src/test/scala/com/rawlabs/snapi/compiler/tests/regressions/RD14684Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.snapi.compiler.tests.regressions | ||
|
||
import com.rawlabs.snapi.compiler.tests.SnapiTestContext | ||
import com.rawlabs.snapi.frontend.snapi.SnapiInterpolator | ||
|
||
class RD14684Test extends SnapiTestContext { | ||
|
||
private val missing_field = tempFile("""[ | ||
|{"name": "Benjamin", "birthYear": 1978}, | ||
|{"name": "X"}, | ||
|{"name": "Jane", "birthYear": 200} | ||
|] | ||
""".stripMargin) | ||
|
||
private val missing_field2 = tempFile("""[ | ||
|{"name": "Benjamin", "birthYear": 1978}, | ||
|{"name": "X"}, | ||
|{"name": "Jane", "birthYear": 200}, | ||
|{"name": "Tarzan", "birthYear": 201} | ||
|] | ||
""".stripMargin) | ||
|
||
private val totallyNotRecord = tempFile("""[ | ||
|{"name": "Benjamin", "birthYear": 1978}, | ||
|14, | ||
|{"name": "Jane", "birthYear": 200} | ||
|] | ||
""".stripMargin) | ||
|
||
ignore( | ||
snapi"""Json.InferAndRead("$missing_field", sampleSize = 1, preferNulls = false)""" | ||
) { it => | ||
// Because we specified a sampleSize of 1, sampling didn't infer a birthyear could miss, | ||
// and we also don't make fields nullable, therefore, the expected behavior is that | ||
// we fail to build the middle record as a whole. | ||
// TODO: RD-14684: the record is indeed parsed as a failed record, but we skip the following one (Jane) | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|Error.Build("'birthYear': not found"), | ||
|{name: "Jane", birthYear: 200}]""".stripMargin | ||
) | ||
} | ||
|
||
ignore( | ||
snapi"""Json.InferAndRead("$missing_field2", sampleSize = 1, preferNulls = false)""" | ||
) { it => | ||
// TODO: RD-14684: the record is indeed parsed as a failed record, but we skip the following one (Jane) | ||
// Same as in the test above. That test confirms we're skipping the following record, not the remaining one. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|Error.Build("'birthYear': not found"), | ||
|{name: "Jane", birthYear: 200}, | ||
|{name: "Tarzan", birthYear: 201}]""".stripMargin | ||
) | ||
} | ||
|
||
test( | ||
snapi"""Json.InferAndRead("$missing_field", sampleSize = 1, preferNulls = true)""" | ||
) { it => | ||
// because sampling didn't infer a birthyear could miss but we make fields | ||
// nullable, we get a null birthYear. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|{name: "X", birthYear: null}, | ||
|{name: "Jane", birthYear: 200}]""".stripMargin | ||
) | ||
} | ||
|
||
test( | ||
snapi"""Json.InferAndRead("$missing_field2", sampleSize = 1, preferNulls = true)""" | ||
) { it => | ||
// because sampling didn't infer a birthyear could miss but we make fields | ||
// nullable, we get a null birthYear. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|{name: "X", birthYear: null}, | ||
|{name: "Jane", birthYear: 200}, | ||
|{name: "Tarzan", birthYear: 201}]""".stripMargin | ||
) | ||
} | ||
|
||
test( | ||
snapi"""Json.InferAndRead("$totallyNotRecord", sampleSize = 1, preferNulls = false)""" | ||
) { it => | ||
// because sampling didn't infer a birthyear could miss and we don't make fields | ||
// nullable, we fail to build the middle record. This doesn't fail like in the first | ||
// tests likely because the parser doesn't start to read the record, it immediately fails | ||
// when it gets an integer in place of the opening brace. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|Error.Build("expected { but token VALUE_NUMBER_INT found"), | ||
|{name: "Jane", birthYear: 200}]""".stripMargin | ||
) | ||
} | ||
|
||
test( | ||
snapi"""Json.InferAndRead("$totallyNotRecord", sampleSize = 1, preferNulls = true)""" | ||
) { it => | ||
// Same as above. Using preferNulls shouldn't change anything. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|Error.Build("expected { but token VALUE_NUMBER_INT found"), | ||
|{name: "Jane", birthYear: 200}]""".stripMargin | ||
) | ||
} | ||
|
||
test( | ||
snapi"""Json.Read("$totallyNotRecord", type list(record(name: string, birthYear: int)))""" | ||
) { it => | ||
// Same as above with an explicit type (which means it's tryable/nullable). | ||
// The parser doesn't even get to start to parse a record. The whole record is failed. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|Error.Build("expected { but token VALUE_NUMBER_INT found"), | ||
|{name: "Jane", birthYear: 200}]""".stripMargin | ||
) | ||
} | ||
|
||
test( | ||
snapi"""Json.Read("$totallyNotRecord", type collection(record(name: string, birthYear: int)))""" | ||
) { it => | ||
// Same as above with a collection. | ||
it should evaluateTo( | ||
"""[{name: "Benjamin", birthYear: 1978}, | ||
|Error.Build("expected { but token VALUE_NUMBER_INT found"), | ||
|{name: "Jane", birthYear: 200}]""".stripMargin | ||
) | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
snapi-compiler/src/test/scala/com/rawlabs/snapi/compiler/tests/regressions/RD14685Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2024 RAW Labs S.A. | ||
* | ||
* Use of this software is governed by the Business Source License | ||
* included in the file licenses/BSL.txt. | ||
* | ||
* As of the Change Date specified in that file, in accordance with | ||
* the Business Source License, use of this software will be governed | ||
* by the Apache License, Version 2.0, included in the file | ||
* licenses/APL.txt. | ||
*/ | ||
|
||
package com.rawlabs.snapi.compiler.tests.regressions | ||
|
||
import com.rawlabs.snapi.compiler.tests.SnapiTestContext | ||
|
||
class RD14685Test extends SnapiTestContext { | ||
|
||
test("Json.Parse(\"12\", type collection(record(a: int, b: string)))")( | ||
_ should runErrorAs("expected [ but token VALUE_NUMBER_INT found") | ||
) | ||
|
||
test("Json.Parse(\" \", type collection(record(a: int, b: string)))")( | ||
// Same error as above. The collection is OK but when rendering to JSON we get a failure. | ||
_ should runErrorAs("expected [ but token null found") | ||
) | ||
|
||
ignore("[Json.Parse(\"12\", type collection(record(a: int, b: string)))]")( | ||
// the collection is consumed when writing JSON, it fails in the middle. | ||
_ should run // TODO if it runs, check the error message in Error.Build | ||
) | ||
|
||
ignore("[Json.Parse(\" \", type collection(record(a: int, b: string)))]")( | ||
// the collection is consumed when writing JSON, it fails in the middle. | ||
_ should run // TODO if it runs, check the error message in Error.Build | ||
) | ||
|
||
ignore("[Collection.Count(Json.Parse(\" \", type collection(record(a: int, b: string))))]")( | ||
// the collection is consumed when running Count, it leads to a failed int in the list. | ||
_ should run // TODO if it runs, check the error message in Error.Build | ||
) | ||
|
||
ignore("[Collection.Count(Json.Parse(\"12\", type collection(record(a: int, b: string))))]")( | ||
// the collection is consumed when running Count, it leads to a failed int in the list. | ||
_ should run // TODO if it runs, check the error message in Error.Build | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters