Skip to content

Commit baff839

Browse files
committed
Update stdlib
1 parent d430c84 commit baff839

13 files changed

+63425
-68844
lines changed

ast/stdast.go

+63,364-68,804
Large diffs are not rendered by default.

std/std.jsonnet

+26-5
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ limitations under the License.
7070
local lower_a_code = std.codepoint('a');
7171
local addDigit(aggregate, char) =
7272
local code = std.codepoint(char);
73-
local digit = if code > lower_a_code then
73+
local digit = if code >= lower_a_code then
7474
code - lower_a_code + 10
75-
else if code > upper_a_code then
75+
else if code >= upper_a_code then
7676
code - upper_a_code + 10
7777
else
7878
code - zero_code;
@@ -81,6 +81,8 @@ limitations under the License.
8181
std.foldl(addDigit, std.stringChars(str), 0),
8282

8383
parseInt(str)::
84+
assert std.isString(str): 'Expected string, got ' + std.type(str);
85+
assert std.length(str) > 0 && str != "-": 'Not an integer: "%s"' % [str];
8486
if str[0] == '-' then
8587
-parse_nat(str[1:], 10)
8688
else
@@ -147,9 +149,9 @@ limitations under the License.
147149
acc + str[start_index:curr_index]
148150
else if found_at(curr_index) then
149151
local new_index = curr_index + std.length(from);
150-
replace_after(new_index, new_index, acc + str[start_index:curr_index] + to)
152+
replace_after(new_index, new_index, acc + str[start_index:curr_index] + to) tailstrict
151153
else
152-
replace_after(start_index, curr_index + 1, acc);
154+
replace_after(start_index, curr_index + 1, acc) tailstrict;
153155

154156
// if from_len==1, then we replace by splitting and rejoining the
155157
// string which is much faster than recursing on replace_after
@@ -853,7 +855,7 @@ limitations under the License.
853855
'\\t'
854856
else
855857
local cp = std.codepoint(ch);
856-
if cp < 32 || (cp >= 126 && cp <= 159) then
858+
if cp < 32 || (cp >= 127 && cp <= 159) then
857859
'\\u%04x' % [cp]
858860
else
859861
ch;
@@ -1245,4 +1247,23 @@ limitations under the License.
12451247
if isContent(std.prune(a[x]))
12461248
} else
12471249
a,
1250+
1251+
findSubstr(pat, str)::
1252+
if std.type(pat) != 'string' then
1253+
error 'findSubstr first parameter should be a string, got ' + std.type(pat)
1254+
else if std.type(str) != 'string' then
1255+
error 'findSubstr second parameter should be a string, got ' + std.type(str)
1256+
else
1257+
local pat_len = std.length(pat);
1258+
local str_len = std.length(str);
1259+
if pat_len == 0 || str_len == 0 || pat_len > str_len then
1260+
[]
1261+
else
1262+
std.filter(function(i) str[i:i+pat_len] == pat, std.range(0, str_len - pat_len)),
1263+
1264+
find(value, arr)::
1265+
if std.type(arr) != 'array' then
1266+
error 'find second parameter should be an array, got ' + std.type(arr)
1267+
else
1268+
std.filter(function(i) arr[i] == value, std.range(0, std.length(arr) - 1)),
12481269
}

testdata/assert_equal4.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Assertion failed. {"x": 1} != {"x": 2}
22
-------------------------------------------------
3-
<std>:780:7-50 function <anonymous>
3+
<std>:782:7-50 function <anonymous>
44

55
error 'Assertion failed. ' + a + ' != ' + b,
66

testdata/assert_equal5.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ RUNTIME ERROR: Assertion failed.
22
!=
33

44
-------------------------------------------------
5-
<std>:780:7-50 function <anonymous>
5+
<std>:782:7-50 function <anonymous>
66

77
error 'Assertion failed. ' + a + ' != ' + b,
88

testdata/assert_equal6.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Assertion failed.  !=
22
-------------------------------------------------
3-
<std>:780:7-50 function <anonymous>
3+
<std>:782:7-50 function <anonymous>
44

