diff --git a/stdlib/std.jsonnet b/stdlib/std.jsonnet index ce3c8bbeb..188c6b7d2 100644 --- a/stdlib/std.jsonnet +++ b/stdlib/std.jsonnet @@ -321,25 +321,20 @@ limitations under the License. }; // Parse a format string (containing none or more % format tags). - local parse_codes(str, i, out) = + local parse_codes(str, i, out, cur) = if i >= std.length(str) then - out + out + [cur] else local c = str[i]; if c == "%" then local r = parse_code(str, i + 1); - parse_codes(str, r.i, out+[r.code]) tailstrict + parse_codes(str, r.i, out+[cur, r.code], "") tailstrict else local last = out[std.length(out)-1]; local append = std.length(out) > 0 && std.type(last) == "string"; - parse_codes(str, i + 1, if append then - std.makeArray(std.length(out), - function(i) if i < std.length(out)-1 then out[i] else last + c) tailstrict - else - std.makeArray(std.length(out) + 1, - function(i) if i < std.length(out) then out[i] else c)) tailstrict; + parse_codes(str, i + 1, out, cur + c) tailstrict; - local codes = parse_codes(str, 0, []); + local codes = parse_codes(str, 0, [], ""); /////////////////////// diff --git a/test_suite/error.equality_function.jsonnet.golden b/test_suite/error.equality_function.jsonnet.golden index e3f37cffa..b98fb7d16 100644 --- a/test_suite/error.equality_function.jsonnet.golden +++ b/test_suite/error.equality_function.jsonnet.golden @@ -1,3 +1,3 @@ RUNTIME ERROR: Cannot test equality of functions - std.jsonnet:948:17-41 function + std.jsonnet:943:17-41 function error.equality_function.jsonnet:17:1-32 diff --git a/test_suite/error.inside_equals_array.jsonnet.golden b/test_suite/error.inside_equals_array.jsonnet.golden index c31f7ca97..f8d3fddad 100644 --- a/test_suite/error.inside_equals_array.jsonnet.golden +++ b/test_suite/error.inside_equals_array.jsonnet.golden @@ -1,7 +1,7 @@ RUNTIME ERROR: foobar error.inside_equals_array.jsonnet:18:18-31 thunk - std.jsonnet:928:41-44 thunk - std.jsonnet:928:33-44 function - std.jsonnet:928:33-44 function - std.jsonnet:931:29-44 function - std.jsonnet:932:21-32 + std.jsonnet:923:41-44 thunk + std.jsonnet:923:33-44 function + std.jsonnet:923:33-44 function + std.jsonnet:926:29-44 function + std.jsonnet:927:21-32 diff --git a/test_suite/error.inside_equals_object.jsonnet.golden b/test_suite/error.inside_equals_object.jsonnet.golden index 9598dd593..d62509d8e 100644 --- a/test_suite/error.inside_equals_object.jsonnet.golden +++ b/test_suite/error.inside_equals_object.jsonnet.golden @@ -1,7 +1,7 @@ RUNTIME ERROR: foobar error.inside_equals_object.jsonnet:18:22-35 object - std.jsonnet:942:62-65 thunk - std.jsonnet:942:54-65 function - std.jsonnet:942:54-65 function - std.jsonnet:945:29-44 function - std.jsonnet:946:21-32 + std.jsonnet:937:62-65 thunk + std.jsonnet:937:54-65 function + std.jsonnet:937:54-65 function + std.jsonnet:940:29-44 function + std.jsonnet:941:21-32 diff --git a/test_suite/error.invariant.equality.jsonnet.golden b/test_suite/error.invariant.equality.jsonnet.golden index d6f1c309a..79a83f982 100644 --- a/test_suite/error.invariant.equality.jsonnet.golden +++ b/test_suite/error.invariant.equality.jsonnet.golden @@ -1,6 +1,6 @@ RUNTIME ERROR: Object assertion failed. error.invariant.equality.jsonnet:17:10-14 thunk - std.jsonnet:942:54-57 thunk - std.jsonnet:942:54-65 function - std.jsonnet:942:54-65 function - std.jsonnet:946:21-32 + std.jsonnet:937:54-57 thunk + std.jsonnet:937:54-65 function + std.jsonnet:937:54-65 function + std.jsonnet:941:21-32 diff --git a/test_suite/error.sanity.jsonnet.golden b/test_suite/error.sanity.jsonnet.golden index 0ffe22b09..2351bfdbc 100644 --- a/test_suite/error.sanity.jsonnet.golden +++ b/test_suite/error.sanity.jsonnet.golden @@ -1,3 +1,3 @@ RUNTIME ERROR: Assertion failed. 1 != 2 - std.jsonnet:635:13-55 function + std.jsonnet:630:13-55 function error.sanity.jsonnet:17:1-21 diff --git a/test_suite/format.jsonnet b/test_suite/format.jsonnet index b0b452fb9..4ff5f7464 100644 --- a/test_suite/format.jsonnet +++ b/test_suite/format.jsonnet @@ -251,4 +251,25 @@ std.assertEqual("%*.*f" % [10, 3, 1 / 3], "%10.3f" % [1 / 3]) && std.assertEqual("%(name)s[%(id)05d]-%(a)2x%(b)2x%(c)2x%(x)c" % { name: "foo", id: 3991, a: 17, b: 18, c: 17, x: 100 }, "foo[03991]-111211d") && +local text = ||| + Lorem ipsum dolor sit amet, consectetur adipiscing elit. In pellentesque felis mi, et iaculis + tellus consectetur pretium. Integer ultricies ullamcorper arcu quis bibendum. Vivamus luctus nec + nulla id egestas. Vestibulum lectus nibh, lobortis sed gravida ac, pellentesque sit amet eros. + Nulla urna purus, ornare at iaculis eget, pharetra sed libero. Fusce a neque malesuada, + hendrerit ex nec, suscipit lorem. Aenean orci quam, placerat sed mollis ut, faucibus nec turpis. + Vivamus consectetur auctor vehicula. Nam eu risus sit amet eros mattis finibus nec ac enim. + Quisque velit metus, tristique in urna in, dictum gravida elit.%(a)s + + Aenean laoreet libero nunc. Cras molestie condimentum mollis. Nam quis leo sed enim vestibulum + dapibus faucibus eget elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Class + aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Praesent + cursus magna at urna viverra, eget venenatis ante sodales. In vitae magna sed lacus iaculis + porttitor eu vel nisl. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut vitae sapien + vel eros ultricies iaculis. Pellentesque et metus libero. Proin nec rhoncus est. Vivamus a + aliquam ipsum, ut vehicula nibh. Sed ac posuere dolor. + ||| % { a: "a" }; + +std.assertEqual(std.length(text), 1244) && + + true