From 19730128f225734bd350006e1b3fc764120a6439 Mon Sep 17 00:00:00 2001 From: Dave Cunningham Date: Mon, 25 Apr 2016 20:33:12 -0400 Subject: [PATCH] More tests for named params / default args --- ...unction_arg_positional_after_named.jsonnet | 19 ++++++++++++++++ ..._arg_positional_after_named.jsonnet.golden | 2 ++ .../error.function_infinite_default.jsonnet | 17 ++++++++++++++ ...r.function_infinite_default.jsonnet.golden | 22 +++++++++++++++++++ .../error.function_no_default_arg.jsonnet | 17 ++++++++++++++ ...ror.function_no_default_arg.jsonnet.golden | 2 ++ test_suite/formatter.jsonnet | 11 ++++++++++ test_suite/formatter.jsonnet.fmt.golden | 11 ++++++++++ test_suite/functions.jsonnet | 15 +++++++++++++ 9 files changed, 116 insertions(+) create mode 100644 test_suite/error.function_arg_positional_after_named.jsonnet create mode 100644 test_suite/error.function_arg_positional_after_named.jsonnet.golden create mode 100644 test_suite/error.function_infinite_default.jsonnet create mode 100644 test_suite/error.function_infinite_default.jsonnet.golden create mode 100644 test_suite/error.function_no_default_arg.jsonnet create mode 100644 test_suite/error.function_no_default_arg.jsonnet.golden diff --git a/test_suite/error.function_arg_positional_after_named.jsonnet b/test_suite/error.function_arg_positional_after_named.jsonnet new file mode 100644 index 000000000..ef3c6e48d --- /dev/null +++ b/test_suite/error.function_arg_positional_after_named.jsonnet @@ -0,0 +1,19 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +local foo(a, b) = [a, b]; + +foo(b=3, 4) diff --git a/test_suite/error.function_arg_positional_after_named.jsonnet.golden b/test_suite/error.function_arg_positional_after_named.jsonnet.golden new file mode 100644 index 000000000..5790d2002 --- /dev/null +++ b/test_suite/error.function_arg_positional_after_named.jsonnet.golden @@ -0,0 +1,2 @@ +RUNTIME ERROR: Internal error: got positional param after named at index 1 + error.function_arg_positional_after_named.jsonnet:19:1-11 diff --git a/test_suite/error.function_infinite_default.jsonnet b/test_suite/error.function_infinite_default.jsonnet new file mode 100644 index 000000000..a402fc7f7 --- /dev/null +++ b/test_suite/error.function_infinite_default.jsonnet @@ -0,0 +1,17 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +function(x=y, y=x) x diff --git a/test_suite/error.function_infinite_default.jsonnet.golden b/test_suite/error.function_infinite_default.jsonnet.golden new file mode 100644 index 000000000..faeae64c7 --- /dev/null +++ b/test_suite/error.function_infinite_default.jsonnet.golden @@ -0,0 +1,22 @@ +RUNTIME ERROR: Max stack frames exceeded. + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + ... + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:17 thunk + error.function_infinite_default.jsonnet:17:12 thunk + error.function_infinite_default.jsonnet:17:20 function + Top-level function diff --git a/test_suite/error.function_no_default_arg.jsonnet b/test_suite/error.function_no_default_arg.jsonnet new file mode 100644 index 000000000..6ffd2df45 --- /dev/null +++ b/test_suite/error.function_no_default_arg.jsonnet @@ -0,0 +1,17 @@ +/* +Copyright 2015 Google Inc. All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +function(a=3, b) null diff --git a/test_suite/error.function_no_default_arg.jsonnet.golden b/test_suite/error.function_no_default_arg.jsonnet.golden new file mode 100644 index 000000000..2c2a06f0b --- /dev/null +++ b/test_suite/error.function_no_default_arg.jsonnet.golden @@ -0,0 +1,2 @@ +RUNTIME ERROR: Function parameter b not bound in call. + Top-level function diff --git a/test_suite/formatter.jsonnet b/test_suite/formatter.jsonnet index 9ba2a2154..8795b04d3 100644 --- a/test_suite/formatter.jsonnet +++ b/test_suite/formatter.jsonnet @@ -36,6 +36,17 @@ limitations under the License. g: 2, }, + local test_local_default1(x=100, y=200) = { + g: 2, + }, + + local test_local_default2( + x=100, + y=200) + = { + g: 2, + }, + test_field0A: { g: 1, }, diff --git a/test_suite/formatter.jsonnet.fmt.golden b/test_suite/formatter.jsonnet.fmt.golden index 91960dae2..1747134ee 100644 --- a/test_suite/formatter.jsonnet.fmt.golden +++ b/test_suite/formatter.jsonnet.fmt.golden @@ -36,6 +36,17 @@ limitations under the License. g: 2, }, + local test_local_default1(x=100, y=200) = { + g: 2, + }, + + local test_local_default2( + x=100, + y=200) + = { + g: 2, + }, + test_field0A: { g: 1, }, diff --git a/test_suite/functions.jsonnet b/test_suite/functions.jsonnet index de906489d..cb9949c38 100644 --- a/test_suite/functions.jsonnet +++ b/test_suite/functions.jsonnet @@ -42,4 +42,19 @@ std.assertEqual((local x = 3; function(a=[x, b[1]], b=[a[0], 2]) [a, b])(), [[3, 2], [3, 2]]) && std.assertEqual({ g: 3, f(a=[self.g, b[1]], b=[a[0], 2]): [a, b] }.f(), [[3, 2], [3, 2]]) && + +local url(host, port=80, protocol="http", url="%s://%s:%d/" % [protocol, host, port]) = url; + +std.assertEqual(url("myhost"), "http://myhost:80/") && +std.assertEqual(url("mybucket", 8080, protocol="gs"), "gs://mybucket:8080/") && +std.assertEqual(url(null, url="wat"), "wat") && + +local test(a=error "Need a", alt="'" + a + "'") = alt; +std.assertEqual(test(a="Q"), "'Q'") && +std.assertEqual(test(alt="|Q|"), "|Q|") && + +local X = 3; +std.assertEqual((function(X=4) X)(), 4) && +std.assertEqual((function(X=4, Y=X) Y)(), 4) && + true