Skip to content

Commit bc67e65

Browse files
feat: sync tests (#611)
ports: google/go-jsonnet#849 google/go-jsonnet#853 google/jsonnet#1291 google/jsonnet#1284 Co-authored-by: Stephen Amar <stephen.amar@databricks.com>
1 parent d9e3939 commit bc67e65

38 files changed

Lines changed: 632 additions & 95 deletions

sjsonnet/src-js/sjsonnet/Platform.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ object Platform {
4747
def yamlToJson(s: String): ujson.Value = {
4848
val docs = docSplitPattern.split(s, -1)
4949
docs.size match {
50-
case 0 => ujson.Obj()
50+
case 0 => ujson.Null
5151
case 1 =>
5252
docs.head.asNode match {
5353
case Right(n) =>
5454
nodeToJson(n)
5555
case Left(e) if docs.head.trim.isEmpty =>
56-
ujson.Obj()
56+
ujson.Null
5757
case Left(e) =>
5858
Error.fail("Error converting YAML to JSON: " + e.getMessage)
5959
}

sjsonnet/src-jvm/sjsonnet/Platform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ object Platform {
8989
val yaml =
9090
new Yaml(new SafeConstructor(new LoaderOptions())).loadAll(yamlString).asScala.toSeq
9191
yaml.size match {
92-
case 0 => ujson.Obj()
92+
case 0 => ujson.Null
9393
case 1 => nodeToJson(yaml.head)
9494
case _ =>
9595
val buf = new mutable.ArrayBuffer[ujson.Value](yaml.size)

sjsonnet/src-native/sjsonnet/Platform.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ object Platform {
8282
def yamlToJson(s: String): ujson.Value = {
8383
val docs = docSplitPattern.split(s, -1)
8484
docs.length match {
85-
case 0 => ujson.Obj()
85+
case 0 => ujson.Null
8686
case 1 =>
8787
docs.head.asNode match {
8888
case Right(n) =>
8989
nodeToJson(n)
9090
case Left(e) if docs.head.trim.isEmpty =>
91-
ujson.Obj()
91+
ujson.Null
9292
case Left(e) =>
9393
Error.fail("Error converting YAML to JSON: " + e.getMessage)
9494
}

sjsonnet/src/sjsonnet/stdlib/ArrayModule.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,10 @@ object ArrayModule extends AbstractFunctionModule {
379379
val fres = func.apply1(v, pos.noOffset)(ev, TailstrictModeDisabled)
380380
fres match {
381381
case va: Val.Arr => va.asLazyArray
382-
case unknown => Error.fail("flatMap func must return an array, not " + unknown)
382+
case unknown =>
383+
Error.fail(
384+
"std.flatMap on arrays, provided function must return an array, got " + unknown.prettyName
385+
)
383386
}
384387
}
385388
}
@@ -399,7 +402,7 @@ object ArrayModule extends AbstractFunctionModule {
399402
case _: Val.Null => ""
400403
case x =>
401404
Error.fail(
402-
"flatMap func must return string, got " + fres
405+
"std.flatMap on strings, provided function must return a string, got " + fres
403406
.asInstanceOf[Val]
404407
.value
405408
.prettyName
@@ -409,7 +412,8 @@ object ArrayModule extends AbstractFunctionModule {
409412
i += Character.charCount(codePoint)
410413
}
411414
Val.Str(pos, builder.toString)
412-
case _ => Error.fail("Argument must be either array or string")
415+
case unknown =>
416+
Error.fail("std.flatMap second param must be array / string, got " + unknown.prettyName)
413417
}
414418
res
415419
},

sjsonnet/src/sjsonnet/stdlib/ManifestModule.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ object ManifestModule extends AbstractFunctionModule {
7272
private object ParseYaml extends Val.Builtin1("parseYaml", "str") {
7373
def evalRhs(str: Eval, ev: EvalScope, pos: Position): Val = {
7474
val input = str.value.asString
75-
if (input.isEmpty) {
75+
if (input.isBlank) {
7676
return Val.Null(pos)
7777
}
7878
ujson.transform(Platform.yamlToJson(input), new ValVisitor(pos))
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
std.isNull(null)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
std.isNull("foo")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
false
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
local cases = [
2+
[123456, '123_456'],
3+
[1750000, '1_750_000'],
4+
[123, '1_2_3'],
5+
[3.141592, '3.141_592'],
6+
[1200.0, '1_200.0'],
7+
[0e101, '0e1_01'],
8+
[1010e3, '10_10e3'],
9+
[23e12, '2_3e1_2'],
10+
[1.12e100, '1.1_2e100'],
11+
[1.1e-101, '1.1e-10_1'],
12+
[9.10938356e-31, '9.109_383_56e-31'],
13+
];
14+
15+
local sepParse(s) = std.parseJson(std.strReplace(s, '_', ''));
16+
17+
{
18+
test_results: [std.assertEqual(c[0], sepParse(c[1])) for c in cases],
19+
}

0 commit comments

Comments
 (0)