55
error 'Assertion failed. ' + a + ' != ' + b,
66

testdata/percent_bad.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Operator % cannot be used on types number and string.
22
-------------------------------------------------
3-
<std>:227:7-94 function <anonymous>
3+
<std>:229:7-94 function <anonymous>
44

55
error 'Operator % cannot be used on types ' + std.type(a) + ' and ' + std.type(b) + '.',
66

testdata/percent_bad2.golden

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
RUNTIME ERROR: Too many values to format: 1, expected 0
22
-------------------------------------------------
3-
<std>:650:11-86 function <format_codes_arr>
3+
<std>:652:11-86 function <format_codes_arr>
44

55
error ('Too many values to format: ' + std.length(arr) + ', expected ' + j)
66

77
-------------------------------------------------
8-
<std>:656:11-59 function <format_codes_arr>
8+
<std>:658:11-59 function <format_codes_arr>
99

1010
format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict
1111

1212
-------------------------------------------------
13-
<std>:747:7-48 function <anonymous>
13+
<std>:749:7-48 function <anonymous>
1414

1515
format_codes_arr(codes, [vals], 0, 0, ''),
1616

1717
-------------------------------------------------
18-
<std>:225:7-23 function <anonymous>
18+
<std>:227:7-23 function <anonymous>
1919

2020
std.format(a, b)
2121

testdata/percent_bad3.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Operator % cannot be used on types function and number.
22
-------------------------------------------------
3-
<std>:227:7-94 function <anonymous>
3+
<std>:229:7-94 function <anonymous>
44

55
error 'Operator % cannot be used on types ' + std.type(a) + ' and ' + std.type(b) + '.',
66

testdata/percent_format_str4.golden

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
RUNTIME ERROR: Too many values to format: 2, expected 1
22
-------------------------------------------------
3-
<std>:650:11-86 function <format_codes_arr>
3+
<std>:652:11-86 function <format_codes_arr>
44

55
error ('Too many values to format: ' + std.length(arr) + ', expected ' + j)
66

77
-------------------------------------------------
8-
<std>:656:11-59 function <format_codes_arr>
8+
<std>:658:11-59 function <format_codes_arr>
99

1010
format_codes_arr(codes, arr, i + 1, j, v + code) tailstrict
1111

1212
-------------------------------------------------
13-
<std>:743:7-46 function <anonymous>
13+
<std>:745:7-46 function <anonymous>
1414

1515
format_codes_arr(codes, vals, 0, 0, '')
1616

1717
-------------------------------------------------
18-
<std>:225:7-23 function <anonymous>
18+
<std>:227:7-23 function <anonymous>
1919

2020
std.format(a, b)
2121

testdata/percent_format_str5.golden

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
RUNTIME ERROR: Not enough values to format, got 1
22
-------------------------------------------------
3-
<std>:683:15-74 thunk <val> from <function <format_codes_arr>>
3+
<std>:685:15-74 thunk <val> from <function <format_codes_arr>>
44

55
error 'Not enough values to format, got ' + std.length(arr);
66

77
-------------------------------------------------
8-
<std>:688:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>
8+
<std>:690:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>
99

1010
format_code(val, code, tmp.fw, tmp2.prec, j2);
1111

1212
-------------------------------------------------
13-
<std>:558:22-25 thunk from <function <format_code>>
13+
<std>:560:22-25 thunk from <function <format_code>>
1414

1515
std.toString(val)
1616

1717
-------------------------------------------------
18-
<std>:558:9-26 function <format_code>
18+
<std>:560:9-26 function <format_code>
1919

2020
std.toString(val)
2121

2222
-------------------------------------------------
2323
... (skipped 10 frames)
2424
-------------------------------------------------
25-
<std>:699:11-64 function <format_codes_arr>
25+
<std>:701:11-64 function <format_codes_arr>
2626

2727
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
2828

2929
-------------------------------------------------
30-
<std>:743:7-46 function <anonymous>
30+
<std>:745:7-46 function <anonymous>
3131

3232
format_codes_arr(codes, vals, 0, 0, '')
3333

