Skip to content

Commit 140d65f

Browse files
committed
Merge pull request #166 from sparkprime/func_tests
More tests for named params / default args
2 parents 2c806e1 + 1973012 commit 140d65f

9 files changed

+116
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
Copyright 2015 Google Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
local foo(a, b) = [a, b];
18+
19+
foo(b=3, 4)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RUNTIME ERROR: Internal error: got positional param after named at index 1
2+
error.function_arg_positional_after_named.jsonnet:19:1-11
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2015 Google Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
function(x=y, y=x) x
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
RUNTIME ERROR: Max stack frames exceeded.
2+
error.function_infinite_default.jsonnet:17:12 thunk <x>
3+
error.function_infinite_default.jsonnet:17:17 thunk <y>
4+
error.function_infinite_default.jsonnet:17:12 thunk <x>
5+
error.function_infinite_default.jsonnet:17:17 thunk <y>
6+
error.function_infinite_default.jsonnet:17:12 thunk <x>
7+
error.function_infinite_default.jsonnet:17:17 thunk <y>
8+
error.function_infinite_default.jsonnet:17:12 thunk <x>
9+
error.function_infinite_default.jsonnet:17:17 thunk <y>
10+
error.function_infinite_default.jsonnet:17:12 thunk <x>
11+
error.function_infinite_default.jsonnet:17:17 thunk <y>
12+
...
13+
error.function_infinite_default.jsonnet:17:17 thunk <y>
14+
error.function_infinite_default.jsonnet:17:12 thunk <x>
15+
error.function_infinite_default.jsonnet:17:17 thunk <y>
16+
error.function_infinite_default.jsonnet:17:12 thunk <x>
17+
error.function_infinite_default.jsonnet:17:17 thunk <y>
18+
error.function_infinite_default.jsonnet:17:12 thunk <x>
19+
error.function_infinite_default.jsonnet:17:17 thunk <y>
20+
error.function_infinite_default.jsonnet:17:12 thunk <x>
21+
error.function_infinite_default.jsonnet:17:20 function <top_level>
22+
Top-level function
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Copyright 2015 Google Inc. All rights reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
function(a=3, b) null
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
RUNTIME ERROR: Function parameter b not bound in call.
2+
Top-level function

test_suite/formatter.jsonnet

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ limitations under the License.
3636
g: 2,
3737
},
3838

39+
local test_local_default1(x=100, y=200) = {
40+
g: 2,
41+
},
42+
43+
local test_local_default2(
44+
x=100,
45+
y=200)
46+
= {
47+
g: 2,
48+
},
49+
3950
test_field0A: {
4051
g: 1,
4152
},

test_suite/formatter.jsonnet.fmt.golden

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ limitations under the License.
3636
g: 2,
3737
},
3838

39+
local test_local_default1(x=100, y=200) = {
40+
g: 2,
41+
},
42+
43+
local test_local_default2(
44+
x=100,
45+
y=200)
46+
= {
47+
g: 2,
48+
},
49+
3950
test_field0A: {
4051
g: 1,
4152
},

test_suite/functions.jsonnet

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,19 @@ std.assertEqual((local x = 3; function(a=[x, b[1]], b=[a[0], 2]) [a, b])(),
4242
[[3, 2], [3, 2]]) &&
4343
std.assertEqual({ g: 3, f(a=[self.g, b[1]], b=[a[0], 2]): [a, b] }.f(),
4444
[[3, 2], [3, 2]]) &&
45+
46+
local url(host, port=80, protocol="http", url="%s://%s:%d/" % [protocol, host, port]) = url;
47+
48+
std.assertEqual(url("myhost"), "http://myhost:80/") &&
49+
std.assertEqual(url("mybucket", 8080, protocol="gs"), "gs://mybucket:8080/") &&
50+
std.assertEqual(url(null, url="wat"), "wat") &&
51+
52+
local test(a=error "Need a", alt="'" + a + "'") = alt;
53+
std.assertEqual(test(a="Q"), "'Q'") &&
54+
std.assertEqual(test(alt="|Q|"), "|Q|") &&
55+
56+
local X = 3;
57+
std.assertEqual((function(X=4) X)(), 4) &&
58+
std.assertEqual((function(X=4, Y=X) Y)(), 4) &&
59+
4560
true

0 commit comments

Comments
 (0)