Skip to content

Commit

Permalink
Fix #386
Browse files Browse the repository at this point in the history
  • Loading branch information
sparkprime committed Oct 31, 2017
1 parent af2afbd commit d4434c8
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 25 deletions.
14 changes: 12 additions & 2 deletions stdlib/std.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,18 @@ limitations under the License.
std.foldl(function(a, b) a + b, arrs, []),

manifestIni(ini)::
local body_lines(body) = ["%s = %s" % [k, body[k]] for k in std.objectFields(body)],
section_lines(sname, sbody) = ["[%s]" % [sname]] + body_lines(sbody),
local body_lines(body) =
std.join([], [
local value_or_values = body[k];
if std.type(value_or_values) == "array" then
["%s = %s" % [k, value] for value in value_or_values]
else
["%s = %s" % [k, value_or_values]]

for k in std.objectFields(body)
]);

local section_lines(sname, sbody) = ["[%s]" % [sname]] + body_lines(sbody),
main_body = if std.objectHas(ini, "main") then body_lines(ini.main) else [],
all_sections = [section_lines(k, ini.sections[k])
for k in std.objectFields(ini.sections)];
Expand Down
2 changes: 1 addition & 1 deletion test_suite/error.equality_function.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RUNTIME ERROR: Cannot test equality of functions
std.jsonnet:1002:17-41 function <anonymous>
std.jsonnet:1012:17-41 function <anonymous>
error.equality_function.jsonnet:17:1-32
10 changes: 5 additions & 5 deletions test_suite/error.inside_equals_array.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RUNTIME ERROR: foobar
error.inside_equals_array.jsonnet:18:18-31 thunk <array_element>
std.jsonnet:982:41-44 thunk <b>
std.jsonnet:982:33-44 function <anonymous>
std.jsonnet:982:33-44 function <aux>
std.jsonnet:985:29-44 function <anonymous>
std.jsonnet:986:21-32
std.jsonnet:992:41-44 thunk <b>
std.jsonnet:992:33-44 function <anonymous>
std.jsonnet:992:33-44 function <aux>
std.jsonnet:995:29-44 function <anonymous>
std.jsonnet:996:21-32
10 changes: 5 additions & 5 deletions test_suite/error.inside_equals_object.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
RUNTIME ERROR: foobar
error.inside_equals_object.jsonnet:18:22-35 object <b>
std.jsonnet:996:62-65 thunk <b>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:996:54-65 function <aux>
std.jsonnet:999:29-44 function <anonymous>
std.jsonnet:1000:21-32
std.jsonnet:1006:62-65 thunk <b>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1006:54-65 function <aux>
std.jsonnet:1009:29-44 function <anonymous>
std.jsonnet:1010:21-32
8 changes: 4 additions & 4 deletions test_suite/error.invariant.equality.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Object assertion failed.
error.invariant.equality.jsonnet:17:10-14 thunk <object_assert>
std.jsonnet:996:54-57 thunk <a>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:1000:21-32
std.jsonnet:1006:54-57 thunk <a>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1010:21-32
8 changes: 4 additions & 4 deletions test_suite/error.obj_assert.fail1.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: Object assertion failed.
error.obj_assert.fail1.jsonnet:20:23-28 thunk <object_assert>
std.jsonnet:996:54-57 thunk <a>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:1000:21-32
std.jsonnet:1006:54-57 thunk <a>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1010:21-32
8 changes: 4 additions & 4 deletions test_suite/error.obj_assert.fail2.jsonnet.golden
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RUNTIME ERROR: foo was not equal to bar
error.obj_assert.fail2.jsonnet:20:32-64 thunk <object_assert>
std.jsonnet:996:54-57 thunk <a>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:996:54-65 function <anonymous>
std.jsonnet:1000:21-32
std.jsonnet:1006:54-57 thunk <a>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1006:54-65 function <anonymous>
std.jsonnet:1010:21-32
16 changes: 16 additions & 0 deletions test_suite/stdlib.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,22 @@ std.assertEqual(
"[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
a = 2
[s2]
p = yes
p =
|||
) &&


std.assertEqual(std.escapeStringJson("hello"), "\"hello\"") &&
std.assertEqual(std.escapeStringJson("he\"llo"), "\"he\\\"llo\"") &&
std.assertEqual(std.escapeStringJson("he\"llo"), "\"he\\\"llo\"") &&
Expand Down

0 comments on commit d4434c8

Please sign in to comment.