diff --git a/sjsonnet/src-jvm/sjsonnet/Platform.scala b/sjsonnet/src-jvm/sjsonnet/Platform.scala
index 074cd13d..867d6b03 100644
--- a/sjsonnet/src-jvm/sjsonnet/Platform.scala
+++ b/sjsonnet/src-jvm/sjsonnet/Platform.scala
@@ -52,10 +52,13 @@ object Platform {
def yamlToJson(yamlString: String): String = {
try {
val yaml = new Yaml(new SafeConstructor(new LoaderOptions())).loadAll(yamlString)
- .asInstanceOf[java.lang.Iterable[java.util.Map[String, Object]]].asScala.toSeq
+ .asInstanceOf[java.lang.Iterable[java.util.Collection[Object]]].asScala.toSeq
yaml.size match {
case 0 => "{}"
- case 1 => new JSONObject(yaml.head).toString()
+ case 1 if yaml.head.isInstanceOf[java.util.Map[String, Object]] =>
+ new JSONObject(yaml.head.asInstanceOf[java.util.Map[String, Object]]).toString()
+ case 1 if yaml.head.isInstanceOf[java.util.List[Object]] =>
+ new JSONArray(yaml.head.asInstanceOf[java.util.List[Object]]).toString()
case _ => new JSONArray(yaml.asJava).toString()
}
} catch {
diff --git a/sjsonnet/src/sjsonnet/Evaluator.scala b/sjsonnet/src/sjsonnet/Evaluator.scala
index 735c3f59..54590b27 100644
--- a/sjsonnet/src/sjsonnet/Evaluator.scala
+++ b/sjsonnet/src/sjsonnet/Evaluator.scala
@@ -661,6 +661,14 @@ class Evaluator(resolver: CachedResolver,
case Nil => scopes
}
+ def compare(x: Val, y: Val): Int = (x, y) match {
+ case (_: Val.Null, _: Val.Null) => 0
+ case (x: Val.Num, y: Val.Num) => x.value.compareTo(y.value)
+ case (x: Val.Str, y: Val.Str) => x.value.compareTo(y.value)
+ case (x: Val.Bool, y: Val.Bool) => x.asBoolean.compareTo(y.asBoolean)
+ case _ => Error.fail("Cannot compare " + x.prettyName + " with " + y.prettyName, x.pos)
+ }
+
def equal(x: Val, y: Val): Boolean = (x eq y) || (x match {
case _: Val.True => y.isInstanceOf[Val.True]
case _: Val.False => y.isInstanceOf[Val.False]
diff --git a/sjsonnet/src/sjsonnet/Std.scala b/sjsonnet/src/sjsonnet/Std.scala
index 3f407d11..193dba14 100644
--- a/sjsonnet/src/sjsonnet/Std.scala
+++ b/sjsonnet/src/sjsonnet/Std.scala
@@ -9,6 +9,7 @@ import sjsonnet.Expr.Member.Visibility
import scala.collection.Searching._
import scala.collection.mutable
+import scala.util.control.Breaks.{break, breakable}
import scala.util.matching.Regex
/**
@@ -19,6 +20,8 @@ import scala.util.matching.Regex
class Std {
private val dummyPos: Position = new Position(null, 0)
private val emptyLazyArray = new Array[Lazy](0)
+ private val leadingWhiteSpacePattern = Pattern.compile("^[ \t\n\f\r\u0085\u00A0']+")
+ private val trailingWhiteSpacePattern = Pattern.compile("[ \t\n\f\r\u0085\u00A0']+$")
private object AssertEqual extends Val.Builtin2("assertEqual", "a", "b") {
def evalRhs(v1: Val, v2: Val, ev: EvalScope, pos: Position): Val = {
@@ -131,20 +134,58 @@ class Std {
}
-private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hidden"), Array(null, null, Val.Null(dummyPos), Val.True(dummyPos))) {
- override def evalRhs(args: Array[_ <: Lazy], ev: EvalScope, pos: Position): Val = {
- val obj = args(0).force.asObj
- val k = args(1).force.asString
- val incHidden = args(3).force.asBoolean
- if (incHidden && obj.containsKey(k)) {
- obj.value(k, pos.noOffset, obj)(ev)
- } else if (!incHidden && obj.containsVisibleKey(k)) {
- obj.value(k, pos.noOffset, obj)(ev)
- } else {
- args(2).force
+ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hidden"), Array(null, null, Val.Null(dummyPos), Val.True(dummyPos))) {
+ override def evalRhs(args: Array[_ <: Lazy], ev: EvalScope, pos: Position): Val = {
+ val obj = args(0).force.asObj
+ val k = args(1).force.asString
+ val incHidden = args(3).force.asBoolean
+ if (incHidden && obj.containsKey(k)) {
+ obj.value(k, pos.noOffset, obj)(ev)
+ } else if (!incHidden && obj.containsVisibleKey(k)) {
+ obj.value(k, pos.noOffset, obj)(ev)
+ } else {
+ args(2).force
+ }
+ }
+ }
+
+ private object MinArray extends Val.Builtin("minArray", Array("arr", "keyF", "onEmpty"), Array(null, Val.False(dummyPos), Val.False(dummyPos))) {
+ override def evalRhs(args: Array[_ <: Lazy], ev: EvalScope, pos: Position): Val = {
+ val arr = args(0).force.asArr
+ val keyF = args(1).force
+ val onEmpty = args(2)
+ if (arr.length == 0) {
+ if (onEmpty.isInstanceOf[Val.False]) {
+ Error.fail("Expected at least one element in array. Got none")
+ } else {
+ onEmpty.force
+ }
+ } else if (keyF.isInstanceOf[Val.False]) {
+ arr.asStrictArray.min(ev)
+ } else {
+ arr.asStrictArray.map(v => keyF.asInstanceOf[Val.Func].apply1(v, pos.fileScope.noOffsetPos)(ev)).min(ev)
+ }
+ }
+ }
+
+ private object MaxArray extends Val.Builtin("maxArray", Array("arr", "keyF", "onEmpty"), Array(null, Val.False(dummyPos), Val.False(dummyPos))) {
+ override def evalRhs(args: Array[_ <: Lazy], ev: EvalScope, pos: Position): Val = {
+ val arr = args(0).force.asArr
+ val keyF = args(1).force
+ val onEmpty = args(2)
+ if (arr.length == 0) {
+ if (onEmpty.isInstanceOf[Val.False]) {
+ Error.fail("Expected at least one element in array. Got none")
+ } else {
+ onEmpty.force
+ }
+ } else if (keyF.isInstanceOf[Val.False]) {
+ arr.asStrictArray.max(ev)
+ } else {
+ arr.asStrictArray.map(v => keyF.asInstanceOf[Val.Func].apply1(v, pos.fileScope.noOffsetPos)(ev)).max(ev)
+ }
}
}
-}
private object Any extends Val.Builtin1("any", "arr") {
def evalRhs(arr: Val, ev: EvalScope, pos: Position): Val = {
@@ -362,12 +403,12 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
}
}
- private object EncodeUTF8 extends Val.Builtin1("encodeUtf8", "s") {
+ private object EncodeUTF8 extends Val.Builtin1("encodeUTF8", "s") {
def evalRhs(s: Val, ev: EvalScope, pos: Position): Val =
new Val.Arr(pos, s.asString.getBytes(UTF_8).map(i => Val.Num(pos, i & 0xff)))
}
- private object DecodeUTF8 extends Val.Builtin1("decodeUtf8", "arr") {
+ private object DecodeUTF8 extends Val.Builtin1("decodeUTF8", "arr") {
def evalRhs(arr: Val, ev: EvalScope, pos: Position): Val =
new Val.Str(pos, new String(arr.asArr.iterator.map(_.cast[Val.Num].value.toByte).toArray, UTF_8))
}
@@ -489,31 +530,46 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
}
}
- private object Split extends Val.Builtin2("split", "str", "c") {
- def evalRhs(_str: Val, _c: Val, ev: EvalScope, pos: Position): Val = {
- val str = _str.asString
- val cStr = _c.asString
- if(cStr.length != 1) Error.fail("std.split second parameter should have length 1, got "+cStr.length)
- val c = cStr.charAt(0)
- val b = new mutable.ArrayBuilder.ofRef[Lazy]
- var i = 0
- var start = 0
- while(i < str.length) {
- if(str.charAt(i) == c) {
- val finalStr = Val.Str(pos, str.substring(start, i))
+ private def splitLimit(pos: Position, str: String, cStr: String, maxSplits: Int): Array[Lazy] = {
+ val b = new mutable.ArrayBuilder.ofRef[Lazy]
+ var sz = 0
+ var i = 0
+ var start = 0
+ breakable {
+ while (i < str.length) {
+ if (maxSplits >= 0 && sz >= maxSplits) {
+ break
+ }
+ if (str.slice(i, i + cStr.length) == cStr) {
+ val finalStr = Val.Str(pos, str.slice(start, i))
b.+=(finalStr)
- start = i+1
+ start = i + cStr.length
+ sz += 1
}
i += 1
}
- b.+=(Val.Str(pos, str.substring(start, math.min(i, str.length))))
- new Val.Arr(pos, b.result())
+ }
+ b.+=(Val.Str(pos, str.substring(start)))
+ sz += 1
+ b.result()
+ }
+
+ private object Split extends Val.Builtin2("split", "str", "c") {
+ def evalRhs(str: Val, c: Val, ev: EvalScope, pos: Position): Val = {
+ new Val.Arr(pos, splitLimit(pos, str.asString, c.asString, -1))
}
}
private object SplitLimit extends Val.Builtin3("splitLimit", "str", "c", "maxSplits") {
def evalRhs(str: Val, c: Val, maxSplits: Val, ev: EvalScope, pos: Position): Val = {
- new Val.Arr(pos, str.asString.split(java.util.regex.Pattern.quote(c.asString), maxSplits.asInt + 1).map(s => Val.Str(pos, s)))
+ new Val.Arr(pos, splitLimit(pos, str.asString, c.asString, maxSplits.asInt))
+ }
+ }
+
+ private object SplitLimitR extends Val.Builtin3("splitLimitR", "str", "c", "maxSplits") {
+ def evalRhs(str: Val, c: Val, maxSplits: Val, ev: EvalScope, pos: Position): Val = {
+ new Val.Arr(pos, splitLimit(pos, str.asString.reverse, c.asString.reverse, maxSplits.asInt)
+ .map(s => Val.Str(pos, s.force.asString.reverse)).reverse)
}
}
@@ -1131,8 +1187,8 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
}
},
- "encodeUTF8" -> EncodeUTF8,
- "decodeUTF8" -> DecodeUTF8,
+ builtin(EncodeUTF8),
+ builtin(DecodeUTF8),
builtinWithDefaults("uniq", "arr" -> null, "keyF" -> Val.False(dummyPos)) { (args, pos, ev) =>
uniqArr(pos, ev, args(0), args(1))
@@ -1206,15 +1262,16 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
existsInSet(ev, pos, keyF, arr, args(0))
},
- "split" -> Split,
- "splitLimit" -> SplitLimit,
- "stringChars" -> StringChars,
- "parseInt" -> ParseInt,
- "parseOctal" -> ParseOctal,
- "parseHex" -> ParseHex,
- "parseJson" -> ParseJson,
- "parseYaml" -> ParseYaml,
- "md5" -> MD5,
+ builtin(Split),
+ builtin(SplitLimit),
+ builtin(SplitLimitR),
+ builtin(StringChars),
+ builtin(ParseInt),
+ builtin(ParseOctal),
+ builtin(ParseHex),
+ builtin(ParseJson),
+ builtin(ParseYaml),
+ builtin(MD5),
builtin("prune", "x"){ (pos, ev, s: Val) =>
def filter(x: Val) = x match{
case c: Val.Arr if c.length == 0 => false
@@ -1248,7 +1305,7 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
str.isEmpty
},
builtin("trim", "str") { (_, _, str: String) =>
- str.trim
+ trailingWhiteSpacePattern.matcher(leadingWhiteSpacePattern.matcher(str).replaceAll("")).replaceAll("")
},
builtin("equalsIgnoreCase", "str1", "str2") { (_, _, str1: String, str2: String) =>
str1.equalsIgnoreCase(str2)
@@ -1271,6 +1328,64 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
builtin("sha3", "str") { (_, _, str: String) =>
Platform.sha3(str)
},
+ builtin("sum", "arr") { (_, _, arr: Val.Arr) =>
+ if (!arr.forall(_.isInstanceOf[Val.Num])) {
+ Error.fail("Argument must be an array of numbers")
+ }
+ arr.asLazyArray.map(_.force.asDouble).sum
+ },
+ builtin("avg", "arr") { (_, _, arr: Val.Arr) =>
+ if (!arr.forall(_.isInstanceOf[Val.Num])) {
+ Error.fail("Argument must be an array of numbers")
+ }
+ if (arr.length == 0) {
+ Error.fail("Cannot calculate average of an empty array")
+ }
+ arr.asLazyArray.map(_.force.asDouble).sum/arr.length
+ },
+ builtin("contains", "arr", "elem") { (_, ev, arr: Val.Arr, elem: Val) =>
+ arr.asLazyArray.indexWhere(s => ev.equal(s.force, elem)) != -1
+ },
+ builtin("remove", "arr", "elem") { (_, ev, arr: Val.Arr, elem: Val) =>
+ val idx = arr.asLazyArray.indexWhere(s => ev.equal(s.force, elem))
+ if (idx == -1) {
+ arr
+ } else {
+ new Val.Arr(arr.pos, arr.asLazyArray.slice(0, idx) ++ arr.asLazyArray.slice(idx + 1, arr.length))
+ }
+ },
+ builtin("removeAt", "arr", "idx") { (_, _, arr: Val.Arr, idx: Int) =>
+ if (!(0 <= idx && idx < arr.length)) {
+ Error.fail("index out of bounds: 0 <= " + idx + " < " + arr.length)
+ }
+ new Val.Arr(arr.pos, arr.asLazyArray.slice(0, idx) ++ arr.asLazyArray.slice(idx + 1, arr.length))
+ },
+ builtin("objectKeysValues", "o") { (pos, ev, o: Val.Obj) =>
+ val keys = getVisibleKeys(ev, o)
+ new Val.Arr(pos, keys.map(k => Val.Obj.mk(
+ pos.fileScope.noOffsetPos,
+ "key" -> new Val.Obj.ConstMember(false, Visibility.Normal, Val.Str(pos.fileScope.noOffsetPos, k)),
+ "value" -> new Val.Obj.ConstMember(false, Visibility.Normal, o.value(k, pos.fileScope.noOffsetPos)(ev))
+ )))
+ },
+ builtin("objectKeysValuesAll", "o") { (pos, ev, o: Val.Obj) =>
+ val keys = getAllKeys(ev, o)
+ new Val.Arr(pos, keys.map(k => Val.Obj.mk(
+ pos.fileScope.noOffsetPos,
+ "key" -> new Val.Obj.ConstMember(false, Visibility.Normal, Val.Str(pos.fileScope.noOffsetPos, k)),
+ "value" -> new Val.Obj.ConstMember(false, Visibility.Normal, o.value(k, pos.fileScope.noOffsetPos)(ev))
+ )))
+ },
+ builtin("objectRemoveKey", "obj", "key") { (pos, ev, o: Val.Obj, key: String) =>
+ val bindings = for{
+ k <- o.visibleKeyNames
+ v = o.value(k, pos.fileScope.noOffsetPos)(ev)
+ if k != key
+ }yield (k, new Val.Obj.ConstMember(false, Visibility.Normal, v))
+ Val.Obj.mk(pos, bindings: _*)
+ },
+ builtin(MinArray),
+ builtin(MaxArray),
)
private def toSetArrOrString(args: Array[Val], idx: Int, pos: Position, ev: EvalScope) = {
@@ -1316,12 +1431,7 @@ private object Get extends Val.Builtin("get", Array("o", "f", "default", "inc_hi
case keyFFunc: Val.Func => keyFFunc.apply1(value, pos.noOffset)(ev)
case _ => value
}
- toFind.force match {
- case s: Val.Str if appliedValue.isInstanceOf[Val.Str] => Ordering.String.compare(s.asString, appliedValue.force.asString)
- case n: Val.Num if appliedValue.isInstanceOf[Val.Num] => java.lang.Double.compare(n.asDouble, appliedValue.force.asDouble)
- case t: Val.Bool if appliedValue.isInstanceOf[Val.Bool] => Ordering.Boolean.compare(t.asBoolean, appliedValue.force.asBoolean)
- case _ => Error.fail("Cannot perform set operation on " + toFind.force.prettyName + " and " + appliedValue.force.prettyName)
- }
+ ev.compare(toFind.force, appliedValue.force)
}).isInstanceOf[Found]
} else {
arr.exists(value => {
diff --git a/sjsonnet/src/sjsonnet/Val.scala b/sjsonnet/src/sjsonnet/Val.scala
index 645cfb5e..e1d5fa25 100644
--- a/sjsonnet/src/sjsonnet/Val.scala
+++ b/sjsonnet/src/sjsonnet/Val.scala
@@ -2,7 +2,6 @@ package sjsonnet
import java.util
import java.util.Arrays
-
import sjsonnet.Expr.Member.Visibility
import sjsonnet.Expr.Params
@@ -561,7 +560,7 @@ object Val{
* [[EvalScope]] models the per-evaluator context that is propagated
* throughout the Jsonnet evaluation.
*/
-abstract class EvalScope extends EvalErrorScope {
+abstract class EvalScope extends EvalErrorScope with Ordering[Val] {
def visitExpr(expr: Expr)
(implicit scope: ValScope): Val
@@ -569,6 +568,8 @@ abstract class EvalScope extends EvalErrorScope {
def equal(x: Val, y: Val): Boolean
+ def compare(x: Val, y: Val): Int
+
val emptyMaterializeFileScope = new FileScope(wd / "(materialize)")
val emptyMaterializeFileScopePos = new Position(emptyMaterializeFileScope, -1)
diff --git a/sjsonnet/test/resources/test_suite/arith_float.jsonnet b/sjsonnet/test/resources/test_suite/arith_float.jsonnet
index 06d1d479..e1c8cc3c 100644
--- a/sjsonnet/test/resources/test_suite/arith_float.jsonnet
+++ b/sjsonnet/test/resources/test_suite/arith_float.jsonnet
@@ -101,7 +101,9 @@ std.assertEqual(4.5 / 3, 1.5) &&
std.assertEqual(4.5 % 2, 0.5) &&
std.assertEqual(4.5 << 2, 16) &&
+std.assertEqual(4.5 << 66, 16) &&
std.assertEqual(4.5 >> 2, 1) &&
+std.assertEqual(4.5 >> 66, 1) &&
std.assertEqual(4.5 ^ 3.6, 7) &&
std.assertEqual(5.5 & 3.3, 1) &&
std.assertEqual(4.5 | 1.9, 5) &&
@@ -134,4 +136,4 @@ local obj = {
std.assertEqual(obj.g, -1) &&
-true
+true
\ No newline at end of file
diff --git a/sjsonnet/test/resources/test_suite/object.jsonnet b/sjsonnet/test/resources/test_suite/object.jsonnet
index 39e7f182..8cfd67b5 100644
--- a/sjsonnet/test/resources/test_suite/object.jsonnet
+++ b/sjsonnet/test/resources/test_suite/object.jsonnet
@@ -63,6 +63,9 @@ std.assertEqual({ ["" + (k + 1)]: (k + 1) for k in [0, 1, 2] }, { ["" + k]: k fo
std.assertEqual({ ["" + k]: k for k in [1, 2, 3] }, { "1": 1, "2": 2, "3": 3 }) &&
std.assertEqual({ [x + ""]: x + foo, local foo = 3 for x in [1, 2, 3] }, { "1": 4, "2": 5, "3": 6 }) &&
+// Test for #791
+std.assertEqual({ [x]: true for x in ['\\k'] }, { '\\k': true }) &&
+
local obj = {
f14true: { x: 1, y: 4, z: true },
@@ -77,6 +80,11 @@ local obj = {
std.assertEqual(obj, { ["f" + x + y + z]: { x: x, y: y, z: z } for x in [1, 2, 3] for y in [1, 4, 6] if x + 2 < y for z in [true, false] }) &&
+// Tests for #1111 - object comprehension fields should use "inherit" visibility.
+std.assertEqual(std.objectFields({ x: 1 } + { [k]: 2 for k in ['x'] }), ['x']) &&
+std.assertEqual(std.objectFields({ x:: 1 } + { [k]: 2 for k in ['x'] }), []) &&
+std.assertEqual(std.objectFields({ x::: 1 } + { [k]: 2 for k in ['x'] }), ['x']) &&
+
std.assertEqual({ f: { foo: 7, bar: 1 } { [self.name]+: 3, name:: "foo" }, name:: "bar" },
{ f: { foo: 7, bar: 4 } }) &&
@@ -108,4 +116,4 @@ std.assertEqual({ x: 1, a: "x" in self, b: "y" in self }, { x: 1, a: true, b: fa
std.assertEqual({ x:: 1, a: "x" in self, b: "y" in self }, { a: true, b: false }) &&
std.assertEqual({ f: "f" in self }, { f: true }) &&
-true
+true
\ No newline at end of file
diff --git a/sjsonnet/test/resources/test_suite/stdlib.jsonnet b/sjsonnet/test/resources/test_suite/stdlib.jsonnet
index 23ff1fdf..94bf40a9 100644
--- a/sjsonnet/test/resources/test_suite/stdlib.jsonnet
+++ b/sjsonnet/test/resources/test_suite/stdlib.jsonnet
@@ -55,9 +55,6 @@ std.assertEqual(std.sqrt(16), 4) &&
std.assertEqual(std.abs(33), 33) &&
std.assertEqual(std.abs(-33), 33) &&
std.assertEqual(std.abs(0), 0) &&
-std.assertEqual(std.mod(20, 10), 0) &&
-std.assertEqual(std.max(0, 1), 1) &&
-std.assertEqual(std.min(0, 1), 0) &&
// Ordinary (non-test) code can define pi as 2*std.acos(0)
local pi = 3.14159265359;
@@ -85,6 +82,10 @@ assertClose(std.exponent(1), 1) &&
assertClose(std.mantissa(128), 0.5) &&
assertClose(std.exponent(128), 8) &&
+std.assertEqual(std.clamp(-3, 0, 5), 0) &&
+std.assertEqual(std.clamp(4, 0, 5), 4) &&
+std.assertEqual(std.clamp(7, 0, 5), 5) &&
+
std.assertEqual(std.type(null), 'null') &&
std.assertEqual(std.type(true), 'boolean') &&
std.assertEqual(std.type(false), 'boolean') &&
@@ -112,6 +113,15 @@ std.assertEqual(std.isObject(null), false) &&
std.assertEqual(std.isArray(null), false) &&
std.assertEqual(std.isFunction(null), false) &&
+std.assertEqual(std.member('foo', 'o'), true) &&
+std.assertEqual(std.member('foo', 'f'), true) &&
+std.assertEqual(std.member('foo', 'x'), false) &&
+std.assertEqual(std.member([], 'o'), false) &&
+std.assertEqual(std.member(['f'], 'o'), false) &&
+std.assertEqual(std.member(['f', 'o', 'o'], 'o'), true) &&
+std.assertEqual(std.member(['f', 'o', 'o'], 'f'), true) &&
+std.assertEqual(std.member(['f', 'o', 'o'], 'g'), false) &&
+
std.assertEqual(std.count([true, false, false, true, true, true, false], true), 4) &&
std.assertEqual(std.count([true, false, false, true, true, true, false], false), 3) &&
@@ -148,7 +158,6 @@ std.assertEqual(std.objectFields({ x::: 1 } { x::: 1 }), ['x']) &&
std.assertEqual(std.objectValues({}), []) &&
std.assertEqual(std.objectValues({ x: 1, y: 2 }), [1, 2]) &&
-std.assertEqual(std.objectValues({ a: 1, b: 2, c: null}), [1, 2, null]) &&
std.assertEqual(std.objectValues({ x: 1 } { x: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x: 1 } { x:: 1 }), []) &&
std.assertEqual(std.objectValues({ x: 1 } { x::: 1 }), [1]) &&
@@ -158,21 +167,38 @@ std.assertEqual(std.objectValues({ x:: 1 } { x::: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x::: 1 } { x: 1 }), [1]) &&
std.assertEqual(std.objectValues({ x::: 1 } { x:: 1 }), []) &&
std.assertEqual(std.objectValues({ x::: 1 } { x::: 1 }), [1]) &&
-std.assertEqual(std.objectValues({ a: 1, b: "2", c: [1, 2], d: {x: 1, y: [2, 3]}}), [1, "2", [1, 2], {x: 1, y: [2, 3]}]) &&
-
-std.assertEqual(std.objectValuesAll({}), []) &&
-std.assertEqual(std.objectValuesAll({ x: 1, y: 2 }), [1, 2]) &&
-std.assertEqual(std.objectValuesAll({ a: 1, b: 2, c: null}), [1, 2, null]) &&
-std.assertEqual(std.objectValuesAll({ x: 1 } { x: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x: 1 } { x:: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x: 1 } { x::: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x:: 1 } { x: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x:: 1 } { x:: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x:: 1 } { x::: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x::: 1 } { x: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x::: 1 } { x:: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ x::: 1 } { x::: 1 }), [1]) &&
-std.assertEqual(std.objectValuesAll({ a: 1, b: "2", c: [1, 2], d: {x: 1, y: [2, 3]}}), [1, "2", [1, 2], {x: 1, y: [2, 3]}]) &&
+
+std.assertEqual(std.objectKeysValues({}), []) &&
+std.assertEqual(std.objectKeysValues({ x: 1, y: 2 }), [{ key: 'x', value: 1 }, { key: 'y', value: 2 }]) &&
+std.assertEqual(std.objectKeysValues({ x: 1 } { x: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x: 1 } { x::: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x:: 1 } { x: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x:: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x:: 1 } { x::: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x::: 1 } { x: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x::: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x::: 1 } { x::: 1 }), [{ key: 'x', value: 1 }]) &&
+
+std.assertEqual(std.get({ x: 1, y: 2 }, 'x', 5), 1) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'z', 5), 5) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'z'), null) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'x', 5), 1) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'z', 5), 5) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'z'), null) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'x', 5), 1) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'x'), 1) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'z', 5), 5) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'z'), null) &&
+std.assertEqual(std.get({}, 'z', 5), 5) &&
+std.assertEqual(std.get({}, 'z'), null) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'x', 5, false), 1) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'z', 5, false), 5) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'x', 5, false), 1) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'z', 5, false), 5) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'x', 5, false), 5) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'z', 5, false), 5) &&
+std.assertEqual(std.get({}, 'z', 5, false), 5) &&
std.assertEqual(std.toString({ a: 1, b: 2 }), '{"a": 1, "b": 2}') &&
std.assertEqual(std.toString({}), '{ }') &&
@@ -187,9 +213,16 @@ std.assertEqual(std.toString([1, 2, 'foo']), '[1, 2, "foo"]') &&
std.assertEqual(std.substr('cookie', 1, 3), 'ook') &&
std.assertEqual(std.substr('cookie', 1, 0), '') &&
-std.assertEqual(std.substr('cookie', 6, 2), '') &&
-std.assertEqual(std.substr('cookie', 6, 0), '') &&
+std.assertEqual(std.substr('cookie', 1, 15), 'ookie') &&
+std.assertEqual(std.substr('cookie', 0, 5), 'cooki') &&
std.assertEqual(std.substr('cookie', 0, 6), 'cookie') &&
+std.assertEqual(std.substr('cookie', 0, 15), 'cookie') &&
+std.assertEqual(std.substr('cookie', 3, 1), 'k') &&
+std.assertEqual(std.substr('cookie', 20, 1), '') &&
+std.assertEqual(std.substr('cookie', 6, 1), '') &&
+
+
+std.assertEqual(std.substr('ąę', 1, 1), 'ę') &&
std.assertEqual(std.startsWith('food', 'foo'), true) &&
std.assertEqual(std.startsWith('food', 'food'), true) &&
@@ -201,6 +234,21 @@ std.assertEqual(std.endsWith('food', 'food'), true) &&
std.assertEqual(std.endsWith('food', 'omgfood'), false) &&
std.assertEqual(std.endsWith('food', 'wat'), false) &&
+std.assertEqual(std.stripChars(' test test test ', ' '), 'test test test') &&
+std.assertEqual(std.stripChars('aaabbbbcccc', 'ac'), 'bbbb') &&
+std.assertEqual(std.stripChars('cacabbbbaacc', 'ac'), 'bbbb') &&
+std.assertEqual(std.stripChars('', 'ac'), '') &&
+
+std.assertEqual(std.lstripChars(' test test test ', ' '), 'test test test ') &&
+std.assertEqual(std.lstripChars('aaabbbbcccc', 'ac'), 'bbbbcccc') &&
+std.assertEqual(std.lstripChars('cacabbbbaacc', 'ac'), 'bbbbaacc') &&
+std.assertEqual(std.lstripChars('', 'ac'), '') &&
+
+std.assertEqual(std.rstripChars(' test test test ', ' '), ' test test test') &&
+std.assertEqual(std.rstripChars('aaabbbbcccc', 'ac'), 'aaabbbb') &&
+std.assertEqual(std.rstripChars('cacabbbbaacc', 'ac'), 'cacabbbb') &&
+std.assertEqual(std.rstripChars('', 'ac'), '') &&
+
std.assertEqual(std.codepoint('a'), 97) &&
std.assertEqual(std.char(97), 'a') &&
std.assertEqual(std.codepoint('\u0000'), 0) &&
@@ -225,6 +273,10 @@ std.assertEqual(std.mapWithIndex(function(i, x) x * i, std.filter(function(x) x
std.assertEqual(std.mapWithKey(function(k, o) k + o, {}), {}) &&
std.assertEqual(std.mapWithKey(function(k, o) k + o, { a: 1, b: 2 }), { a: 'a1', b: 'b2' }) &&
+std.assertEqual(std.flatMap(function(x) [x, x], [1, 2, 3]), [1, 1, 2, 2, 3, 3]) &&
+std.assertEqual(std.flatMap(function(x) if x == 2 then [] else [x], [1, 2, 3]), [1, 3]) &&
+std.assertEqual(std.flatMap(function(x) if x == 2 then [] else [x * 3, x * 2], [1, 2, 3]), [3, 2, 9, 6]) &&
+
std.assertEqual(std.filterMap(function(x) x >= 0, function(x) x * x, [-3, -2, -1, 0, 1, 2, 3]), [0, 1, 4, 9]) &&
std.assertEqual(std.foldl(function(x, y) [x, y], [], 'foo'), 'foo') &&
@@ -237,18 +289,35 @@ std.assertEqual(std.range(2, 6), [2, 3, 4, 5, 6]) &&
std.assertEqual(std.range(2, 2), [2]) &&
std.assertEqual(std.range(2, 1), []) &&
+std.assertEqual(std.repeat([], 0), []) &&
+std.assertEqual(std.repeat([1], 1), [1]) &&
+std.assertEqual(std.repeat([1, 2], 1), [1, 2]) &&
+std.assertEqual(std.repeat([1], 2), [1, 1]) &&
+std.assertEqual(std.repeat([1, 2], 2), [1, 2, 1, 2]) &&
+std.assertEqual(std.repeat('a', 1), 'a') &&
+std.assertEqual(std.repeat('a', 4), 'aaaa') &&
+std.assertEqual(std.repeat('ab', 4), 'abababab') &&
+std.assertEqual(std.repeat('a', 0), '') &&
+
std.assertEqual(std.join([], [[1, 2], [3, 4, 5], [6]]), [1, 2, 3, 4, 5, 6]) &&
std.assertEqual(std.join(['a', 'b'], [[]]), []) &&
std.assertEqual(std.join(['a', 'b'], []), []) &&
std.assertEqual(std.join(['a', 'b'], [null, [1, 2], null, [3, 4, 5], [6], null]), [1, 2, 'a', 'b', 3, 4, 5, 'a', 'b', 6]) &&
+std.assertEqual(std.join(['a', 'b'], [[], [1, 2]]), ['a', 'b', 1, 2]) &&
std.assertEqual(std.join('', [null, '12', null, '345', '6', null]), '123456') &&
std.assertEqual(std.join('ab', ['']), '') &&
std.assertEqual(std.join('ab', []), '') &&
std.assertEqual(std.join('ab', [null, '12', null, '345', '6', null]), '12ab345ab6') &&
+std.assertEqual(std.join('ab', ['', '12']), 'ab12') &&
std.assertEqual(std.lines(['a', null, 'b']), 'a\nb\n') &&
std.assertEqual(std.flattenArrays([[1, 2, 3], [4, 5, 6], []]), [1, 2, 3, 4, 5, 6]) &&
+//std.assertEqual(std.flattenDeepArray([]), []) &&
+//std.assertEqual(std.flattenDeepArray([1, 2, 3]), [1, 2, 3]) &&
+//std.assertEqual(std.flattenDeepArray([1, [2, 3]]), [1, 2, 3]) &&
+//std.assertEqual(std.flattenDeepArray([[1], [2, 3], [[null]]]), [1, 2, 3, null]) &&
+
std.assertEqual(
std.manifestIni({
main: { a: '1', b: '2' },
@@ -278,13 +347,7 @@ std.assertEqual(
sections: {
s2: { p: ['yes', ''] },
},
- }), |||
- a = 1
- a = 2
- [s2]
- p = yes
- p =
- |||
+ }), 'a = 1\na = 2\n[s2]\np = yes\np = \n'
) &&
@@ -293,6 +356,11 @@ std.assertEqual(std.escapeStringJson('he"llo'), '"he\\"llo"') &&
std.assertEqual(std.escapeStringJson('he"llo'), '"he\\"llo"') &&
std.assertEqual(std.escapeStringBash("he\"l'lo"), "'he\"l'\"'\"'lo'") &&
std.assertEqual(std.escapeStringDollars('The path is ${PATH}.'), 'The path is $${PATH}.') &&
+//std.assertEqual(std.escapeStringXML('2 < 3'), '2 < 3') &&
+//std.assertEqual(std.escapeStringXML('3 > 2'), '3 > 2') &&
+//std.assertEqual(std.escapeStringXML('"foo"'), '"foo"') &&
+//std.assertEqual(std.escapeStringXML("don't believe the hype"), 'don't believe the hype') &&
+//std.assertEqual(std.escapeStringXML('PB&J'), 'PB&J') &&
std.assertEqual(std.escapeStringJson('!~'), '"!~"') &&
std.assertEqual(std.manifestPython({
@@ -354,8 +422,11 @@ std.assertEqual(std.base64Decode('SGVsbG8gV29ybGQ='), 'Hello World') &&
std.assertEqual(std.base64Decode('SGVsbG8gV29ybA=='), 'Hello Worl') &&
std.assertEqual(std.base64Decode(''), '') &&
-std.assertEqual(std.decodeUTF8([36, 194, 162, 224, 164, 185, 226, 130, 172, 240, 144, 141, 136]), '\u0024\u00a2\u0939\u20AC\uD800\uDF48') &&
-std.assertEqual(std.encodeUTF8('\u0024\u00a2\u0939\u20AC\uD800\uDF48'), [36, 194, 162, 224, 164, 185, 226, 130, 172, 240, 144, 141, 136]) &&
+std.assertEqual(std.reverse([]), []) &&
+std.assertEqual(std.reverse([1]), [1]) &&
+std.assertEqual(std.reverse([1, 2]), [2, 1]) &&
+std.assertEqual(std.reverse([1, 2, 3]), [3, 2, 1]) &&
+std.assertEqual(std.reverse([[1, 2, 3]]), [[1, 2, 3]]) &&
std.assertEqual(std.sort([]), []) &&
std.assertEqual(std.sort([1]), [1]) &&
@@ -431,9 +502,106 @@ std.assertEqual(std.extVar('var2') { x+: 2 }.x, 3) &&
std.assertEqual(std.split('foo/bar', '/'), ['foo', 'bar']) &&
std.assertEqual(std.split('/foo/', '/'), ['', 'foo', '']) &&
+std.assertEqual(std.split('foo/_bar', '/_'), ['foo', 'bar']) &&
+std.assertEqual(std.split('/_foo/_', '/_'), ['', 'foo', '']) &&
std.assertEqual(std.splitLimit('foo/bar', '/', 1), ['foo', 'bar']) &&
std.assertEqual(std.splitLimit('/foo/', '/', 1), ['', 'foo/']) &&
+std.assertEqual(std.splitLimit('foo/_bar', '/_', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimit('/_foo/_', '/_', 1), ['', 'foo/_']) &&
+
+std.assertEqual(std.splitLimitR('foo/bar', '/', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimitR('/foo/', '/', 1), ['/foo', '']) &&
+std.assertEqual(std.splitLimitR('/foo/', '/', -1), ['', 'foo', '']) &&
+std.assertEqual(std.splitLimitR('foo/_bar', '/_', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimitR('/_foo/_', '/_', 1), ['/_foo', '']) &&
+std.assertEqual(std.splitLimitR('/_foo/_', '/_', -1), ['', 'foo', '']) &&
+
+//local some_toml = {
+// key: 'value',
+// simple: { t: 5 },
+// section: {
+// a: 1,
+// nested: { b: 2 },
+// 'e$caped': { q: 't' },
+// array: [
+// { c: 3 },
+// { d: 4 },
+// ],
+// nestedArray: [{
+// k: 'v',
+// nested: { e: 5 },
+// }],
+// },
+// arraySection: [
+// { q: 1 },
+// { w: 2 },
+// ],
+// 'escaped"Section': { z: 'q' },
+// emptySection: {},
+// emptyArraySection: [{}],
+// bool: true,
+// notBool: false,
+// number: 7,
+// array: ['s', 1, [2, 3], { r: 6, a: ['0', 'z'] }],
+// emptyArray: [],
+// '"': 4,
+//};
+//
+//std.assertEqual(
+// std.manifestTomlEx(some_toml, ' ') + '\n',
+// |||
+// "\"" = 4
+// array = [
+// "s",
+// 1,
+// [ 2, 3 ],
+// { a = [ "0", "z" ], r = 6 }
+// ]
+// bool = true
+// emptyArray = []
+// key = "value"
+// notBool = false
+// number = 7
+//
+// [[arraySection]]
+// q = 1
+//
+// [[arraySection]]
+// w = 2
+//
+// [[emptyArraySection]]
+//
+// [emptySection]
+//
+// ["escaped\"Section"]
+// z = "q"
+//
+// [section]
+// a = 1
+//
+// [[section.array]]
+// c = 3
+//
+// [[section.array]]
+// d = 4
+//
+// [section."e$caped"]
+// q = "t"
+//
+// [section.nested]
+// b = 2
+//
+// [[section.nestedArray]]
+// k = "v"
+//
+// [section.nestedArray.nested]
+// e = 5
+//
+// [simple]
+// t = 5
+// |||
+//) &&
local some_json = {
x: [1, 2, 3, true, false, null, 'string\nstring\n'],
@@ -445,48 +613,149 @@ local some_json = {
'"': null,
};
+local bare_yaml_quoted = {
+ '685230': 'canonical',
+ '+685_230': 'decimal',
+ '02472256': 'octal',
+ '-1_0': 'negative integer',
+ '-0.1_0_0': 'negative float',
+ '0x_0A_74_AE': 'hexadecimal',
+ '-0x_0A_74_AE': 'negative hexadecimal',
+ '0b1010_0111_0100_1010_1110': 'binary',
+ '-0b1010_0111_0100_1010_1110': 'binary',
+ '190:20:30': 'sexagesimal',
+ '-190:20:30': 'negative sexagesimal',
+ '6.8523015e+5': 'canonical',
+ '6.8523015e-5': 'canonical',
+ '-6.8523015e+5': 'negative canonical',
+ '685.230_15e+03': 'exponential',
+ '-685.230_15e+03': 'negative exponential',
+ '-685.230_15e-03': 'negative w/ negative exponential',
+ '-685.230_15E-03': 'negative w/ negative exponential',
+ '685_230.15': 'fixed',
+ '-685_230.15': 'negative fixed',
+ '190:20:30.15': 'sexagesimal',
+ '-190:20:30.15': 'negative sexagesimal',
+ '-.inf': 'negative infinity',
+ '.inf': 'positive infinity',
+ '+.inf': 'positive infinity',
+ '.NaN': 'not a number',
+ y: 'boolean true',
+ yes: 'boolean true',
+ Yes: 'boolean true',
+ True: 'boolean true',
+ 'true': 'boolean true',
+ on: 'boolean true',
+ On: 'boolean true',
+ NO: 'boolean false',
+ n: 'boolean false',
+ N: 'boolean false',
+ off: 'boolean false',
+ OFF: 'boolean false',
+ 'null': 'null word',
+ NULL: 'null word capital',
+ Null: 'null word',
+ '~': 'null key',
+ '': 'empty key',
+ '-': 'invalid bare key',
+ '---': 'triple dash key',
+ '2001-12-15T02:59:43.1Z': 'canonical',
+ '2001-12-14t21:59:43.10-05:00': 'valid iso8601',
+ '2001-12-14 21:59:43.10 -5': 'space separated',
+ '2001-12-15 2:59:43.10': 'no time zone (Z)',
+ '2002-12-14': 'date',
+};
+local bare_yaml_unquoted = {
+ '0X_0a_74_ae': 'BARE_KEY',
+ '__-0X_0a_74_ae': 'BARE_KEY',
+ '-0B1010_0111_0100_1010_1110': 'BARE_KEY',
+ '__-0B1010_0111_0100_1010_1110': 'BARE_KEY',
+ x: 'BARE_KEY',
+ b: 'BARE_KEY',
+ just_letters_underscores: 'BARE_KEY',
+ 'just-letters-dashes': 'BARE_KEY',
+ 'jsonnet.org/k8s-label-like': 'BARE_KEY',
+ '192.168.0.1': 'BARE_KEY',
+ '1-234-567-8901': 'BARE_KEY',
+};
+local bare_yaml_test = bare_yaml_quoted + bare_yaml_unquoted;
+
std.assertEqual(
- std.manifestJsonEx(some_json, ' ') + '\n',
- |||
- {
- "\"": null,
- "arr": [
- [
- [
-
- ]
- ]
- ],
- "emptyArray": [
-
- ],
- "emptyObject": {
-
- },
- "objectInArray": [
- {
- "f": 3
- }
- ],
- "x": [
- 1,
- 2,
- 3,
- true,
- false,
- null,
- "string\nstring\n"
- ],
- "y": {
- "a": 1,
- "b": 2,
- "c": [
- 1,
- 2
- ]
- }
- }
- |||
+ std.manifestJsonEx(some_json, ' ') + '\n',
+ |||
+ {
+ "\"": null,
+ "arr": [
+ [
+ [
+
+ ]
+ ]
+ ],
+ "emptyArray": [
+
+ ],
+ "emptyObject": {
+
+ },
+ "objectInArray": [
+ {
+ "f": 3
+ }
+ ],
+ "x": [
+ 1,
+ 2,
+ 3,
+ true,
+ false,
+ null,
+ "string\nstring\n"
+ ],
+ "y": {
+ "a": 1,
+ "b": 2,
+ "c": [
+ 1,
+ 2
+ ]
+ }
+ }
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestJsonEx(some_json, '', ' ', ' : '),
+// '{ "\\"" : null, "arr" : [ [ [ ] ] ], "emptyArray" : [ ], '
+// + '"emptyObject" : { }, "objectInArray" : [ { "f" : 3 } ], '
+// + '"x" : [ 1, 2, 3, true, false, null, "string\\nstring\\n" ], '
+// + '"y" : { "a" : 1, "b" : 2, "c" : [ 1, 2 ] } }'
+//) &&
+
+std.assertEqual(
+ std.manifestJsonMinified(some_json),
+ '{"\\"":null,"arr":[[[]]],"emptyArray":[],"emptyObject":{},"objectInArray":[{"f":3}],'
+ + '"x":[1,2,3,true,false,null,"string\\nstring\\n"],"y":{"a":1,"b":2,"c":[1,2]}}'
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc([{ x: [1, 2, 3] }], quote_keys=false) + '\n',
+// |||
+// - x:
+// - 1
+// - 2
+// - 3
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlDoc([{ x: [1, 2, 3] }]) + '\n',
+ |||
+ - "x":
+ - 1
+ - 2
+ - 3
+ |||
) &&
std.assertEqual(
@@ -540,6 +809,21 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlDoc({ x: [[[1, { f: 3, g: [1, 2] }, 1]]] }, quote_keys=false) + '\n',
+// |||
+// x:
+// -
+// -
+// - 1
+// - f: 3
+// g:
+// - 1
+// - 2
+// - 1
+// |||
+//) &&
+
std.assertEqual(
std.manifestYamlDoc('hello\nworld\n') + '\n',
|||
@@ -567,6 +851,15 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlDoc({ f: 'hello\nworld\n' }, quote_keys=false) + '\n',
+// |||
+// f: |
+// hello
+// world
+// |||
+//) &&
+
std.assertEqual(
std.manifestYamlDoc(some_json) + '\n',
|||
@@ -597,6 +890,36 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlDoc(some_json, quote_keys=false) + '\n',
+// |||
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// |||
+//) &&
+
std.assertEqual(
std.manifestYamlDoc([{ x: [1, 2, 3] }], indent_array_in_object=true) + '\n',
|||
@@ -607,6 +930,16 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlDoc([{ x: [1, 2, 3] }], indent_array_in_object=true, quote_keys=false) + '\n',
+// |||
+// - x:
+// - 1
+// - 2
+// - 3
+// |||
+//) &&
+
std.assertEqual(
std.manifestYamlDoc({ x: [1, 2, 3] }, indent_array_in_object=true) + '\n',
|||
@@ -715,6 +1048,173 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlDoc(some_json, indent_array_in_object=true, quote_keys=false) + '\n',
+// |||
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// |||
+//) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc(bare_yaml_test, quote_keys=false) + '\n',
+// |||
+// "": "empty key"
+// "+.inf": "positive infinity"
+// "+685_230": "decimal"
+// "-": "invalid bare key"
+// "---": "triple dash key"
+// "-.inf": "negative infinity"
+// "-0.1_0_0": "negative float"
+// -0B1010_0111_0100_1010_1110: "BARE_KEY"
+// "-0b1010_0111_0100_1010_1110": "binary"
+// "-0x_0A_74_AE": "negative hexadecimal"
+// "-190:20:30": "negative sexagesimal"
+// "-190:20:30.15": "negative sexagesimal"
+// "-1_0": "negative integer"
+// "-6.8523015e+5": "negative canonical"
+// "-685.230_15E-03": "negative w/ negative exponential"
+// "-685.230_15e+03": "negative exponential"
+// "-685.230_15e-03": "negative w/ negative exponential"
+// "-685_230.15": "negative fixed"
+// ".NaN": "not a number"
+// ".inf": "positive infinity"
+// "02472256": "octal"
+// 0X_0a_74_ae: "BARE_KEY"
+// "0b1010_0111_0100_1010_1110": "binary"
+// "0x_0A_74_AE": "hexadecimal"
+// 1-234-567-8901: "BARE_KEY"
+// "190:20:30": "sexagesimal"
+// "190:20:30.15": "sexagesimal"
+// 192.168.0.1: "BARE_KEY"
+// "2001-12-14 21:59:43.10 -5": "space separated"
+// "2001-12-14t21:59:43.10-05:00": "valid iso8601"
+// "2001-12-15 2:59:43.10": "no time zone (Z)"
+// "2001-12-15T02:59:43.1Z": "canonical"
+// "2002-12-14": "date"
+// "6.8523015e+5": "canonical"
+// "6.8523015e-5": "canonical"
+// "685.230_15e+03": "exponential"
+// "685230": "canonical"
+// "685_230.15": "fixed"
+// "N": "boolean false"
+// "NO": "boolean false"
+// "NULL": "null word capital"
+// "Null": "null word"
+// "OFF": "boolean false"
+// "On": "boolean true"
+// "True": "boolean true"
+// "Yes": "boolean true"
+// __-0B1010_0111_0100_1010_1110: "BARE_KEY"
+// __-0X_0a_74_ae: "BARE_KEY"
+// b: "BARE_KEY"
+// jsonnet.org/k8s-label-like: "BARE_KEY"
+// just-letters-dashes: "BARE_KEY"
+// just_letters_underscores: "BARE_KEY"
+// "n": "boolean false"
+// "null": "null word"
+// "off": "boolean false"
+// "on": "boolean true"
+// "true": "boolean true"
+// x: "BARE_KEY"
+// "y": "boolean true"
+// "yes": "boolean true"
+// "~": "null key"
+// |||
+//) &&
+//
+//std.assertEqual(
+// std.manifestYamlStream([bare_yaml_quoted, bare_yaml_unquoted], quote_keys=false),
+// |||
+// ---
+// "": "empty key"
+// "+.inf": "positive infinity"
+// "+685_230": "decimal"
+// "-": "invalid bare key"
+// "---": "triple dash key"
+// "-.inf": "negative infinity"
+// "-0.1_0_0": "negative float"
+// "-0b1010_0111_0100_1010_1110": "binary"
+// "-0x_0A_74_AE": "negative hexadecimal"
+// "-190:20:30": "negative sexagesimal"
+// "-190:20:30.15": "negative sexagesimal"
+// "-1_0": "negative integer"
+// "-6.8523015e+5": "negative canonical"
+// "-685.230_15E-03": "negative w/ negative exponential"
+// "-685.230_15e+03": "negative exponential"
+// "-685.230_15e-03": "negative w/ negative exponential"
+// "-685_230.15": "negative fixed"
+// ".NaN": "not a number"
+// ".inf": "positive infinity"
+// "02472256": "octal"
+// "0b1010_0111_0100_1010_1110": "binary"
+// "0x_0A_74_AE": "hexadecimal"
+// "190:20:30": "sexagesimal"
+// "190:20:30.15": "sexagesimal"
+// "2001-12-14 21:59:43.10 -5": "space separated"
+// "2001-12-14t21:59:43.10-05:00": "valid iso8601"
+// "2001-12-15 2:59:43.10": "no time zone (Z)"
+// "2001-12-15T02:59:43.1Z": "canonical"
+// "2002-12-14": "date"
+// "6.8523015e+5": "canonical"
+// "6.8523015e-5": "canonical"
+// "685.230_15e+03": "exponential"
+// "685230": "canonical"
+// "685_230.15": "fixed"
+// "N": "boolean false"
+// "NO": "boolean false"
+// "NULL": "null word capital"
+// "Null": "null word"
+// "OFF": "boolean false"
+// "On": "boolean true"
+// "True": "boolean true"
+// "Yes": "boolean true"
+// "n": "boolean false"
+// "null": "null word"
+// "off": "boolean false"
+// "on": "boolean true"
+// "true": "boolean true"
+// "y": "boolean true"
+// "yes": "boolean true"
+// "~": "null key"
+// ---
+// -0B1010_0111_0100_1010_1110: "BARE_KEY"
+// 0X_0a_74_ae: "BARE_KEY"
+// 1-234-567-8901: "BARE_KEY"
+// 192.168.0.1: "BARE_KEY"
+// __-0B1010_0111_0100_1010_1110: "BARE_KEY"
+// __-0X_0a_74_ae: "BARE_KEY"
+// b: "BARE_KEY"
+// jsonnet.org/k8s-label-like: "BARE_KEY"
+// just-letters-dashes: "BARE_KEY"
+// just_letters_underscores: "BARE_KEY"
+// x: "BARE_KEY"
+// ...
+// |||
+//) &&
+
std.assertEqual(
std.manifestYamlStream([some_json, some_json, {}, [], 3, '"']),
|||
@@ -780,6 +1280,71 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlStream([some_json, some_json, {}, [], 3, '"'], quote_keys=false),
+// |||
+// ---
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// ---
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// ---
+// {}
+// ---
+// []
+// ---
+// 3
+// ---
+// "\""
+// ...
+// |||
+//) &&
+
std.assertEqual(
std.manifestYamlStream([some_json, some_json, {}, [], 3, '"'], indent_array_in_object=true),
|||
@@ -845,6 +1410,20 @@ std.assertEqual(
|||
) &&
+//std.assertEqual(
+// std.manifestYamlStream([{}, [], 3, '"'], c_document_end=false),
+// |||
+// ---
+// {}
+// ---
+// []
+// ---
+// 3
+// ---
+// "\""
+// |||
+//) &&
+
std.assertEqual(std.parseInt('01234567890'), 1234567890) &&
std.assertEqual(std.parseInt('-01234567890'), -1234567890) &&
std.assertEqual(std.parseOctal('755'), 493) &&
@@ -853,7 +1432,15 @@ std.assertEqual(std.parseHex('ff'), 255) &&
std.assertEqual(std.parseHex('FF'), 255) &&
std.assertEqual(std.parseHex('0ff'), 255) &&
std.assertEqual(std.parseHex('0FF'), 255) &&
-
+std.assertEqual(std.parseHex('a'), 10) &&
+std.assertEqual(std.parseHex('A'), 10) &&
+std.assertEqual(std.parseHex('4a'), 74) &&
+
+// verified by running md5 -s value
+std.assertEqual(std.md5(''), 'd41d8cd98f00b204e9800998ecf8427e') &&
+std.assertEqual(std.md5('grape'), 'b781cbb29054db12f88f08c6e161c199') &&
+std.assertEqual(std.md5("{}[]01234567890\"'+=-_/<>?,.!@#$%^&*|\\:;`~"), 'a680db28332f0c9647376e5b2aeb4b3d') &&
+std.assertEqual(std.md5('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum si.'), '3496bb633e830e7679ce53700d42de1e') &&
std.assertEqual(std.parseInt('-01234567890'), -1234567890) &&
std.assertEqual(std.prune({}), {}) &&
@@ -871,10 +1458,63 @@ std.assertEqual(std.parseJson('[]'), []) &&
std.assertEqual(std.parseJson('null'), null) &&
std.assertEqual(std.parseJson('12'), 12) &&
std.assertEqual(std.parseJson('12.123'), 12.123) &&
-std.assertEqual(std.parseJson('{"a": 1}'), { a: 1}) &&
-std.assertEqual(std.parseJson('[5]'), [5]) &&
std.assertEqual(std.parseJson('{"a": {"b": ["c", 42]}}'), { a: { b: ['c', 42] } }) &&
+std.assertEqual(std.parseYaml('{}'), {}) &&
+std.assertEqual(std.parseYaml('[]'), []) &&
+std.assertEqual(
+ std.parseYaml(
+ |||
+ foo:
+ bar:
+ - true
+ - 42
+ - 1.0
+ |||
+ ), { foo: { bar: [true, 42, 1] } }
+) &&
+std.assertEqual(
+ std.parseYaml(
+ |||
+ ---
+ foo:
+ bar:
+ - true
+ - 42
+ - 1.0
+ ---
+ wibble:
+ wobble:
+ - true
+ - 42
+ - 1.0
+ |||
+ ), [{ foo: { bar: [true, 42, 1] } }, { wibble: { wobble: [true, 42, 1] } }]
+) &&
+std.assertEqual(
+ std.parseYaml(
+ |||
+ - 1
+ - 2
+ - 3
+ |||
+ ), [1, 2, 3]
+) &&
+std.assertEqual(
+ std.parseYaml(
+ |||
+ f1: |
+ a
+ b
+ f2: "a\nb\n"
+ |||
+ ), { f1: 'a\nb\n', f2: 'a\nb\n' }
+) &&
+// Issue https://github.com/google/jsonnet/issues/1014
+std.assertEqual(std.parseYaml('version: 1.2.3'), { version: '1.2.3' }) &&
+// Issue https://github.com/google/jsonnet/issues/1050
+std.assertEqual(std.type(std.parseYaml('id: "12345"').id), 'string') &&
+
std.assertEqual(std.asciiUpper('!@#$%&*()asdfghFGHJKL09876 '), '!@#$%&*()ASDFGHFGHJKL09876 ') &&
std.assertEqual(std.asciiLower('!@#$%&*()asdfghFGHJKL09876 '), '!@#$%&*()asdfghfghjkl09876 ') &&
@@ -897,16 +1537,80 @@ std.assertEqual(std.find('a', ['a']), [0]) &&
std.assertEqual(std.find('a', ['a', ['a'], 'b', 'a']), [0, 3]) &&
std.assertEqual(std.find(['a'], [['a']]), [0]) &&
-std.assertEqual(std.trace('', null), null) &&
-std.assertEqual(std.trace('', true), true) &&
-std.assertEqual(std.trace('', 77), 77) &&
-std.assertEqual(std.trace('', 77.88), 77.88) &&
-std.assertEqual(std.trace('', 'word'), 'word') &&
-std.assertEqual(std.foldl(std.trace('', function(acc, i) acc + i), [1, 2, 3], 0), 6) &&
-std.assertEqual(std.trace('', {}), {}) &&
-std.assertEqual(std.trace('', { a: {} }), { a: {} }) &&
-std.assertEqual(std.trace('', []), []) &&
-std.assertEqual(std.trace('', [{ a: 'b' }, { a: 'b' }]), [{ a: 'b' }, { a: 'b' }]) &&
-std.assertEqual(std.trace('Some Trace Message', { a: {} }), { a: {} }) &&
-
-true
+std.assertEqual(std.encodeUTF8(''), []) &&
+std.assertEqual(std.encodeUTF8('A'), [65]) &&
+std.assertEqual(std.encodeUTF8('AAA'), [65, 65, 65]) &&
+std.assertEqual(std.encodeUTF8('§'), [194, 167]) &&
+std.assertEqual(std.encodeUTF8('Zażółć gęślą jaźń'), [90, 97, 197, 188, 195, 179, 197, 130, 196, 135, 32, 103, 196, 153, 197, 155, 108, 196, 133, 32, 106, 97, 197, 186, 197, 132]) &&
+std.assertEqual(std.encodeUTF8('😃'), [240, 159, 152, 131]) &&
+
+std.assertEqual(std.decodeUTF8([]), '') &&
+std.assertEqual(std.decodeUTF8([65]), 'A') &&
+std.assertEqual(std.decodeUTF8([65, 65, 65]), 'AAA') &&
+std.assertEqual(std.decodeUTF8([(function(x) 65)(42)]), 'A') &&
+std.assertEqual(std.decodeUTF8([65 + 1 - 1]), 'A') &&
+std.assertEqual(std.decodeUTF8([90, 97, 197, 188, 195, 179, 197, 130, 196, 135, 32, 103, 196, 153, 197, 155, 108, 196, 133, 32, 106, 97, 197, 186, 197, 132]), 'Zażółć gęślą jaźń') &&
+std.assertEqual(std.decodeUTF8([240, 159, 152, 131]), '😃') &&
+
+std.assertEqual(std.any([true, false]), true) &&
+std.assertEqual(std.any([false, false]), false) &&
+std.assertEqual(std.any([]), false) &&
+
+std.assertEqual(std.all([true, false]), false) &&
+std.assertEqual(std.all([true, true]), true) &&
+std.assertEqual(std.all([]), true) &&
+
+std.assertEqual(std.sum([1, 2, 3]), 6) &&
+
+std.assertEqual(std.avg([1, 2, 3]), 2) &&
+std.assertEqual(std.avg([0, 0, 0]), 0) &&
+std.assertEqual(std.avg([1, 1, 2.5]), 1.5) &&
+
+std.assertEqual(std.minArray([1, 2, 3]), 1) &&
+std.assertEqual(std.minArray(['1', '2', '3']), '1') &&
+
+std.assertEqual(std.maxArray([1, 2, 3]), 3) &&
+std.assertEqual(std.maxArray(['1', '2', '3']), '3') &&
+std.assertEqual(std.maxArray(['a', 'x', 'z']), 'z') &&
+
+std.assertEqual(std.xor(true, false), true) &&
+std.assertEqual(std.xor(true, true), false) &&
+
+std.assertEqual(std.xnor(true, false), false) &&
+std.assertEqual(std.xnor(true, true), true) &&
+
+//std.assertEqual(std.round(1.2), 1) &&
+//std.assertEqual(std.round(1.5), 2) &&
+
+std.assertEqual(std.isEmpty(''), true) &&
+std.assertEqual(std.isEmpty('non-empty string'), false) &&
+
+std.assertEqual(std.contains([1, 2, 3], 2), true) &&
+std.assertEqual(std.contains([1, 2, 3], 'foo'), false) &&
+
+std.assertEqual(std.equalsIgnoreCase('foo', 'FOO'), true) &&
+std.assertEqual(std.equalsIgnoreCase('foo', 'bar'), false) &&
+
+//std.assertEqual(std.isEven(10), true) &&
+//std.assertEqual(std.isEven(5), false) &&
+//std.assertEqual(std.isOdd(5), true) &&
+//std.assertEqual(std.isOdd(10), false) &&
+//std.assertEqual(std.isInteger(1), true) &&
+//std.assertEqual(std.isInteger(1.1), false) &&
+//std.assertEqual(std.isDecimal(1.1), true) &&
+//std.assertEqual(std.isDecimal(1), false) &&
+
+std.assertEqual(std.remove([1, 2, 3], 2), [1, 3]) &&
+std.assertEqual(std.removeAt([1, 2, 3], 1), [1, 3]) &&
+
+std.assertEqual(std.objectRemoveKey({ foo: 1, bar: 2, baz: 3 }, 'foo'), { bar: 2, baz: 3 }) &&
+
+std.assertEqual(std.trim('already trimmed string'), 'already trimmed string') &&
+std.assertEqual(std.trim(' string with spaces on both ends '), 'string with spaces on both ends') &&
+std.assertEqual(std.trim('string with newline character at end\n'), 'string with newline character at end') &&
+std.assertEqual(std.trim('string with tabs at end\t\t'), 'string with tabs at end') &&
+// The last character here was previously expressed as \u00A0, but this is rewritten by jsonnetfmt.
+// To avoid ambiguity but allow the code to pass unchanged through jsonnetfmt, this now uses a std.char() call.
+std.assertEqual(std.trim('string with other special whitespaces at end\f\r\u0085' + std.char(160)), 'string with other special whitespaces at end') &&
+
+true
\ No newline at end of file
diff --git a/sjsonnet/test/resources/test_suite/stdlib_native.jsonnet b/sjsonnet/test/resources/test_suite/stdlib_native.jsonnet
new file mode 100644
index 00000000..218c3042
--- /dev/null
+++ b/sjsonnet/test/resources/test_suite/stdlib_native.jsonnet
@@ -0,0 +1,1616 @@
+/*
+Copyright 2015 Google Inc. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+// This file tests functions from the standard library (std.jsonnet and builtins).
+std.assertEqual(std.findSubstr('aa bb cc', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'), []) &&
+// Can capture std from another file.
+std.assertEqual((import 'lib/capture_std_func.libsonnet')().sqrt(4), 2) &&
+
+// Each import has its own std.
+std.assertEqual(
+ local std = { sqrt: function(x) x };
+ local lib = import 'lib/capture_std.libsonnet';
+ lib.sqrt(4),
+ 2
+) &&
+
+// Now, test each std library function in turn.
+
+std.assertEqual(std.makeArray(10, function(i) i + 1), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) &&
+std.assertEqual(std.makeArray(0, function(i) null), []) &&
+
+local assertClose(a, b) =
+ local err =
+ if b == 0 then
+ a - b
+ else
+ if a / b - 1 > 0 then a / b - 1 else 1 - a / b;
+ if err > 0.000005 then
+ error 'Assertion failed (error ' + err + '). ' + a + ' !~ ' + b
+ else
+ true;
+
+std.assertEqual(std.pow(3, 2), 9) &&
+std.assertEqual(std.floor(10), 10) &&
+std.assertEqual(std.floor(10.99999), 10) &&
+std.assertEqual(std.ceil(10), 10) &&
+std.assertEqual(std.ceil(10.99999), 11) &&
+std.assertEqual(std.sqrt(0), 0) &&
+std.assertEqual(std.sqrt(1), 1) &&
+std.assertEqual(std.sqrt(9), 3) &&
+std.assertEqual(std.sqrt(16), 4) &&
+std.assertEqual(std.abs(33), 33) &&
+std.assertEqual(std.abs(-33), 33) &&
+std.assertEqual(std.abs(0), 0) &&
+
+// Ordinary (non-test) code can define pi as 2*std.acos(0)
+local pi = 3.14159265359;
+
+assertClose(std.sin(0.0 * pi), 0) &&
+assertClose(std.sin(0.5 * pi), 1) &&
+assertClose(std.sin(1.0 * pi), 0) &&
+assertClose(std.sin(1.5 * pi), -1) &&
+assertClose(std.sin(2.0 * pi), 0) &&
+assertClose(std.cos(0.0 * pi), 1) &&
+assertClose(std.cos(0.5 * pi), 0) &&
+assertClose(std.cos(1.0 * pi), -1) &&
+assertClose(std.cos(1.5 * pi), 0) &&
+assertClose(std.cos(2.0 * pi), 1) &&
+assertClose(std.tan(0), 0) &&
+assertClose(std.tan(0.25 * pi), 1) &&
+assertClose(std.asin(0), 0) &&
+assertClose(std.acos(1), 0) &&
+assertClose(std.asin(1), 0.5 * pi) &&
+assertClose(std.acos(0), 0.5 * pi) &&
+assertClose(std.atan(0), 0) &&
+assertClose(std.log(std.exp(5)), 5) &&
+assertClose(std.mantissa(1), 0.5) &&
+assertClose(std.exponent(1), 1) &&
+assertClose(std.mantissa(128), 0.5) &&
+assertClose(std.exponent(128), 8) &&
+
+std.assertEqual(std.clamp(-3, 0, 5), 0) &&
+std.assertEqual(std.clamp(4, 0, 5), 4) &&
+std.assertEqual(std.clamp(7, 0, 5), 5) &&
+
+std.assertEqual(std.type(null), 'null') &&
+std.assertEqual(std.type(true), 'boolean') &&
+std.assertEqual(std.type(false), 'boolean') &&
+std.assertEqual(std.type(0), 'number') &&
+std.assertEqual(std.type(-1e10), 'number') &&
+std.assertEqual(std.type([1, 2, 3]), 'array') &&
+std.assertEqual(std.type([]), 'array') &&
+std.assertEqual(std.type(function(x) x), 'function') &&
+std.assertEqual(std.type({ x: 1, y: 2 }), 'object') &&
+std.assertEqual(std.type({}), 'object') &&
+std.assertEqual(std.type('fail'), 'string') &&
+std.assertEqual(std.type('' + {}), 'string') &&
+
+std.assertEqual(std.isString(''), true) &&
+std.assertEqual(std.isBoolean(true), true) &&
+std.assertEqual(std.isNumber(0), true) &&
+std.assertEqual(std.isObject({}), true) &&
+std.assertEqual(std.isArray([]), true) &&
+std.assertEqual(std.isFunction(function() 0), true) &&
+
+std.assertEqual(std.isString(null), false) &&
+std.assertEqual(std.isBoolean(null), false) &&
+std.assertEqual(std.isNumber(null), false) &&
+std.assertEqual(std.isObject(null), false) &&
+std.assertEqual(std.isArray(null), false) &&
+std.assertEqual(std.isFunction(null), false) &&
+
+std.assertEqual(std.member('foo', 'o'), true) &&
+std.assertEqual(std.member('foo', 'f'), true) &&
+std.assertEqual(std.member('foo', 'x'), false) &&
+std.assertEqual(std.member([], 'o'), false) &&
+std.assertEqual(std.member(['f'], 'o'), false) &&
+std.assertEqual(std.member(['f', 'o', 'o'], 'o'), true) &&
+std.assertEqual(std.member(['f', 'o', 'o'], 'f'), true) &&
+std.assertEqual(std.member(['f', 'o', 'o'], 'g'), false) &&
+
+std.assertEqual(std.count([true, false, false, true, true, true, false], true), 4) &&
+std.assertEqual(std.count([true, false, false, true, true, true, false], false), 3) &&
+
+std.assertEqual(std.filter(function(x) x % 2 == 0, [1, 2, 3, 4]), [2, 4]) &&
+std.assertEqual(std.filter(function(x) false, [1, 2, 3, 4]), []) &&
+std.assertEqual(std.filter(function(x) x, []), []) &&
+
+std.assertEqual(std.objectHas({ x: 1, y: 2 }, 'x'), true) &&
+std.assertEqual(std.objectHas({ x: 1, y: 2 }, 'z'), false) &&
+std.assertEqual(std.objectHas({}, 'z'), false) &&
+
+std.assertEqual(std.length('asdfasdf'), 8) &&
+std.assertEqual(std.length([1, 4, 9, error 'foo']), 4) &&
+std.assertEqual(std.length(function(x, y, z) error 'foo'), 3) &&
+std.assertEqual(std.length({ x: 1, y: 2 }), 2) &&
+std.assertEqual(std.length({ a: 1, b: 2, c: 0 } + { c: 3, d: error 'foo' }), 4) &&
+std.assertEqual(std.length(''), 0) &&
+std.assertEqual(std.length([]), 0) &&
+std.assertEqual(std.length(function() error 'foo'), 0) &&
+std.assertEqual(std.length({}), 0) &&
+
+std.assertEqual(std.objectFields({}), []) &&
+std.assertEqual(std.objectFields({ x: 1, y: 2 }), ['x', 'y']) &&
+std.assertEqual(std.objectFields({ a: 1, b: 2, c: null, d: error 'foo' }), ['a', 'b', 'c', 'd']) &&
+std.assertEqual(std.objectFields({ x: 1 } { x: 1 }), ['x']) &&
+std.assertEqual(std.objectFields({ x: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectFields({ x: 1 } { x::: 1 }), ['x']) &&
+std.assertEqual(std.objectFields({ x:: 1 } { x: 1 }), []) &&
+std.assertEqual(std.objectFields({ x:: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectFields({ x:: 1 } { x::: 1 }), ['x']) &&
+std.assertEqual(std.objectFields({ x::: 1 } { x: 1 }), ['x']) &&
+std.assertEqual(std.objectFields({ x::: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectFields({ x::: 1 } { x::: 1 }), ['x']) &&
+
+std.assertEqual(std.objectValues({}), []) &&
+std.assertEqual(std.objectValues({ x: 1, y: 2 }), [1, 2]) &&
+std.assertEqual(std.objectValues({ x: 1 } { x: 1 }), [1]) &&
+std.assertEqual(std.objectValues({ x: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectValues({ x: 1 } { x::: 1 }), [1]) &&
+std.assertEqual(std.objectValues({ x:: 1 } { x: 1 }), []) &&
+std.assertEqual(std.objectValues({ x:: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectValues({ x:: 1 } { x::: 1 }), [1]) &&
+std.assertEqual(std.objectValues({ x::: 1 } { x: 1 }), [1]) &&
+std.assertEqual(std.objectValues({ x::: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectValues({ x::: 1 } { x::: 1 }), [1]) &&
+
+std.assertEqual(std.objectKeysValues({}), []) &&
+std.assertEqual(std.objectKeysValues({ x: 1, y: 2 }), [{ key: 'x', value: 1 }, { key: 'y', value: 2 }]) &&
+std.assertEqual(std.objectKeysValues({ x: 1 } { x: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x: 1 } { x::: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x:: 1 } { x: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x:: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x:: 1 } { x::: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x::: 1 } { x: 1 }), [{ key: 'x', value: 1 }]) &&
+std.assertEqual(std.objectKeysValues({ x::: 1 } { x:: 1 }), []) &&
+std.assertEqual(std.objectKeysValues({ x::: 1 } { x::: 1 }), [{ key: 'x', value: 1 }]) &&
+
+std.assertEqual(std.get({ x: 1, y: 2 }, 'x', 5), 1) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'z', 5), 5) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'z'), null) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'x', 5), 1) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'z', 5), 5) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'z'), null) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'x', 5), 1) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'x'), 1) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'z', 5), 5) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'z'), null) &&
+std.assertEqual(std.get({}, 'z', 5), 5) &&
+std.assertEqual(std.get({}, 'z'), null) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'x', 5, false), 1) &&
+std.assertEqual(std.get({ x: 1, y: 2 }, 'z', 5, false), 5) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'x', 5, false), 1) &&
+std.assertEqual(std.get({ x::: 1, y::: 2 }, 'z', 5, false), 5) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'x', 5, false), 5) &&
+std.assertEqual(std.get({ x:: 1, y:: 2 }, 'z', 5, false), 5) &&
+std.assertEqual(std.get({}, 'z', 5, false), 5) &&
+
+std.assertEqual(std.toString({ a: 1, b: 2 }), '{"a": 1, "b": 2}') &&
+std.assertEqual(std.toString({}), '{ }') &&
+std.assertEqual(std.toString([1, 2]), '[1, 2]') &&
+std.assertEqual(std.toString([]), '[ ]') &&
+std.assertEqual(std.toString(null), 'null') &&
+std.assertEqual(std.toString(true), 'true') &&
+std.assertEqual(std.toString(false), 'false') &&
+std.assertEqual(std.toString('str'), 'str') &&
+std.assertEqual(std.toString(''), '') &&
+std.assertEqual(std.toString([1, 2, 'foo']), '[1, 2, "foo"]') &&
+
+std.assertEqual(std.substr('cookie', 1, 3), 'ook') &&
+std.assertEqual(std.substr('cookie', 1, 0), '') &&
+std.assertEqual(std.substr('cookie', 1, 15), 'ookie') &&
+std.assertEqual(std.substr('cookie', 0, 5), 'cooki') &&
+std.assertEqual(std.substr('cookie', 0, 6), 'cookie') &&
+std.assertEqual(std.substr('cookie', 0, 15), 'cookie') &&
+std.assertEqual(std.substr('cookie', 3, 1), 'k') &&
+std.assertEqual(std.substr('cookie', 20, 1), '') &&
+std.assertEqual(std.substr('cookie', 6, 1), '') &&
+
+
+std.assertEqual(std.substr('ąę', 1, 1), 'ę') &&
+
+std.assertEqual(std.startsWith('food', 'foo'), true) &&
+std.assertEqual(std.startsWith('food', 'food'), true) &&
+std.assertEqual(std.startsWith('food', 'foody'), false) &&
+std.assertEqual(std.startsWith('food', 'wat'), false) &&
+
+std.assertEqual(std.endsWith('food', 'ood'), true) &&
+std.assertEqual(std.endsWith('food', 'food'), true) &&
+std.assertEqual(std.endsWith('food', 'omgfood'), false) &&
+std.assertEqual(std.endsWith('food', 'wat'), false) &&
+
+//std.assertEqual(std.stripChars(' test test test ', ' '), 'test test test') &&
+//std.assertEqual(std.stripChars('aaabbbbcccc', 'ac'), 'bbbb') &&
+//std.assertEqual(std.stripChars('cacabbbbaacc', 'ac'), 'bbbb') &&
+//std.assertEqual(std.stripChars('', 'ac'), '') &&
+
+//std.assertEqual(std.lstripChars(' test test test ', ' '), 'test test test ') &&
+//std.assertEqual(std.lstripChars('aaabbbbcccc', 'ac'), 'bbbbcccc') &&
+//std.assertEqual(std.lstripChars('cacabbbbaacc', 'ac'), 'bbbbaacc') &&
+//std.assertEqual(std.lstripChars('', 'ac'), '') &&
+
+//std.assertEqual(std.rstripChars(' test test test ', ' '), ' test test test') &&
+//std.assertEqual(std.rstripChars('aaabbbbcccc', 'ac'), 'aaabbbb') &&
+//std.assertEqual(std.rstripChars('cacabbbbaacc', 'ac'), 'cacabbbb') &&
+//std.assertEqual(std.rstripChars('', 'ac'), '') &&
+
+std.assertEqual(std.codepoint('a'), 97) &&
+std.assertEqual(std.char(97), 'a') &&
+std.assertEqual(std.codepoint('\u0000'), 0) &&
+std.assertEqual(std.char(0), '\u0000') &&
+
+std.assertEqual(std.strReplace('A cat walked by', 'cat', 'dog'), 'A dog walked by') &&
+std.assertEqual(std.strReplace('cat', 'cat', 'dog'), 'dog') &&
+std.assertEqual(std.strReplace('', 'cat', ''), '') &&
+std.assertEqual(std.strReplace('xoxoxoxox', 'xoxox3xox', 'A'), 'xoxoxoxox') &&
+std.assertEqual(std.strReplace('xoxoxox3xox', 'xoxox3xox', 'A'), 'xoA') &&
+std.assertEqual(std.strReplace('A cat is a cat', 'cat', 'dog'), 'A dog is a dog') &&
+std.assertEqual(std.strReplace('wishyfishyisishy', 'ish', 'and'), 'wandyfandyisandy') &&
+
+std.assertEqual(std.map(function(x) x * x, []), []) &&
+std.assertEqual(std.map(function(x) x * x, [1, 2, 3, 4]), [1, 4, 9, 16]) &&
+std.assertEqual(std.map(function(x) x * x, std.filter(function(x) x > 5, std.range(1, 10))), [36, 49, 64, 81, 100]) &&
+
+std.assertEqual(std.mapWithIndex(function(i, x) x * i, []), []) &&
+std.assertEqual(std.mapWithIndex(function(i, x) x * i, [1, 2, 3, 4]), [0, 2, 6, 12]) &&
+std.assertEqual(std.mapWithIndex(function(i, x) x * i, std.filter(function(x) x > 5, std.range(1, 10))), [0, 7, 16, 27, 40]) &&
+
+std.assertEqual(std.mapWithKey(function(k, o) k + o, {}), {}) &&
+std.assertEqual(std.mapWithKey(function(k, o) k + o, { a: 1, b: 2 }), { a: 'a1', b: 'b2' }) &&
+
+std.assertEqual(std.flatMap(function(x) [x, x], [1, 2, 3]), [1, 1, 2, 2, 3, 3]) &&
+std.assertEqual(std.flatMap(function(x) if x == 2 then [] else [x], [1, 2, 3]), [1, 3]) &&
+std.assertEqual(std.flatMap(function(x) if x == 2 then [] else [x * 3, x * 2], [1, 2, 3]), [3, 2, 9, 6]) &&
+
+std.assertEqual(std.filterMap(function(x) x >= 0, function(x) x * x, [-3, -2, -1, 0, 1, 2, 3]), [0, 1, 4, 9]) &&
+
+std.assertEqual(std.foldl(function(x, y) [x, y], [], 'foo'), 'foo') &&
+std.assertEqual(std.foldl(function(x, y) [x, y], [1, 2, 3, 4], []), [[[[[], 1], 2], 3], 4]) &&
+
+std.assertEqual(std.foldr(function(x, y) [x, y], [], 'bar'), 'bar') &&
+std.assertEqual(std.foldr(function(x, y) [x, y], [1, 2, 3, 4], []), [1, [2, [3, [4, []]]]]) &&
+
+std.assertEqual(std.range(2, 6), [2, 3, 4, 5, 6]) &&
+std.assertEqual(std.range(2, 2), [2]) &&
+std.assertEqual(std.range(2, 1), []) &&
+
+std.assertEqual(std.repeat([], 0), []) &&
+std.assertEqual(std.repeat([1], 1), [1]) &&
+std.assertEqual(std.repeat([1, 2], 1), [1, 2]) &&
+std.assertEqual(std.repeat([1], 2), [1, 1]) &&
+std.assertEqual(std.repeat([1, 2], 2), [1, 2, 1, 2]) &&
+std.assertEqual(std.repeat('a', 1), 'a') &&
+std.assertEqual(std.repeat('a', 4), 'aaaa') &&
+std.assertEqual(std.repeat('ab', 4), 'abababab') &&
+std.assertEqual(std.repeat('a', 0), '') &&
+
+std.assertEqual(std.join([], [[1, 2], [3, 4, 5], [6]]), [1, 2, 3, 4, 5, 6]) &&
+std.assertEqual(std.join(['a', 'b'], [[]]), []) &&
+std.assertEqual(std.join(['a', 'b'], []), []) &&
+std.assertEqual(std.join(['a', 'b'], [null, [1, 2], null, [3, 4, 5], [6], null]), [1, 2, 'a', 'b', 3, 4, 5, 'a', 'b', 6]) &&
+std.assertEqual(std.join(['a', 'b'], [[], [1, 2]]), ['a', 'b', 1, 2]) &&
+std.assertEqual(std.join('', [null, '12', null, '345', '6', null]), '123456') &&
+std.assertEqual(std.join('ab', ['']), '') &&
+std.assertEqual(std.join('ab', []), '') &&
+std.assertEqual(std.join('ab', [null, '12', null, '345', '6', null]), '12ab345ab6') &&
+std.assertEqual(std.join('ab', ['', '12']), 'ab12') &&
+std.assertEqual(std.lines(['a', null, 'b']), 'a\nb\n') &&
+
+std.assertEqual(std.flattenArrays([[1, 2, 3], [4, 5, 6], []]), [1, 2, 3, 4, 5, 6]) &&
+
+//std.assertEqual(std.flattenDeepArray([]), []) &&
+//std.assertEqual(std.flattenDeepArray([1, 2, 3]), [1, 2, 3]) &&
+//std.assertEqual(std.flattenDeepArray([1, [2, 3]]), [1, 2, 3]) &&
+//std.assertEqual(std.flattenDeepArray([[1], [2, 3], [[null]]]), [1, 2, 3, null]) &&
+
+std.assertEqual(
+ std.manifestIni({
+ main: { a: '1', b: '2' },
+ sections: {
+ s1: { x: '11', y: '22', z: '33' },
+ s2: { p: 'yes', q: '' },
+ empty: {},
+ },
+ }),
+ 'a = 1\nb = 2\n[empty]\n[s1]\nx = 11\ny = 22\nz = 33\n[s2]\np = yes\nq = \n'
+) &&
+
+std.assertEqual(
+ std.manifestIni({
+ sections: {
+ s1: { x: '11', y: '22', z: '33' },
+ s2: { p: 'yes', q: '' },
+ empty: {},
+ },
+ }),
+ '[empty]\n[s1]\nx = 11\ny = 22\nz = 33\n[s2]\np = yes\nq = \n'
+) &&
+
+std.assertEqual(
+ std.manifestIni({
+ main: { a: ['1', '2'] },
+ sections: {
+ s2: { p: ['yes', ''] },
+ },
+ }), 'a = 1\na = 2\n[s2]\np = yes\np = \n'
+) &&
+
+
+std.assertEqual(std.escapeStringJson('hello'), '"hello"') &&
+std.assertEqual(std.escapeStringJson('he"llo'), '"he\\"llo"') &&
+std.assertEqual(std.escapeStringJson('he"llo'), '"he\\"llo"') &&
+std.assertEqual(std.escapeStringBash("he\"l'lo"), "'he\"l'\"'\"'lo'") &&
+std.assertEqual(std.escapeStringDollars('The path is ${PATH}.'), 'The path is $${PATH}.') &&
+//std.assertEqual(std.escapeStringXML('2 < 3'), '2 < 3') &&
+//std.assertEqual(std.escapeStringXML('3 > 2'), '3 > 2') &&
+//std.assertEqual(std.escapeStringXML('"foo"'), '"foo"') &&
+//std.assertEqual(std.escapeStringXML("don't believe the hype"), 'don't believe the hype') &&
+//std.assertEqual(std.escapeStringXML('PB&J'), 'PB&J') &&
+std.assertEqual(std.escapeStringJson('!~'), '"!~"') &&
+
+std.assertEqual(std.manifestPython({
+ x: 'test',
+ y: [],
+ z: ['foo', 'bar'],
+ n: 1,
+ a: true,
+ b: false,
+ c: null,
+ o: { f1: 'foo', f2: 'bar' },
+}), '{%s}' % std.join(', ', [
+ '"a": True',
+ '"b": False',
+ '"c": None',
+ '"n": 1',
+ '"o": {"f1": "foo", "f2": "bar"}',
+ '"x": "test"',
+ '"y": []',
+ '"z": ["foo", "bar"]',
+])) &&
+
+std.assertEqual(std.manifestPythonVars({
+ x: 'test',
+ y: [],
+ z: ['foo', 'bar'],
+ n: 1,
+ a: true,
+ b: false,
+ c: null,
+ o: { f1: 'foo', f2: 'bar' },
+}), std.join('\n', [
+ 'a = True',
+ 'b = False',
+ 'c = None',
+ 'n = 1',
+ 'o = {"f1": "foo", "f2": "bar"}',
+ 'x = "test"',
+ 'y = []',
+ 'z = ["foo", "bar"]',
+ '',
+])) &&
+
+std.assertEqual(
+ std.manifestXmlJsonml(
+ ['f', {}, ' ', ['g', 'inside'], 'nope', ['h', { attr: 'yolo' }, ['x', { attr: 'otter' }]]]
+ ),
+ ' insidenope'
+) &&
+
+
+std.assertEqual(std.base64('Hello World!'), 'SGVsbG8gV29ybGQh') &&
+std.assertEqual(std.base64('Hello World'), 'SGVsbG8gV29ybGQ=') &&
+std.assertEqual(std.base64('Hello Worl'), 'SGVsbG8gV29ybA==') &&
+std.assertEqual(std.base64(''), '') &&
+
+std.assertEqual(std.base64Decode('SGVsbG8gV29ybGQh'), 'Hello World!') &&
+std.assertEqual(std.base64Decode('SGVsbG8gV29ybGQ='), 'Hello World') &&
+std.assertEqual(std.base64Decode('SGVsbG8gV29ybA=='), 'Hello Worl') &&
+std.assertEqual(std.base64Decode(''), '') &&
+
+std.assertEqual(std.reverse([]), []) &&
+std.assertEqual(std.reverse([1]), [1]) &&
+std.assertEqual(std.reverse([1, 2]), [2, 1]) &&
+std.assertEqual(std.reverse([1, 2, 3]), [3, 2, 1]) &&
+std.assertEqual(std.reverse([[1, 2, 3]]), [[1, 2, 3]]) &&
+
+std.assertEqual(std.sort([]), []) &&
+std.assertEqual(std.sort([1]), [1]) &&
+std.assertEqual(std.sort([1, 2]), [1, 2]) &&
+std.assertEqual(std.sort([2, 1]), [1, 2]) &&
+std.assertEqual(std.sort(['1', '2']), ['1', '2']) &&
+std.assertEqual(std.sort(['2', '1']), ['1', '2']) &&
+std.assertEqual(
+ std.sort(['The', 'rain', 'in', 'spain', 'falls', 'mainly', 'on', 'the', 'plain.']),
+ ['The', 'falls', 'in', 'mainly', 'on', 'plain.', 'rain', 'spain', 'the']
+) &&
+
+std.assertEqual(std.uniq([]), []) &&
+std.assertEqual(std.uniq([1]), [1]) &&
+std.assertEqual(std.uniq([1, 2]), [1, 2]) &&
+std.assertEqual(std.uniq(['1', '2']), ['1', '2']) &&
+std.assertEqual(
+ std.uniq(['The', 'falls', 'in', 'mainly', 'on', 'plain.', 'rain', 'spain', 'the']),
+ ['The', 'falls', 'in', 'mainly', 'on', 'plain.', 'rain', 'spain', 'the']
+) &&
+
+local animal_set = ['ant', 'bat', 'cat', 'dog', 'elephant', 'fish', 'giraffe'];
+
+std.assertEqual(
+ std.uniq(['ant', 'bat', 'cat', 'dog', 'dog', 'elephant', 'fish', 'fish', 'giraffe']),
+ animal_set
+) &&
+
+std.assertEqual(
+ std.set(['dog', 'ant', 'bat', 'cat', 'dog', 'elephant', 'fish', 'giraffe', 'fish']),
+ animal_set
+) &&
+
+std.assertEqual(std.setUnion(animal_set, animal_set), animal_set) &&
+std.assertEqual(std.setUnion(animal_set, []), animal_set) &&
+std.assertEqual(std.setUnion([], animal_set), animal_set) &&
+std.assertEqual(std.setUnion([], []), []) &&
+std.assertEqual(std.setUnion(['a', 'b'], ['b', 'c']), ['a', 'b', 'c']) &&
+
+std.assertEqual(std.setInter(animal_set, animal_set), animal_set) &&
+std.assertEqual(std.setInter(animal_set, []), []) &&
+std.assertEqual(std.setInter([], animal_set), []) &&
+std.assertEqual(std.setInter([], []), []) &&
+std.assertEqual(std.setInter(['a', 'b'], ['b', 'c']), ['b']) &&
+
+std.assertEqual(std.setDiff(animal_set, animal_set), []) &&
+std.assertEqual(std.setDiff(animal_set, []), animal_set) &&
+std.assertEqual(std.setDiff([], animal_set), []) &&
+std.assertEqual(std.setDiff([], []), []) &&
+std.assertEqual(std.setDiff(['a', 'b'], ['b', 'c']), ['a']) &&
+
+std.assertEqual(std.setMember('a', ['a', 'b', 'c']), true) &&
+std.assertEqual(std.setMember('a', []), false) &&
+std.assertEqual(std.setMember('a', ['b', 'c']), false) &&
+
+(
+ if std.thisFile == '' then
+ // This happens when testing the unparser.
+ true
+ else
+ std.assertEqual(std.thisFile, 'stdlib_native.jsonnet')
+) &&
+
+std.assertEqual(import 'this_file/a.libsonnet', 'this_file/a.libsonnet') &&
+std.assertEqual(import 'this_file/b.libsonnet', 'this_file/a.libsonnet') &&
+
+
+std.assertEqual(std.extVar('var1'), 'test') &&
+
+std.assertEqual(std.toString(std.extVar('var2')), '{"x": 1, "y": 2}') &&
+std.assertEqual(std.extVar('var2'), { x: 1, y: 2 }) &&
+std.assertEqual(std.extVar('var2') { x+: 2 }.x, 3) &&
+
+std.assertEqual(std.split('foo/bar', '/'), ['foo', 'bar']) &&
+std.assertEqual(std.split('/foo/', '/'), ['', 'foo', '']) &&
+std.assertEqual(std.split('foo/_bar', '/_'), ['foo', 'bar']) &&
+std.assertEqual(std.split('/_foo/_', '/_'), ['', 'foo', '']) &&
+
+std.assertEqual(std.splitLimit('foo/bar', '/', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimit('/foo/', '/', 1), ['', 'foo/']) &&
+std.assertEqual(std.splitLimit('foo/_bar', '/_', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimit('/_foo/_', '/_', 1), ['', 'foo/_']) &&
+
+std.assertEqual(std.splitLimitR('foo/bar', '/', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimitR('/foo/', '/', 1), ['/foo', '']) &&
+std.assertEqual(std.splitLimitR('/foo/', '/', -1), ['', 'foo', '']) &&
+std.assertEqual(std.splitLimitR('foo/_bar', '/_', 1), ['foo', 'bar']) &&
+std.assertEqual(std.splitLimitR('/_foo/_', '/_', 1), ['/_foo', '']) &&
+std.assertEqual(std.splitLimitR('/_foo/_', '/_', -1), ['', 'foo', '']) &&
+
+//local some_toml = {
+// key: 'value',
+// simple: { t: 5 },
+// section: {
+// a: 1,
+// nested: { b: 2 },
+// 'e$caped': { q: 't' },
+// array: [
+// { c: 3 },
+// { d: 4 },
+// ],
+// nestedArray: [{
+// k: 'v',
+// nested: { e: 5 },
+// }],
+// },
+// arraySection: [
+// { q: 1 },
+// { w: 2 },
+// ],
+// 'escaped"Section': { z: 'q' },
+// emptySection: {},
+// emptyArraySection: [{}],
+// bool: true,
+// notBool: false,
+// number: 7,
+// array: ['s', 1, [2, 3], { r: 6, a: ['0', 'z'] }],
+// emptyArray: [],
+// '"': 4,
+//};
+//
+//std.assertEqual(
+// std.manifestTomlEx(some_toml, ' ') + '\n',
+// |||
+// "\"" = 4
+// array = [
+// "s",
+// 1,
+// [ 2, 3 ],
+// { a = [ "0", "z" ], r = 6 }
+// ]
+// bool = true
+// emptyArray = []
+// key = "value"
+// notBool = false
+// number = 7
+//
+// [[arraySection]]
+// q = 1
+//
+// [[arraySection]]
+// w = 2
+//
+// [[emptyArraySection]]
+//
+// [emptySection]
+//
+// ["escaped\"Section"]
+// z = "q"
+//
+// [section]
+// a = 1
+//
+// [[section.array]]
+// c = 3
+//
+// [[section.array]]
+// d = 4
+//
+// [section."e$caped"]
+// q = "t"
+//
+// [section.nested]
+// b = 2
+//
+// [[section.nestedArray]]
+// k = "v"
+//
+// [section.nestedArray.nested]
+// e = 5
+//
+// [simple]
+// t = 5
+// |||
+//) &&
+
+local some_json = {
+ x: [1, 2, 3, true, false, null, 'string\nstring\n'],
+ arr: [[[]]],
+ y: { a: 1, b: 2, c: [1, 2] },
+ emptyArray: [],
+ emptyObject: {},
+ objectInArray: [{ f: 3 }],
+ '"': null,
+};
+
+local bare_yaml_quoted = {
+ '685230': 'canonical',
+ '+685_230': 'decimal',
+ '02472256': 'octal',
+ '-1_0': 'negative integer',
+ '-0.1_0_0': 'negative float',
+ '0x_0A_74_AE': 'hexadecimal',
+ '-0x_0A_74_AE': 'negative hexadecimal',
+ '0b1010_0111_0100_1010_1110': 'binary',
+ '-0b1010_0111_0100_1010_1110': 'binary',
+ '190:20:30': 'sexagesimal',
+ '-190:20:30': 'negative sexagesimal',
+ '6.8523015e+5': 'canonical',
+ '6.8523015e-5': 'canonical',
+ '-6.8523015e+5': 'negative canonical',
+ '685.230_15e+03': 'exponential',
+ '-685.230_15e+03': 'negative exponential',
+ '-685.230_15e-03': 'negative w/ negative exponential',
+ '-685.230_15E-03': 'negative w/ negative exponential',
+ '685_230.15': 'fixed',
+ '-685_230.15': 'negative fixed',
+ '190:20:30.15': 'sexagesimal',
+ '-190:20:30.15': 'negative sexagesimal',
+ '-.inf': 'negative infinity',
+ '.inf': 'positive infinity',
+ '+.inf': 'positive infinity',
+ '.NaN': 'not a number',
+ y: 'boolean true',
+ yes: 'boolean true',
+ Yes: 'boolean true',
+ True: 'boolean true',
+ 'true': 'boolean true',
+ on: 'boolean true',
+ On: 'boolean true',
+ NO: 'boolean false',
+ n: 'boolean false',
+ N: 'boolean false',
+ off: 'boolean false',
+ OFF: 'boolean false',
+ 'null': 'null word',
+ NULL: 'null word capital',
+ Null: 'null word',
+ '~': 'null key',
+ '': 'empty key',
+ '-': 'invalid bare key',
+ '---': 'triple dash key',
+ '2001-12-15T02:59:43.1Z': 'canonical',
+ '2001-12-14t21:59:43.10-05:00': 'valid iso8601',
+ '2001-12-14 21:59:43.10 -5': 'space separated',
+ '2001-12-15 2:59:43.10': 'no time zone (Z)',
+ '2002-12-14': 'date',
+};
+local bare_yaml_unquoted = {
+ '0X_0a_74_ae': 'BARE_KEY',
+ '__-0X_0a_74_ae': 'BARE_KEY',
+ '-0B1010_0111_0100_1010_1110': 'BARE_KEY',
+ '__-0B1010_0111_0100_1010_1110': 'BARE_KEY',
+ x: 'BARE_KEY',
+ b: 'BARE_KEY',
+ just_letters_underscores: 'BARE_KEY',
+ 'just-letters-dashes': 'BARE_KEY',
+ 'jsonnet.org/k8s-label-like': 'BARE_KEY',
+ '192.168.0.1': 'BARE_KEY',
+ '1-234-567-8901': 'BARE_KEY',
+};
+local bare_yaml_test = bare_yaml_quoted + bare_yaml_unquoted;
+
+std.assertEqual(
+ std.manifestJsonEx(some_json, ' ') + '\n',
+ |||
+ {
+ "\"": null,
+ "arr": [
+ [
+ [
+
+ ]
+ ]
+ ],
+ "emptyArray": [
+
+ ],
+ "emptyObject": {
+
+ },
+ "objectInArray": [
+ {
+ "f": 3
+ }
+ ],
+ "x": [
+ 1,
+ 2,
+ 3,
+ true,
+ false,
+ null,
+ "string\nstring\n"
+ ],
+ "y": {
+ "a": 1,
+ "b": 2,
+ "c": [
+ 1,
+ 2
+ ]
+ }
+ }
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestJsonEx(some_json, '', ' ', ' : '),
+// '{ "\\"" : null, "arr" : [ [ [ ] ] ], "emptyArray" : [ ], '
+// + '"emptyObject" : { }, "objectInArray" : [ { "f" : 3 } ], '
+// + '"x" : [ 1, 2, 3, true, false, null, "string\\nstring\\n" ], '
+// + '"y" : { "a" : 1, "b" : 2, "c" : [ 1, 2 ] } }'
+//) &&
+
+std.assertEqual(
+ std.manifestJsonMinified(some_json),
+ '{"\\"":null,"arr":[[[]]],"emptyArray":[],"emptyObject":{},"objectInArray":[{"f":3}],'
+ + '"x":[1,2,3,true,false,null,"string\\nstring\\n"],"y":{"a":1,"b":2,"c":[1,2]}}'
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc([{ x: [1, 2, 3] }], quote_keys=false) + '\n',
+// |||
+// - x:
+// - 1
+// - 2
+// - 3
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlDoc([{ x: [1, 2, 3] }]) + '\n',
+ |||
+ - "x":
+ - 1
+ - 2
+ - 3
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ x: [1, 2, 3] }) + '\n',
+ |||
+ "x":
+ - 1
+ - 2
+ - 3
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc([[[1, 2], [3, 4]]]) + '\n',
+ |||
+ -
+ -
+ - 1
+ - 2
+ -
+ - 3
+ - 4
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ x: [[[1, [1], 1]]] }) + '\n',
+ |||
+ "x":
+ -
+ -
+ - 1
+ -
+ - 1
+ - 1
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ x: [[[1, { f: 3, g: [1, 2] }, 1]]] }) + '\n',
+ |||
+ "x":
+ -
+ -
+ - 1
+ - "f": 3
+ "g":
+ - 1
+ - 2
+ - 1
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc({ x: [[[1, { f: 3, g: [1, 2] }, 1]]] }, quote_keys=false) + '\n',
+// |||
+// x:
+// -
+// -
+// - 1
+// - f: 3
+// g:
+// - 1
+// - 2
+// - 1
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlDoc('hello\nworld\n') + '\n',
+ |||
+ |
+ hello
+ world
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc(['hello\nworld\n']) + '\n',
+ |||
+ - |
+ hello
+ world
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ f: 'hello\nworld\n' }) + '\n',
+ |||
+ "f": |
+ hello
+ world
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc({ f: 'hello\nworld\n' }, quote_keys=false) + '\n',
+// |||
+// f: |
+// hello
+// world
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlDoc(some_json) + '\n',
+ |||
+ "\"": null
+ "arr":
+ -
+ - []
+ "emptyArray": []
+ "emptyObject": {}
+ "objectInArray":
+ - "f": 3
+ "x":
+ - 1
+ - 2
+ - 3
+ - true
+ - false
+ - null
+ - |
+ string
+ string
+ "y":
+ "a": 1
+ "b": 2
+ "c":
+ - 1
+ - 2
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc(some_json, quote_keys=false) + '\n',
+// |||
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlDoc([{ x: [1, 2, 3] }], indent_array_in_object=true) + '\n',
+ |||
+ - "x":
+ - 1
+ - 2
+ - 3
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc([{ x: [1, 2, 3] }], indent_array_in_object=true, quote_keys=false) + '\n',
+// |||
+// - x:
+// - 1
+// - 2
+// - 3
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ x: [1, 2, 3] }, indent_array_in_object=true) + '\n',
+ |||
+ "x":
+ - 1
+ - 2
+ - 3
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc([[[1, 2], [3, 4]]], indent_array_in_object=true) + '\n',
+ |||
+ -
+ -
+ - 1
+ - 2
+ -
+ - 3
+ - 4
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ x: [[[1, [1], 1]]] }, indent_array_in_object=true) + '\n',
+ |||
+ "x":
+ -
+ -
+ - 1
+ -
+ - 1
+ - 1
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ x: [[[1, { f: 3, g: [1, 2] }, 1]]] }, indent_array_in_object=true) + '\n',
+ |||
+ "x":
+ -
+ -
+ - 1
+ - "f": 3
+ "g":
+ - 1
+ - 2
+ - 1
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc('hello\nworld\n', indent_array_in_object=true) + '\n',
+ |||
+ |
+ hello
+ world
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc(['hello\nworld\n'], indent_array_in_object=true) + '\n',
+ |||
+ - |
+ hello
+ world
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc({ f: 'hello\nworld\n' }, indent_array_in_object=true) + '\n',
+ |||
+ "f": |
+ hello
+ world
+ |||
+) &&
+
+std.assertEqual(
+ std.manifestYamlDoc(some_json, indent_array_in_object=true) + '\n',
+ |||
+ "\"": null
+ "arr":
+ -
+ - []
+ "emptyArray": []
+ "emptyObject": {}
+ "objectInArray":
+ - "f": 3
+ "x":
+ - 1
+ - 2
+ - 3
+ - true
+ - false
+ - null
+ - |
+ string
+ string
+ "y":
+ "a": 1
+ "b": 2
+ "c":
+ - 1
+ - 2
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc(some_json, indent_array_in_object=true, quote_keys=false) + '\n',
+// |||
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// |||
+//) &&
+
+//std.assertEqual(
+// std.manifestYamlDoc(bare_yaml_test, quote_keys=false) + '\n',
+// |||
+// "": "empty key"
+// "+.inf": "positive infinity"
+// "+685_230": "decimal"
+// "-": "invalid bare key"
+// "---": "triple dash key"
+// "-.inf": "negative infinity"
+// "-0.1_0_0": "negative float"
+// -0B1010_0111_0100_1010_1110: "BARE_KEY"
+// "-0b1010_0111_0100_1010_1110": "binary"
+// "-0x_0A_74_AE": "negative hexadecimal"
+// "-190:20:30": "negative sexagesimal"
+// "-190:20:30.15": "negative sexagesimal"
+// "-1_0": "negative integer"
+// "-6.8523015e+5": "negative canonical"
+// "-685.230_15E-03": "negative w/ negative exponential"
+// "-685.230_15e+03": "negative exponential"
+// "-685.230_15e-03": "negative w/ negative exponential"
+// "-685_230.15": "negative fixed"
+// ".NaN": "not a number"
+// ".inf": "positive infinity"
+// "02472256": "octal"
+// 0X_0a_74_ae: "BARE_KEY"
+// "0b1010_0111_0100_1010_1110": "binary"
+// "0x_0A_74_AE": "hexadecimal"
+// 1-234-567-8901: "BARE_KEY"
+// "190:20:30": "sexagesimal"
+// "190:20:30.15": "sexagesimal"
+// 192.168.0.1: "BARE_KEY"
+// "2001-12-14 21:59:43.10 -5": "space separated"
+// "2001-12-14t21:59:43.10-05:00": "valid iso8601"
+// "2001-12-15 2:59:43.10": "no time zone (Z)"
+// "2001-12-15T02:59:43.1Z": "canonical"
+// "2002-12-14": "date"
+// "6.8523015e+5": "canonical"
+// "6.8523015e-5": "canonical"
+// "685.230_15e+03": "exponential"
+// "685230": "canonical"
+// "685_230.15": "fixed"
+// "N": "boolean false"
+// "NO": "boolean false"
+// "NULL": "null word capital"
+// "Null": "null word"
+// "OFF": "boolean false"
+// "On": "boolean true"
+// "True": "boolean true"
+// "Yes": "boolean true"
+// __-0B1010_0111_0100_1010_1110: "BARE_KEY"
+// __-0X_0a_74_ae: "BARE_KEY"
+// b: "BARE_KEY"
+// jsonnet.org/k8s-label-like: "BARE_KEY"
+// just-letters-dashes: "BARE_KEY"
+// just_letters_underscores: "BARE_KEY"
+// "n": "boolean false"
+// "null": "null word"
+// "off": "boolean false"
+// "on": "boolean true"
+// "true": "boolean true"
+// x: "BARE_KEY"
+// "y": "boolean true"
+// "yes": "boolean true"
+// "~": "null key"
+// |||
+//) &&
+//
+//std.assertEqual(
+// std.manifestYamlStream([bare_yaml_quoted, bare_yaml_unquoted], quote_keys=false),
+// |||
+// ---
+// "": "empty key"
+// "+.inf": "positive infinity"
+// "+685_230": "decimal"
+// "-": "invalid bare key"
+// "---": "triple dash key"
+// "-.inf": "negative infinity"
+// "-0.1_0_0": "negative float"
+// "-0b1010_0111_0100_1010_1110": "binary"
+// "-0x_0A_74_AE": "negative hexadecimal"
+// "-190:20:30": "negative sexagesimal"
+// "-190:20:30.15": "negative sexagesimal"
+// "-1_0": "negative integer"
+// "-6.8523015e+5": "negative canonical"
+// "-685.230_15E-03": "negative w/ negative exponential"
+// "-685.230_15e+03": "negative exponential"
+// "-685.230_15e-03": "negative w/ negative exponential"
+// "-685_230.15": "negative fixed"
+// ".NaN": "not a number"
+// ".inf": "positive infinity"
+// "02472256": "octal"
+// "0b1010_0111_0100_1010_1110": "binary"
+// "0x_0A_74_AE": "hexadecimal"
+// "190:20:30": "sexagesimal"
+// "190:20:30.15": "sexagesimal"
+// "2001-12-14 21:59:43.10 -5": "space separated"
+// "2001-12-14t21:59:43.10-05:00": "valid iso8601"
+// "2001-12-15 2:59:43.10": "no time zone (Z)"
+// "2001-12-15T02:59:43.1Z": "canonical"
+// "2002-12-14": "date"
+// "6.8523015e+5": "canonical"
+// "6.8523015e-5": "canonical"
+// "685.230_15e+03": "exponential"
+// "685230": "canonical"
+// "685_230.15": "fixed"
+// "N": "boolean false"
+// "NO": "boolean false"
+// "NULL": "null word capital"
+// "Null": "null word"
+// "OFF": "boolean false"
+// "On": "boolean true"
+// "True": "boolean true"
+// "Yes": "boolean true"
+// "n": "boolean false"
+// "null": "null word"
+// "off": "boolean false"
+// "on": "boolean true"
+// "true": "boolean true"
+// "y": "boolean true"
+// "yes": "boolean true"
+// "~": "null key"
+// ---
+// -0B1010_0111_0100_1010_1110: "BARE_KEY"
+// 0X_0a_74_ae: "BARE_KEY"
+// 1-234-567-8901: "BARE_KEY"
+// 192.168.0.1: "BARE_KEY"
+// __-0B1010_0111_0100_1010_1110: "BARE_KEY"
+// __-0X_0a_74_ae: "BARE_KEY"
+// b: "BARE_KEY"
+// jsonnet.org/k8s-label-like: "BARE_KEY"
+// just-letters-dashes: "BARE_KEY"
+// just_letters_underscores: "BARE_KEY"
+// x: "BARE_KEY"
+// ...
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlStream([some_json, some_json, {}, [], 3, '"']),
+ |||
+ ---
+ "\"": null
+ "arr":
+ -
+ - []
+ "emptyArray": []
+ "emptyObject": {}
+ "objectInArray":
+ - "f": 3
+ "x":
+ - 1
+ - 2
+ - 3
+ - true
+ - false
+ - null
+ - |
+ string
+ string
+ "y":
+ "a": 1
+ "b": 2
+ "c":
+ - 1
+ - 2
+ ---
+ "\"": null
+ "arr":
+ -
+ - []
+ "emptyArray": []
+ "emptyObject": {}
+ "objectInArray":
+ - "f": 3
+ "x":
+ - 1
+ - 2
+ - 3
+ - true
+ - false
+ - null
+ - |
+ string
+ string
+ "y":
+ "a": 1
+ "b": 2
+ "c":
+ - 1
+ - 2
+ ---
+ {}
+ ---
+ []
+ ---
+ 3
+ ---
+ "\""
+ ...
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlStream([some_json, some_json, {}, [], 3, '"'], quote_keys=false),
+// |||
+// ---
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// ---
+// "\"": null
+// arr:
+// -
+// - []
+// emptyArray: []
+// emptyObject: {}
+// objectInArray:
+// - f: 3
+// x:
+// - 1
+// - 2
+// - 3
+// - true
+// - false
+// - null
+// - |
+// string
+// string
+// "y":
+// a: 1
+// b: 2
+// c:
+// - 1
+// - 2
+// ---
+// {}
+// ---
+// []
+// ---
+// 3
+// ---
+// "\""
+// ...
+// |||
+//) &&
+
+std.assertEqual(
+ std.manifestYamlStream([some_json, some_json, {}, [], 3, '"'], indent_array_in_object=true),
+ |||
+ ---
+ "\"": null
+ "arr":
+ -
+ - []
+ "emptyArray": []
+ "emptyObject": {}
+ "objectInArray":
+ - "f": 3
+ "x":
+ - 1
+ - 2
+ - 3
+ - true
+ - false
+ - null
+ - |
+ string
+ string
+ "y":
+ "a": 1
+ "b": 2
+ "c":
+ - 1
+ - 2
+ ---
+ "\"": null
+ "arr":
+ -
+ - []
+ "emptyArray": []
+ "emptyObject": {}
+ "objectInArray":
+ - "f": 3
+ "x":
+ - 1
+ - 2
+ - 3
+ - true
+ - false
+ - null
+ - |
+ string
+ string
+ "y":
+ "a": 1
+ "b": 2
+ "c":
+ - 1
+ - 2
+ ---
+ {}
+ ---
+ []
+ ---
+ 3
+ ---
+ "\""
+ ...
+ |||
+) &&
+
+//std.assertEqual(
+// std.manifestYamlStream([{}, [], 3, '"'], c_document_end=false),
+// |||
+// ---
+// {}
+// ---
+// []
+// ---
+// 3
+// ---
+// "\""
+// |||
+//) &&
+
+std.assertEqual(std.parseInt('01234567890'), 1234567890) &&
+std.assertEqual(std.parseInt('-01234567890'), -1234567890) &&
+std.assertEqual(std.parseOctal('755'), 493) &&
+std.assertEqual(std.parseOctal('0755'), 493) &&
+std.assertEqual(std.parseHex('ff'), 255) &&
+std.assertEqual(std.parseHex('FF'), 255) &&
+std.assertEqual(std.parseHex('0ff'), 255) &&
+std.assertEqual(std.parseHex('0FF'), 255) &&
+std.assertEqual(std.parseHex('a'), 10) &&
+std.assertEqual(std.parseHex('A'), 10) &&
+std.assertEqual(std.parseHex('4a'), 74) &&
+
+// verified by running md5 -s value
+//std.assertEqual(std.md5(''), 'd41d8cd98f00b204e9800998ecf8427e') &&
+//std.assertEqual(std.md5('grape'), 'b781cbb29054db12f88f08c6e161c199') &&
+//std.assertEqual(std.md5("{}[]01234567890\"'+=-_/<>?,.!@#$%^&*|\\:;`~"), 'a680db28332f0c9647376e5b2aeb4b3d') &&
+//std.assertEqual(std.md5('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum sit amet pede facilisis laoreet. Donec lacus nunc, viverra nec, blandit vel, egestas et, augue. Vestibulum tincidunt malesuada tellus. Ut ultrices ultrices enim. Curabitur sit amet mauris. Morbi in dui quis est pulvinar ullamcorper. Nulla facilisi. Integer lacinia sollicitudin massa. Cras metus. Sed aliquet risus a tortor. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante. Nulla quam. Aenean laoreet. Vestibulum nisi lectus, commodo ac, facilisis ac, ultricies eu, pede. Ut orci risus, accumsan porttitor, cursus quis, aliquet eget, justo. Sed pretium blandit orci. Ut eu diam at pede suscipit sodales. Aenean lectus elit, fermentum non, convallis id, sagittis at, neque. Nullam mauris orci, aliquet et, iaculis et, viverra vitae, ligula. Nulla ut felis in purus aliquam imperdiet. Maecenas aliquet mollis lectus. Vivamus consectetuer risus et tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Curabitur sodales ligula in libero. Sed dignissim lacinia nunc. Curabitur tortor. Pellentesque nibh. Aenean quam. In scelerisque sem at dolor. Maecenas mattis. Sed convallis tristique sem. Proin ut ligula vel nunc egestas porttitor. Morbi lectus risus, iaculis vel, suscipit quis, luctus non, massa. Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante. Sed lacinia, urna non tincidunt mattis, tortor neque adipiscing diam, a cursus ipsum ante quis turpis. Nulla facilisi. Ut fringilla. Suspendisse potenti. Nunc feugiat mi a tellus consequat imperdiet. Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Quisque cursus, metus vitae pharetra auctor, sem massa mattis sem, at interdum magna augue eget diam. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi lacinia molestie dui. Praesent blandit dolor. Sed non quam. In vel mi sit amet augue congue elementum. Morbi in ipsum si.'), '3496bb633e830e7679ce53700d42de1e') &&
+std.assertEqual(std.parseInt('-01234567890'), -1234567890) &&
+
+std.assertEqual(std.prune({}), {}) &&
+std.assertEqual(std.prune([]), []) &&
+std.assertEqual(std.prune(null), null) &&
+std.assertEqual(std.prune({ a: [], b: {}, c: null }), {}) &&
+std.assertEqual(std.prune([[], {}, null]), []) &&
+std.assertEqual(std.prune({ a: [[], {}, null], b: { a: [], b: {}, c: null } }), {}) &&
+std.assertEqual(std.prune([[[], {}, null], { a: [], b: {}, c: null }]), []) &&
+std.assertEqual(std.prune({ a: [{ b: true }] }), { a: [{ b: true }] }) &&
+
+std.assertEqual(std.parseJson('"foo"'), 'foo') &&
+std.assertEqual(std.parseJson('{}'), {}) &&
+std.assertEqual(std.parseJson('[]'), []) &&
+std.assertEqual(std.parseJson('null'), null) &&
+std.assertEqual(std.parseJson('12'), 12) &&
+std.assertEqual(std.parseJson('12.123'), 12.123) &&
+std.assertEqual(std.parseJson('{"a": {"b": ["c", 42]}}'), { a: { b: ['c', 42] } }) &&
+
+//std.assertEqual(std.parseYaml('{}'), {}) &&
+//std.assertEqual(std.parseYaml('[]'), []) &&
+//std.assertEqual(
+// std.parseYaml(
+// |||
+// foo:
+// bar:
+// - true
+// - 42
+// - 1.0
+// |||
+// ), { foo: { bar: [true, 42, 1] } }
+//) &&
+//std.assertEqual(
+// std.parseYaml(
+// |||
+// ---
+// foo:
+// bar:
+// - true
+// - 42
+// - 1.0
+// ---
+// wibble:
+// wobble:
+// - true
+// - 42
+// - 1.0
+// |||
+// ), [{ foo: { bar: [true, 42, 1] } }, { wibble: { wobble: [true, 42, 1] } }]
+//) &&
+//std.assertEqual(
+// std.parseYaml(
+// |||
+// - 1
+// - 2
+// - 3
+// |||
+// ), [1, 2, 3]
+//) &&
+//std.assertEqual(
+// std.parseYaml(
+// |||
+// f1: |
+// a
+// b
+// f2: "a\nb\n"
+// |||
+// ), { f1: 'a\nb\n', f2: 'a\nb\n' }
+//) &&
+//// Issue https://github.com/google/jsonnet/issues/1014
+//std.assertEqual(std.parseYaml('version: 1.2.3'), { version: '1.2.3' }) &&
+//// Issue https://github.com/google/jsonnet/issues/1050
+//std.assertEqual(std.type(std.parseYaml('id: "12345"').id), 'string') &&
+
+std.assertEqual(std.asciiUpper('!@#$%&*()asdfghFGHJKL09876 '), '!@#$%&*()ASDFGHFGHJKL09876 ') &&
+std.assertEqual(std.asciiLower('!@#$%&*()asdfghFGHJKL09876 '), '!@#$%&*()asdfghfghjkl09876 ') &&
+
+//std.assertEqual(std.deepJoin(['a', ['b', 'c', [[], 'd', ['e'], 'f', 'g'], [], []], 'h']),
+// 'abcdefgh') &&
+
+std.assertEqual(std.findSubstr('', 'a'), []) &&
+std.assertEqual(std.findSubstr('aa', ''), []) &&
+std.assertEqual(std.findSubstr('aa', 'bb'), []) &&
+std.assertEqual(std.findSubstr('aa', 'a'), []) &&
+std.assertEqual(std.findSubstr('aa', 'aa'), [0]) &&
+std.assertEqual(std.findSubstr('aa', 'bbaabaaa'), [2, 5, 6]) &&
+
+std.assertEqual(std.find(null, [null]), [0]) &&
+std.assertEqual(std.find([], [[]]), [0]) &&
+std.assertEqual(std.find({}, [{}]), [0]) &&
+std.assertEqual(std.find('a', []), []) &&
+std.assertEqual(std.find('a', ['b']), []) &&
+std.assertEqual(std.find('a', ['a']), [0]) &&
+std.assertEqual(std.find('a', ['a', ['a'], 'b', 'a']), [0, 3]) &&
+std.assertEqual(std.find(['a'], [['a']]), [0]) &&
+
+std.assertEqual(std.encodeUTF8(''), []) &&
+std.assertEqual(std.encodeUTF8('A'), [65]) &&
+std.assertEqual(std.encodeUTF8('AAA'), [65, 65, 65]) &&
+std.assertEqual(std.encodeUTF8('§'), [194, 167]) &&
+std.assertEqual(std.encodeUTF8('Zażółć gęślą jaźń'), [90, 97, 197, 188, 195, 179, 197, 130, 196, 135, 32, 103, 196, 153, 197, 155, 108, 196, 133, 32, 106, 97, 197, 186, 197, 132]) &&
+std.assertEqual(std.encodeUTF8('😃'), [240, 159, 152, 131]) &&
+
+std.assertEqual(std.decodeUTF8([]), '') &&
+std.assertEqual(std.decodeUTF8([65]), 'A') &&
+std.assertEqual(std.decodeUTF8([65, 65, 65]), 'AAA') &&
+std.assertEqual(std.decodeUTF8([(function(x) 65)(42)]), 'A') &&
+std.assertEqual(std.decodeUTF8([65 + 1 - 1]), 'A') &&
+std.assertEqual(std.decodeUTF8([90, 97, 197, 188, 195, 179, 197, 130, 196, 135, 32, 103, 196, 153, 197, 155, 108, 196, 133, 32, 106, 97, 197, 186, 197, 132]), 'Zażółć gęślą jaźń') &&
+std.assertEqual(std.decodeUTF8([240, 159, 152, 131]), '😃') &&
+
+std.assertEqual(std.any([true, false]), true) &&
+std.assertEqual(std.any([false, false]), false) &&
+std.assertEqual(std.any([]), false) &&
+
+std.assertEqual(std.all([true, false]), false) &&
+std.assertEqual(std.all([true, true]), true) &&
+std.assertEqual(std.all([]), true) &&
+
+std.assertEqual(std.sum([1, 2, 3]), 6) &&
+
+std.assertEqual(std.avg([1, 2, 3]), 2) &&
+std.assertEqual(std.avg([0, 0, 0]), 0) &&
+std.assertEqual(std.avg([1, 1, 2.5]), 1.5) &&
+
+std.assertEqual(std.minArray([1, 2, 3]), 1) &&
+std.assertEqual(std.minArray(['1', '2', '3']), '1') &&
+
+std.assertEqual(std.maxArray([1, 2, 3]), 3) &&
+std.assertEqual(std.maxArray(['1', '2', '3']), '3') &&
+std.assertEqual(std.maxArray(['a', 'x', 'z']), 'z') &&
+
+std.assertEqual(std.xor(true, false), true) &&
+std.assertEqual(std.xor(true, true), false) &&
+
+std.assertEqual(std.xnor(true, false), false) &&
+std.assertEqual(std.xnor(true, true), true) &&
+
+//std.assertEqual(std.round(1.2), 1) &&
+//std.assertEqual(std.round(1.5), 2) &&
+
+std.assertEqual(std.isEmpty(''), true) &&
+std.assertEqual(std.isEmpty('non-empty string'), false) &&
+
+std.assertEqual(std.contains([1, 2, 3], 2), true) &&
+std.assertEqual(std.contains([1, 2, 3], 'foo'), false) &&
+
+std.assertEqual(std.equalsIgnoreCase('foo', 'FOO'), true) &&
+std.assertEqual(std.equalsIgnoreCase('foo', 'bar'), false) &&
+
+//std.assertEqual(std.isEven(10), true) &&
+//std.assertEqual(std.isEven(5), false) &&
+//std.assertEqual(std.isOdd(5), true) &&
+//std.assertEqual(std.isOdd(10), false) &&
+//std.assertEqual(std.isInteger(1), true) &&
+//std.assertEqual(std.isInteger(1.1), false) &&
+//std.assertEqual(std.isDecimal(1.1), true) &&
+//std.assertEqual(std.isDecimal(1), false) &&
+
+std.assertEqual(std.remove([1, 2, 3], 2), [1, 3]) &&
+std.assertEqual(std.removeAt([1, 2, 3], 1), [1, 3]) &&
+
+std.assertEqual(std.objectRemoveKey({ foo: 1, bar: 2, baz: 3 }, 'foo'), { bar: 2, baz: 3 }) &&
+
+std.assertEqual(std.trim('already trimmed string'), 'already trimmed string') &&
+std.assertEqual(std.trim(' string with spaces on both ends '), 'string with spaces on both ends') &&
+std.assertEqual(std.trim('string with newline character at end\n'), 'string with newline character at end') &&
+std.assertEqual(std.trim('string with tabs at end\t\t'), 'string with tabs at end') &&
+// The last character here was previously expressed as \u00A0, but this is rewritten by jsonnetfmt.
+// To avoid ambiguity but allow the code to pass unchanged through jsonnetfmt, this now uses a std.char() call.
+std.assertEqual(std.trim('string with other special whitespaces at end\f\r\u0085' + std.char(160)), 'string with other special whitespaces at end') &&
+
+true
\ No newline at end of file
diff --git a/sjsonnet/test/src-jvm-js/sjsonnet/StdStripCharsTests.scala b/sjsonnet/test/src-jvm-js/sjsonnet/StdStripCharsTests.scala
index 70515601..2b9de713 100644
--- a/sjsonnet/test/src-jvm-js/sjsonnet/StdStripCharsTests.scala
+++ b/sjsonnet/test/src-jvm-js/sjsonnet/StdStripCharsTests.scala
@@ -11,7 +11,7 @@ object StdStripCharsTests extends TestSuite {
eval("std.rstripChars(\"cacabbbbaacc\", \"ac\")").toString() ==> """"cacabbbb""""
eval("std.rstripChars(\"cacabbcacabbaacc\", \"ac\")").toString() ==> """"cacabbcacabb""""
- eval("std.rstripChars(\"cacabbcacabb[aacc]\", \"ac[]$%^&*(\")").toString() ==> """"cacabbcacabb""""
+ eval("""std.rstripChars("cacabbcacabb[aacc]", "ac[]$%^&*(")""").toString() ==> """"cacabbcacabb""""
}
test("stdLStripChars") {
eval("std.lstripChars(\" test test test \", \" \")").toString() ==> """"test test test """"
diff --git a/sjsonnet/test/src-jvm-native/sjsonnet/ErrorTests.scala b/sjsonnet/test/src-jvm-native/ErrorTests.scala
similarity index 99%
rename from sjsonnet/test/src-jvm-native/sjsonnet/ErrorTests.scala
rename to sjsonnet/test/src-jvm-native/ErrorTests.scala
index 455abf62..0240075a 100644
--- a/sjsonnet/test/src-jvm-native/sjsonnet/ErrorTests.scala
+++ b/sjsonnet/test/src-jvm-native/ErrorTests.scala
@@ -1,5 +1,4 @@
-package sjsonnet
-
+import sjsonnet._
import utest._
object ErrorTests extends TestSuite{
diff --git a/sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala b/sjsonnet/test/src-jvm-native/PrettyYamlRendererTests.scala
similarity index 98%
rename from sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala
rename to sjsonnet/test/src-jvm-native/PrettyYamlRendererTests.scala
index 7d3e9e19..b1f5a855 100644
--- a/sjsonnet/test/src-jvm-native/sjsonnet/PrettyYamlRendererTests.scala
+++ b/sjsonnet/test/src-jvm-native/PrettyYamlRendererTests.scala
@@ -1,5 +1,4 @@
-package sjsonnet
-
+import sjsonnet._
import utest._
object PrettyYamlRendererTests extends TestSuite{
diff --git a/sjsonnet/test/src-jvm-native/sjsonnet/FileTests.scala b/sjsonnet/test/src-jvm/sjsonnet/FileTests.scala
similarity index 100%
rename from sjsonnet/test/src-jvm-native/sjsonnet/FileTests.scala
rename to sjsonnet/test/src-jvm/sjsonnet/FileTests.scala
diff --git a/sjsonnet/test/src-native/sjsonnet/FileTests.scala b/sjsonnet/test/src-native/sjsonnet/FileTests.scala
new file mode 100644
index 00000000..01330941
--- /dev/null
+++ b/sjsonnet/test/src-native/sjsonnet/FileTests.scala
@@ -0,0 +1,74 @@
+package sjsonnet
+
+import utest._
+
+object FileTests extends TestSuite{
+ val testSuiteRoot = os.pwd / "sjsonnet" / "test" / "resources" / "test_suite"
+ def eval(p: os.Path) = {
+ val interp = new Interpreter(
+ Map("var1" -> "\"test\"", "var2" -> """local f(a, b) = {[a]: b, "y": 2}; f("x", 1)"""),
+ Map("var1" -> "\"test\"", "var2" -> """{"x": 1, "y": 2}"""),
+ OsPath(testSuiteRoot),
+ importer = sjsonnet.SjsonnetMain.resolveImport(Array(OsPath(testSuiteRoot))),
+ parseCache = new DefaultParseCache
+ )
+ interp.interpret(os.read(p), OsPath(p))
+ }
+ def check(expected: ujson.Value = ujson.True)(implicit tp: utest.framework.TestPath) = {
+ val res = eval(testSuiteRoot / s"${tp.value.last}.jsonnet")
+ assert(res == Right(expected))
+ res
+ }
+ def checkFail(expected: String)(implicit tp: utest.framework.TestPath) = {
+ val res = eval(testSuiteRoot / s"${tp.value.last}.jsonnet")
+ assert(res == Left(expected))
+ res
+ }
+ def checkGolden()(implicit tp: utest.framework.TestPath) = {
+ check(ujson.read(os.read(testSuiteRoot / s"${tp.value.last}.jsonnet.golden")))
+ }
+ def tests = Tests{
+ test("arith_bool") - check()
+ test("arith_float") - check()
+ test("arith_string") - check()
+ test("array") - check()
+ test("assert") - check()
+ test("binary") - check()
+ test("comments") - check()
+ test("condition") - check()
+// test("dos_line_endings") - checkGolden()
+ test("format") - check()
+// test("formatter") - checkGolden()
+ test("formatting_braces") - checkGolden()
+ test("formatting_braces2") - checkGolden()
+ test("functions") - check()
+ test("import") - check()
+ test("invariant") - check()
+ test("invariant_manifest") - checkGolden()
+ test("local") - check()
+ test("merge") - check()
+ test("null") - check()
+ test("object") - check()
+ test("oop") - check()
+ test("oop_extra") - check()
+ test("parsing_edge_cases") - check()
+ test("precedence") - check()
+// test("recursive_function") - check()
+ test("recursive_import_ok") - check()
+ test("recursive_object") - check()
+ test("sanity") - checkGolden()
+ test("sanity2") - checkGolden()
+ test("shebang") - check()
+ "slice.sugar" - check()
+ test("std_all_hidden") - check()
+ test("stdlib_native") - check()
+ test("text_block") - check()
+ "tla.simple"- check()
+ test("unicode") - check()
+ test("unix_line_endings") - checkGolden()
+ test("unparse") - checkGolden()
+ test("verbatim_strings") - check()
+ test("issue_127") - check()
+ }
+}
+
diff --git a/sjsonnet/test/src/sjsonnet/FormatTests.scala b/sjsonnet/test/src/sjsonnet/FormatTests.scala
index b44b8484..5eb461d1 100644
--- a/sjsonnet/test/src/sjsonnet/FormatTests.scala
+++ b/sjsonnet/test/src/sjsonnet/FormatTests.scala
@@ -15,6 +15,7 @@ object FormatTests extends TestSuite{
def visitExpr(expr: Expr)(implicit scope: ValScope): Val = ???
def materialize(v: Val): Value = ???
def equal(x: Val, y: Val): Boolean = ???
+ def compare(x: Val, y: Val): Int = ???
def importer: sjsonnet.CachedImporter = ???
def settings = Settings.default
def warn(e: Error) = ()