From 1f32d70008448c607edb8c14265182dee2490bf3 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Thu, 14 Nov 2024 17:42:51 -0800 Subject: [PATCH 1/4] Adds conformance tests cases for values, none, meta, default, and repeat --- conformance/system_macros/default.ion | 88 ++++++++++++++++++++++++--- conformance/system_macros/meta.ion | 39 +++++++++++- conformance/system_macros/none.ion | 27 +++++++- conformance/system_macros/repeat.ion | 64 +++++++++++++++++-- conformance/system_macros/values.ion | 40 +++++++++++- 5 files changed, 237 insertions(+), 21 deletions(-) diff --git a/conformance/system_macros/default.ion b/conformance/system_macros/default.ion index b0a1c16..1d3cd4d 100644 --- a/conformance/system_macros/default.ion +++ b/conformance/system_macros/default.ion @@ -1,10 +1,84 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// default can be invoked using any type of macro reference. -// both arguments may be any expression or expression group -// if the first argument is non-empty -// - `default` produces the first argument as its result -// - the second argument is not expanded -// if the first argument is empty (i.e. none), `default` produces the second argument as its result +(ion_1_1 "default can be invoked" + (each "in text with an unqualified macro name" + (text " (:default 0 1) ") + "in text with an unqualified macro address" + (text " (:23 0 1) ") + "in text with a qualified macro name" + (text " (:$ion::default 0 1) ") + "in text using qualified system macro address 23" + (text " (:$ion::23 0 1) ") + "in binary using system macro address 23" + (binary "EF 17 05 60 61 01") + "in binary with a user macro address" + (binary "17 05 60 61 01") + (produces 0))) + +(ion_1_1 "default produces" + (each "the first argument when the first argument is a single value" + (text " (:default 1 0) ") + "the second argument when the first argument is empty" + (text " (:default (::) 1) ") + (produces 1)) + (then "nothing when both argument are empty" + (text "(:default)") + (produces /*nothing*/))) + +(ion_1_1 "when the first argument is non-empty, the second argument is not expanded" + // none with any argument should signal an error _iff_ it is evaluated + (text "(:default 1 (:none 123))") + (produces 1)) + +(ion_1_1 "the first argument can be" + (then "a single value" + (text "(:default (::) 1)") + (produces 1)) + (then "an empty expression group" + (text "(:default (::) (::))") + (produces /*nothing*/)) + (then "an expression group with a single value" + (text "(:default (:: 1) (::))") + (produces 1)) + (then "an expression group with multiple values" + (text "(:default (:: 1 2 3) (::))") + (produces 1 2 3)) + (then "an expression that produces nothing" + (text "(:default (:values) (::))") + (produces /*nothing*/)) + (then "an expression that produces a single value" + (text "(:default (:values 1) (::))") + (produces 1)) + (then "an expression that produces multiple values" + (text "(:default (:values 1 2 3) (::))") + (produces 1 2 3))) + +(ion_1_1 "the second argument can be" + (then "nothing" + (text "(:default (::))") + (produces /*nothing*/)) + (then "a single value" + (text "(:default (::) 1)") + (produces 1)) + (then "multiple values" + (text "(:default (::) 1 2 3)") + (produces 1 2 3)) + (then "an empty expression group" + (text "(:default (::) (::))") + (produces /*nothing*/)) + (then "an expression group with a single value" + (text "(:default (::) (:: 1))") + (produces 1)) + (then "an expression group with multiple values" + (text "(:default (::) (:: 1 2 3))") + (produces 1 2 3)) + (then "an expression that produces nothing" + (text "(:default (::) (:values))") + (produces /*nothing*/)) + (then "an expression that produces a single value" + (text "(:default (::) (:values 1))") + (produces 1)) + (then "an expression that produces multiple values" + (text "(:default (::) (:values 1 2 3))") + (produces 1 2 3))) diff --git a/conformance/system_macros/meta.ion b/conformance/system_macros/meta.ion index 30302df..67f1648 100644 --- a/conformance/system_macros/meta.ion +++ b/conformance/system_macros/meta.ion @@ -1,6 +1,39 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// meta can be invoked using any type of macro reference. -// meta has one parameter that accepts zero-to-many argument expressions and always produces nothing +// This covers _all_ happy cases because there are no arguments and there is no output. +(ion_1_1 "meta can be invoked" + (each "in text with an unqualified macro name" + (text " (:meta) ") + "in text with an unqualified macro address" + (text " (:21) ") + "in text with a qualified macro name" + (text " (:$ion::meta) ") + "in text using qualified system macro address 21" + (text " (:$ion::21) ") + "in binary using system macro address 21" + (binary "EF 15 00") + "in binary with a user macro address" + (binary "15 00") + (produces /*nothing*/))) + +(ion_1_1 "meta produces nothing when its argument is" + (each "no values" + (text "(:meta)") + "a single value" + (text "(:meta 0)") + "multiple values" + (text "(:meta 1 2 3)") + "passed an empty expression group" + (text "(:meta (::))") + "passed an expression group with one value" + (text "(:meta (:: 0))") + "passed an expression group with multiple values" + (text "(:meta (:: 1 2 3))") + "passed an expression that produces nothing" + (text "(:meta (:meta))") + "passed an expression that produces one value" + (text "(:meta (:values 0))") + "passed an expression that produces multiple values" + (text "(:meta (:values 1 2 3))") + (produces /*nothing*/))) diff --git a/conformance/system_macros/none.ion b/conformance/system_macros/none.ion index 61a4d8f..a0bbdf1 100644 --- a/conformance/system_macros/none.ion +++ b/conformance/system_macros/none.ion @@ -1,6 +1,27 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// none can be invoked using any type of macro reference. -// none accepts no arguments and produces nothing +// This covers _all_ happy cases because there are no arguments and there is no output. +(ion_1_1 "none can be invoked" + (each "in text with an unqualified macro name" + (text " (:none) ") + "in text with an unqualified macro address" + (text " (:0) ") + "in text with a qualified macro name" + (text " (:$ion::none) ") + "in text using qualified system macro address 0" + (text " (:$ion::0) ") + "in binary using system macro address 0" + (binary "EF 00") + "in binary with a user macro address" + (binary "00") + (produces /*nothing*/))) + +(ion_1_1 "none signals an error when" + (each "passed any expression value" + (text "(:none 0)") + "passed an empty expression group" + (text "(:none (::))") + "passed an expression that produces nothing" + (text "(:none (:none))") + (signals "unexpected argument"))) diff --git a/conformance/system_macros/repeat.ion b/conformance/system_macros/repeat.ion index cd9bc0b..bfc29d6 100644 --- a/conformance/system_macros/repeat.ion +++ b/conformance/system_macros/repeat.ion @@ -1,8 +1,62 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// repeat can be invoked using any type of macro reference. -// repeat can repeat things the correct number of times -// the number of repetitions must be a single expression that expands to one positive integer (i.e. an integer greater than zero) -// the thing to be repeated must be at least one expression of any type +(ion_1_1 "repeat can be invoked" + (each "in text with an unqualified macro name" + (text ''' (:repeat 1 1) ''') + "in text with an unqualified macro address" + (text ''' (:17 1 1) ''') + "in text with a qualified macro name" + (text ''' (:$ion::repeat 1 1) ''') + "in text with a qualified macro address" + (text ''' (:$ion::17 1 1) ''') + "in binary with a system macro address" + (binary "EF 11 01 61 01 61 01") + "in binary with a user macro address" + (binary "11 01 61 01 61 01") + (produces 1))) + +(ion_1_1 "repeat will repeat things the correct number of times" + (then (text "(:repeat 1 0)") (produces 0)) + (then (text "(:repeat 2 0)") (produces 0 0)) + (then (text "(:repeat 3 0)") (produces 0 0 0)) + (then (text "(:repeat 4 0)") (produces 0 0 0 0)) + (then (text "(:repeat 5 0)") (produces 0 0 0 0 0))) + +(ion_1_1 "repeat will ignore any annotations on the number of repetitions" + (then (text "(:repeat a::1 0)") (produces 0)) + (then (text "(:repeat b::2 0)") (produces 0 0)) + (then (text "(:repeat c::3 0)") (produces 0 0 0)) + (then (text "(:repeat d::4 0)") (produces 0 0 0 0)) + (then (text "(:repeat e::5 0)") (produces 0 0 0 0 0))) + +(ion_1_1 "repeat can repeat an expression group with multiple values" + (then (text "(:repeat 1 (:: 0 1))") (produces 0 1)) + (then (text "(:repeat 2 (:: 0 1))") (produces 0 1 0 1)) + (then (text "(:repeat 3 (:: 0 1))") (produces 0 1 0 1 0 1)) + (then (text "(:repeat 4 (:: 0 1))") (produces 0 1 0 1 0 1 0 1))) + +(ion_1_1 "repeat can repeat an expression that produces multiple values" + (then (text "(:repeat 1 (:values 0 1))") (produces 0 1)) + (then (text "(:repeat 2 (:values 0 1))") (produces 0 1 0 1)) + (then (text "(:repeat 3 (:values 0 1))") (produces 0 1 0 1 0 1)) + (then (text "(:repeat 4 (:values 0 1))") (produces 0 1 0 1 0 1 0 1))) + +(ion_1_1 "repeat signals an error when" + (each "the number of repeats is not an integer" + (text "(:repeat 1d0 0)") + (text "(:repeat 1e1 0)") + (text "(:repeat false 0)") + "the number of repeats is multiple values" + (text "(:repeat (:: 1 2) 0)") + "the number of repeats an expression the produces multiple values" + (text "(:repeat (:values 1 2) 0)") + "the number of repeats is negative" + (text "(:repeat -1 0)") + "the number of repeats is 0" + (text "(:repeat 0 0)") + "the expression to be repeated is empty" + (text "(:repeat 1)") + (text "(:repeat 1 (::))") + (text "(:repeat 1 (:none))") + (signals "invalid argument"))) diff --git a/conformance/system_macros/values.ion b/conformance/system_macros/values.ion index 128f674..8118b7a 100644 --- a/conformance/system_macros/values.ion +++ b/conformance/system_macros/values.ion @@ -1,6 +1,40 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// values can be invoked using any type of macro reference. -// values has one parameter that accept zero-to-many arguments and produces its input +(ion_1_1 "values can be invoked" + (each "in text with an unqualified macro name" + (text ''' (:values 0) ''') + "in text with an unqualified macro address" + (text ''' (:1 0) ''') + "in text with a qualified macro name" + (text ''' (:$ion::values 0) ''') + "in text with a qualified macro address" + (text ''' (:$ion::1 0) ''') + "in binary with a system macro address" + (binary "EF 01 01 60") + "in binary with a user macro address" + (binary "01 01 60") + (produces 0))) + +(ion_1_1 "values produces its input when its argument" + (each "is elided" + (text " (:values)") + "is an empty expression group" + (text " (:values (::))") + "is an expression that evaluates to nothing" + (text " (:values (:values))") + (produces /*nothing*/)) + (each "is a single value" + (text " (:values 0)") + "is an expression that evaluates to a single value" + (text " (:values (:values 0))") + "is an expression group with one value" + (text " (:values (:: 0))") + (produces 0)) + (each "is multiple values" + (text " (:values 1 2 3)") + "is a single expression that evaluates to multiple values" + (text " (:values (:values 1 2 3))") + "is an expression containing multiple values" + (text " (:values (:: 1 2 3))") + (produces 1 2 3))) From cd0228f0b5881c0ba199ef13e102fa84c57aedf4 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Thu, 14 Nov 2024 17:43:32 -0800 Subject: [PATCH 2/4] Make the github workflow run for all branches --- .github/workflows/main.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0483fb8..6901cae 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -3,12 +3,6 @@ name: "Validate Conformance Test Syntax" on: push: pull_request: - branches: - # Branches from forks have the form 'user:branch-name' so we only run this job on pull_request events for - # branches that look like fork branches. Without this we would end up running this job twice for non-forked - # PRs, once for the push and then once for opening the PR. - # Taken from https://github.community/t/how-to-trigger-an-action-on-push-or-pull-request-but-not-both/16662/10 - - '**:**' jobs: check-conformance-test-syntax: From a28f91ac92f11af693eabc867ce7e5c4c7636f02 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Fri, 15 Nov 2024 10:28:55 -0800 Subject: [PATCH 3/4] Adds suggested changes --- conformance/system_macros/default.ion | 8 ++-- conformance/system_macros/repeat.ion | 58 ++++++++++++++++----------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/conformance/system_macros/default.ion b/conformance/system_macros/default.ion index 1d3cd4d..4e86e06 100644 --- a/conformance/system_macros/default.ion +++ b/conformance/system_macros/default.ion @@ -47,10 +47,10 @@ (then "an expression that produces nothing" (text "(:default (:values) (::))") (produces /*nothing*/)) - (then "an expression that produces a single value" + (then "an expression that produces a single value" (text "(:default (:values 1) (::))") (produces 1)) - (then "an expression that produces multiple values" + (then "an expression that produces multiple values" (text "(:default (:values 1 2 3) (::))") (produces 1 2 3))) @@ -76,9 +76,9 @@ (then "an expression that produces nothing" (text "(:default (::) (:values))") (produces /*nothing*/)) - (then "an expression that produces a single value" + (then "an expression that produces a single value" (text "(:default (::) (:values 1))") (produces 1)) - (then "an expression that produces multiple values" + (then "an expression that produces multiple values" (text "(:default (::) (:values 1 2 3))") (produces 1 2 3))) diff --git a/conformance/system_macros/repeat.ion b/conformance/system_macros/repeat.ion index bfc29d6..90e14f4 100644 --- a/conformance/system_macros/repeat.ion +++ b/conformance/system_macros/repeat.ion @@ -16,12 +16,40 @@ (binary "11 01 61 01 61 01") (produces 1))) -(ion_1_1 "repeat will repeat things the correct number of times" - (then (text "(:repeat 1 0)") (produces 0)) - (then (text "(:repeat 2 0)") (produces 0 0)) - (then (text "(:repeat 3 0)") (produces 0 0 0)) - (then (text "(:repeat 4 0)") (produces 0 0 0 0)) - (then (text "(:repeat 5 0)") (produces 0 0 0 0 0))) +(ion_1_1 "repeat can produce" + (then "a single expression" + (then "0 times" (text "(:repeat 0 0)") (produces)) + (then "1 times" (text "(:repeat 1 0)") (produces 0)) + (then "2 times" (text "(:repeat 2 0)") (produces 0 0)) + (then "3 times" (text "(:repeat 3 0)") (produces 0 0 0)) + (then "4 times" (text "(:repeat 4 0)") (produces 0 0 0 0)) + (then "5 times" (text "(:repeat 5 0)") (produces 0 0 0 0 0))) + (then "an empty expression group" + (each (text "(:repeat 0 (::))") + (text "(:repeat 1 (::))") + (text "(:repeat 2 (::))") + (text "(:repeat 3 (::))") + (text "(:repeat 4 (::))") + (produces /*nothing*/ ))) + (then "an expression that produces no values" + (each (text "(:repeat 0 (:none))") + (text "(:repeat 1 (:none))") + (text "(:repeat 2 (:none))") + (text "(:repeat 3 (:none))") + (text "(:repeat 4 (:none))") + (produces /*nothing*/ ))) + (then "an expression group with multiple values" + (then "0 times" (text "(:repeat 0 (:: 0 1))") (produces)) + (then "1 times" (text "(:repeat 1 (:: 0 1))") (produces 0 1)) + (then "2 times" (text "(:repeat 2 (:: 0 1))") (produces 0 1 0 1)) + (then "3 times" (text "(:repeat 3 (:: 0 1))") (produces 0 1 0 1 0 1)) + (then "4 times" (text "(:repeat 4 (:: 0 1))") (produces 0 1 0 1 0 1 0 1))) + (then "an expression that produces multiple values" + (then "0 times" (text "(:repeat 0 (:values 0 1))") (produces)) + (then "1 times" (text "(:repeat 1 (:values 0 1))") (produces 0 1)) + (then "2 times" (text "(:repeat 2 (:values 0 1))") (produces 0 1 0 1)) + (then "3 times" (text "(:repeat 3 (:values 0 1))") (produces 0 1 0 1 0 1)) + (then "4 times" (text "(:repeat 4 (:values 0 1))") (produces 0 1 0 1 0 1 0 1))) ) (ion_1_1 "repeat will ignore any annotations on the number of repetitions" (then (text "(:repeat a::1 0)") (produces 0)) @@ -30,18 +58,6 @@ (then (text "(:repeat d::4 0)") (produces 0 0 0 0)) (then (text "(:repeat e::5 0)") (produces 0 0 0 0 0))) -(ion_1_1 "repeat can repeat an expression group with multiple values" - (then (text "(:repeat 1 (:: 0 1))") (produces 0 1)) - (then (text "(:repeat 2 (:: 0 1))") (produces 0 1 0 1)) - (then (text "(:repeat 3 (:: 0 1))") (produces 0 1 0 1 0 1)) - (then (text "(:repeat 4 (:: 0 1))") (produces 0 1 0 1 0 1 0 1))) - -(ion_1_1 "repeat can repeat an expression that produces multiple values" - (then (text "(:repeat 1 (:values 0 1))") (produces 0 1)) - (then (text "(:repeat 2 (:values 0 1))") (produces 0 1 0 1)) - (then (text "(:repeat 3 (:values 0 1))") (produces 0 1 0 1 0 1)) - (then (text "(:repeat 4 (:values 0 1))") (produces 0 1 0 1 0 1 0 1))) - (ion_1_1 "repeat signals an error when" (each "the number of repeats is not an integer" (text "(:repeat 1d0 0)") @@ -53,10 +69,4 @@ (text "(:repeat (:values 1 2) 0)") "the number of repeats is negative" (text "(:repeat -1 0)") - "the number of repeats is 0" - (text "(:repeat 0 0)") - "the expression to be repeated is empty" - (text "(:repeat 1)") - (text "(:repeat 1 (::))") - (text "(:repeat 1 (:none))") (signals "invalid argument"))) From 088e2f215ee990b7e834aa2aaaf5af8400d47e90 Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Mon, 18 Nov 2024 17:19:34 -0800 Subject: [PATCH 4/4] Update conformance/system_macros/default.ion --- conformance/system_macros/default.ion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conformance/system_macros/default.ion b/conformance/system_macros/default.ion index 4e86e06..326e700 100644 --- a/conformance/system_macros/default.ion +++ b/conformance/system_macros/default.ion @@ -33,7 +33,7 @@ (ion_1_1 "the first argument can be" (then "a single value" - (text "(:default (::) 1)") + (text "(:default 1 (::))") (produces 1)) (then "an empty expression group" (text "(:default (::) (::))")