From 0134a27c6afa185c4f13dcc4b2989daf376ed1c0 Mon Sep 17 00:00:00 2001 From: Shimin Guo Date: Tue, 24 May 2016 20:51:40 +0800 Subject: [PATCH] avoid trailing spaces in manifestJsonEx output --- stdlib/std.jsonnet | 12 ++++++------ test_suite/stdlib.jsonnet | 8 ++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/stdlib/std.jsonnet b/stdlib/std.jsonnet index 4e4d092b7..5bb2c20a9 100644 --- a/stdlib/std.jsonnet +++ b/stdlib/std.jsonnet @@ -726,16 +726,16 @@ limitations under the License. error "Tried to manifest function at " + path else if std.type(v) == "array" then local range = std.range(0, std.length(v) - 1); - local lines = ["[\n" + cindent] - + std.join([",\n" + cindent], - [[indent + aux(v[i], path + [i], cindent + indent)] for i + local lines = ["[\n"] + + std.join([",\n"], + [[cindent + indent + aux(v[i], path + [i], cindent + indent)] for i in range]) + ["\n" + cindent + "]"]; std.join("", lines) else if std.type(v) == "object" then - local lines = ["{\n" + cindent] - + std.join([",\n" + cindent], - [[indent + "\"" + k + "\": " + local lines = ["{\n"] + + std.join([",\n"], + [[cindent + indent + "\"" + k + "\": " + aux(v[k], path + [k], cindent + indent)] for k in std.objectFields(v)]) + ["\n" + cindent + "}"]; diff --git a/test_suite/stdlib.jsonnet b/test_suite/stdlib.jsonnet index 70b3957df..362c128d0 100644 --- a/test_suite/stdlib.jsonnet +++ b/test_suite/stdlib.jsonnet @@ -341,8 +341,16 @@ std.assertEqual(std.splitLimit("/foo/", "/", 1), ["", "foo/"]) && std.assertEqual(std.manifestJsonEx({ x: [1, 2, 3, true, false, null, "string\nstring"], y: { a: 1, b: 2, c: [1, 2] }, + emptyArray: [], + emptyObject: {}, }, " ") + "\n", ||| { + "emptyArray": [ + + ], + "emptyObject": { + + }, "x": [ 1, 2,