3434
-------------------------------------------------
35-
<std>:225:7-23 function <anonymous>
35+
<std>:227:7-23 function <anonymous>
3636

3737
std.format(a, b)
3838

testdata/percent_format_str6.golden

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
RUNTIME ERROR: Not enough values to format, got 1
22
-------------------------------------------------
3-
<std>:683:15-74 thunk <val> from <function <format_codes_arr>>
3+
<std>:685:15-74 thunk <val> from <function <format_codes_arr>>
44

55
error 'Not enough values to format, got ' + std.length(arr);
66

77
-------------------------------------------------
8-
<std>:688:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>
8+
<std>:690:27-30 thunk from <thunk <s> from <function <format_codes_arr>>>
99

1010
format_code(val, code, tmp.fw, tmp2.prec, j2);
1111

1212
-------------------------------------------------
13-
<std>:558:22-25 thunk from <function <format_code>>
13+
<std>:560:22-25 thunk from <function <format_code>>
1414

1515
std.toString(val)
1616

1717
-------------------------------------------------
18-
<std>:558:9-26 function <format_code>
18+
<std>:560:9-26 function <format_code>
1919

2020
std.toString(val)
2121

2222
-------------------------------------------------
2323
... (skipped 10 frames)
2424
-------------------------------------------------
25-
<std>:699:11-64 function <format_codes_arr>
25+
<std>:701:11-64 function <format_codes_arr>
2626

2727
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
2828

2929
-------------------------------------------------
30-
<std>:747:7-48 function <anonymous>
30+
<std>:749:7-48 function <anonymous>
3131

3232
format_codes_arr(codes, [vals], 0, 0, ''),
3333

3434
-------------------------------------------------
35-
<std>:225:7-23 function <anonymous>
35+
<std>:227:7-23 function <anonymous>
3636

3737
std.format(a, b)
3838

testdata/percent_format_str7.golden

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
RUNTIME ERROR: Format required number at 0, got string
22
-------------------------------------------------
3-
<std>:(561:11)-(562:47) function <format_code>
3+
<std>:(563:11)-(564:47) function <format_code>
44

55
error 'Format required number at '
66
+ i + ', got ' + std.type(val)
77

88
-------------------------------------------------
9-
<std>:688:15-60 thunk <s> from <function <format_codes_arr>>
9+
<std>:690:15-60 thunk <s> from <function <format_codes_arr>>
1010

1111
format_code(val, code, tmp.fw, tmp2.prec, j2);
1212

1313
-------------------------------------------------
14-
<std>:693:24-25 thunk from <thunk <s_padded> from <function <format_codes_arr>>>
14+
<std>:695:24-25 thunk from <thunk <s_padded> from <function <format_codes_arr>>>
1515

1616
pad_left(s, tmp.fw, ' ');
1717

1818
-------------------------------------------------
19-
<std>:473:30-33 thunk from <thunk from <function <pad_left>>>
19+
<std>:475:30-33 thunk from <thunk from <function <pad_left>>>
2020

2121
padding(w - std.length(str), s) + str;
2222

2323
-------------------------------------------------
2424
... (skipped 7 frames)
2525
-------------------------------------------------
26-
<std>:699:11-64 function <format_codes_arr>
26+
<std>:701:11-64 function <format_codes_arr>
2727

2828
format_codes_arr(codes, arr, i + 1, j3, v + s_padded) tailstrict;
2929

3030
-------------------------------------------------
31-
<std>:743:7-46 function <anonymous>
31+
<std>:745:7-46 function <anonymous>
3232

3333
format_codes_arr(codes, vals, 0, 0, '')
3434

3535
-------------------------------------------------
36-
<std>:225:7-23 function <anonymous>
36+
<std>:227:7-23 function <anonymous>
3737

3838
std.format(a, b)
3939

testdata/percent_mod_int5.golden

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
RUNTIME ERROR: Division by zero.
22
-------------------------------------------------
3-
<std>:223:7-23 builtin function <modulo>
3+
<std>:225:7-23 builtin function <modulo>
44

55
std.modulo(a, b)
66

0 commit comments

Comments
 (0)