From 15811a1d6de141b69157b613eb8a202dad38c3bb Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Wed, 20 Nov 2024 15:51:47 -0800 Subject: [PATCH 1/3] Adds test cases for add/set_symbols and add/set_macros --- conformance/system_macros/add_macros.ion | 90 ++++++++++++++++++++-- conformance/system_macros/add_symbols.ion | 88 ++++++++++++++++++++-- conformance/system_macros/set_macros.ion | 91 +++++++++++++++++++++-- conformance/system_macros/set_symbols.ion | 85 +++++++++++++++++++-- 4 files changed, 329 insertions(+), 25 deletions(-) diff --git a/conformance/system_macros/add_macros.ion b/conformance/system_macros/add_macros.ion index 6507bc1..b1bdd4b 100644 --- a/conformance/system_macros/add_macros.ion +++ b/conformance/system_macros/add_macros.ion @@ -1,9 +1,87 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// add_macros can be invoked using any type of macro reference. -// the argument values may be zero or more macro definitions -// add_macros does not have any side-effects on the symbol table -// add_macros should append its arguments to the macro table of the default module -// annotations on any argument value should signal an error (because it's not allowed in the macro table rather than because of any specific validation by the add_macros macro) +// TODO: add_macros can accept a module name (of a loaded module) as an argument? +// TODO: add_macros can accept a module/macro export? + +(ion_1_1 "add_macros can be invoked" + (each "in text with an unqualified macro name" + (text "(:add_macros) ") + "in text with an unqualified macro address" + (text "(:14)") + "in text with a qualified macro name" + (text "(:$ion::add_macros)") + "in text with a qualified macro address 14" + (text "(:$ion::14)") + "in binary with a system macro address 14" + (binary "EF 0E 00") + "in binary with a user macro address" + (binary "0E 00") + (produces))) + +(ion_1_1 "add_macros can add a macro to the macro table" + (text "(:add_macros (macro x () X))") + (each "and it can be invoked by name" + (text "(:x)") + "and it can be invoked by address" + (text "(:0)") + (produces X)) + (then "then add_macros can accept" + (then "an empty expression group" + (text "(:add_macros)") + (then "with no error and producing no user values" + (produces)) + (then "and does not remove any macros" + (text "(:x)") + (produces X))) + (then "a single macro" + (text "(:add_macros (macro foo () 123))") + (then "with no error and producing no user values" + (produces)) + (then "and does not remove any macros" + (text "(:x)") + (produces X)) + (each "and appends the new macro to the macro table" + (text "(:foo)") + (text "(:1)") + (produces 123))) + (then "multiple macros" + (text '''(:add_macros (macro foo () 123) + (macro null () 456) + (macro bar () 789))''') + (then "with no error and producing no user values" + (produces)) + (then "and does not remove any macros" + (text "(:x)") + (produces X)) + (each "and appends the new macros to the macro table" + (text "(:foo) (:2) (:bar)") + (text "(:1) (:2) (:3)") + (produces 123 456 789))))) + +(ion_1_1 "add_macros does not accept" + (each "nulls" + (text "(:add_macros null)") + (text "(:add_macros null.symbol)") + (text "(:add_macros null.sexp)") + "invalid macro definitions" + (text "(:add_macros a::(macro foo () 123))") + (text "(:add_macros (macro $0 () 123))") + (text "(:add_macros ( foo () 123))") + (text "(:add_macros (macro () 123))") + (text "(:add_macros (macro foo 123))") + (text "(:add_macros (macro foo () ))") + (signals "invalid argument"))) + +(ion_1_1 "add_macros does not have any side-effects on the symbol table" + (text "(:set_symbols a b c)") + (then "[PRECONDITION] symbols are set as expected" + (then (toplevel '#$1' '#$2' '#$3') (produces a b c)) + (then (toplevel '#$4') (signals "invalid SID"))) + (each (text "(:add_macros)") + (text "(:add_macros (macro a () 123))") + (text "(:add_macros (macro a () 123) (macro b () 456))") + (then "no symbols are removed" + (toplevel '#$1' '#$2' '#$3') (produces a b c)) + (then "no symbols are added" + (toplevel '#$4') (signals "invalid SID")))) diff --git a/conformance/system_macros/add_symbols.ion b/conformance/system_macros/add_symbols.ion index f5667f5..fc775d9 100644 --- a/conformance/system_macros/add_symbols.ion +++ b/conformance/system_macros/add_symbols.ion @@ -1,9 +1,85 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// add_symbols can be invoked using any type of macro reference. -// the argument values may be zero or more non-null text values -// add_symbols does not have any side-effects on the macro table -// add_symbols should append its arguments to the symbol table of the default module -// annotations on any argument value should signal an error (because it's not allowed in the symbol table rather than because of any specific validation by the add_symbols macro) +(ion_1_1 "add_symbols can be invoked" + (each "in text with an unqualified macro name" + (text ''' (:add_symbols "") ''') + "in text with an unqualified macro address" + (text ''' (:12 "") ''') + "in text with a qualified macro name" + (text ''' (:$ion::add_symbols "") ''') + "in text with a qualified macro address 12" + (text ''' (:$ion::12 "") ''') + "in binary with a system macro address 12" + (binary "EF 0C 01 90") + "in binary with a user macro address" + (binary "0C 01 90") + (then "and produces only system values" + (produces)) + (then "and affects the symbol table" + (toplevel '#$1' '#$65' '#$66') + (produces '$ion' 'make_field' '')))) + +(ion_1_1 "add_symbols can accept" + (then "an empty expression group" + (text "(:add_symbols)") + (then "with no error and producing no user values" + (produces)) + (then "and does not remove any symbols" + (toplevel '#$1' '#$65') + (produces '$ion' 'make_field')) + (then "and does not add any symbols" + (toplevel '#$66') + (signals "invalid symbol id"))) + (each "a single string" + (text "(:add_symbols '''a''')") + "a single symbol" + (text "(:add_symbols 'a')") + (then "with no error and producing no user values" + (produces)) + (then "and does not remove any symbols" + (toplevel '#$1' '#$65') + (produces '$ion' 'make_field')) + (then "and appends the new symbol to the symbol table" + (toplevel '#$66') + (produces 'a'))) + (each "multiple strings" + (text ''' (:add_symbols "a" "b" "c") ''') + "multiple symbols" + (text ''' (:add_symbols 'a' 'b' 'c') ''') + "a mix of strings and symbols" + (text ''' (:add_symbols 'a' "b" 'c') ''') + (then "with no error and producing no user values" + (produces)) + (then "and does not remove any symbols" + (toplevel '#$1' '#$65') + (produces '$ion' 'make_field')) + (then "and appends the new symbols to the symbol table" + (toplevel '#$66' '#$67' '#$68') + (produces 'a' 'b' 'c')))) + +(ion_1_1 "add_symbols does not accept" + (each "null" + (text "(:add_symbols null)") + "null.symbol" + (text "(:add_symbols null.symbol)") + "null.string" + (text "(:add_symbols null.string)") + "annotated arguments" // because of the symbol table syntax rather than any specific restriction of this macro + (text "(:add_symbols a::b)") + "symbols with unknown text and sid >0" + (text "(:add_symbols $256)") + (signals "invalid argument"))) + +(ion_1_1 "add_symbols does not have any side-effects on the symbol table" + (text "(:set_macros (macro x () X))") + (then "[PRECONDITION] macros are set as expected" + (text "(:x) (:0)") + (produces X X)) + (each (text "(:$ion::add_symbols)") + (text "(:$ion::add_symbols 'a')") + (text "(:$ion::add_symbols 'a' 'b')") + // TODO: If it's not too difficult, assert that no macros are added + (then "no macros are removed" + (text "(:x) (:0)") + (produces X X)))) diff --git a/conformance/system_macros/set_macros.ion b/conformance/system_macros/set_macros.ion index a9269d0..8b65872 100644 --- a/conformance/system_macros/set_macros.ion +++ b/conformance/system_macros/set_macros.ion @@ -1,10 +1,87 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// set_macros can be invoked using any type of macro reference. -// the argument values may be zero or more macro definitions -// TODO: Could it also be a module or an export? -// set_macros does not have any side-effects on the symbol table -// set_macros replaces the current macro table with a new macro table that consists of the arguments of set_macros -// annotations on any argument value should signal an error (because it's not allowed in the macro table rather than because of any specific validation by the set_macros macro) +// TODO: set_macros can accept a module name (of a loaded module) as an argument? +// TODO: set_macros can accept a module/macro export? + +(ion_1_1 "set_macros can be invoked" + (each "in text with an unqualified macro name" + (text "(:set_macros) ") + "in text with an unqualified macro address" + (text "(:13)") + "in text with a qualified macro name" + (text "(:$ion::set_macros)") + "in text with a qualified macro address 13" + (text "(:$ion::13)") + "in binary with a system macro address 13" + (binary "EF 0D 00") + "in binary with a user macro address" + (binary "0D 00") + (produces))) + +(ion_1_1 "set_macros can be invoked with a single macro" + (text "(:set_macros (macro x () X))") + (each "which can be invoked by name" + (text "(:x)") + "which can be invoked by address" + (text "(:0)") + (produces X)) + (then "then set_macros can accept" + (then "an empty expression group" + (text "(:$ion::set_macros)") + (then "with no error and producing no user values" + (produces)) + (then "and it removes existing macros" + (text "(:x)") + (signals "unknown macro"))) + (then "a single macro" + (text "(:$ion::set_macros (macro foo () 123))") + (then "with no error and producing no user values" + (produces)) + (then "and it removes existing macros" + (text "(:x)") + (signals "unknown macro")) + (each "and it sets macro table with the new macro" + (text "(:foo)") + (text "(:0)") + (produces 123))) + (then "multiple macros" + (text '''(:$ion::set_macros (macro foo () 123) + (macro null () 456) + (macro bar () 789))''') + (then "with no error and producing no user values" + (produces)) + (then "and it removes existing macros" + (text "(:x)") + (signals "unknown macro")) + (each "and it sets macro table with the new macros" + (text "(:foo) (:1) (:bar)") + (text "(:0) (:1) (:2)") + (produces 123 456 789))))) + +(ion_1_1 "set_macros does not accept" + (each "nulls" + (text "(:set_macros null)") + (text "(:set_macros null.symbol)") + (text "(:set_macros null.sexp)") + "invalid macro definitions" + (text "(:set_macros a::(macro foo () 123))") + (text "(:set_macros (macro $0 () 123))") + (text "(:set_macros ( foo () 123))") + (text "(:set_macros (macro () 123))") + (text "(:set_macros (macro foo 123))") + (text "(:set_macros (macro foo () ))") + (signals "invalid argument"))) + +(ion_1_1 "set_macros does not have any side-effects on the symbol table" + (text "(:set_symbols a b c)") + (then "[PRECONDITION] symbols are set as expected" + (then (toplevel '#$1' '#$2' '#$3') (produces a b c)) + (then (toplevel '#$4') (signals "invalid SID"))) + (each (text "(:set_macros)") + (text "(:set_macros (macro a () 123))") + (text "(:set_macros (macro a () 123) (macro b () 456))") + (then "no symbols are removed" + (toplevel '#$1' '#$2' '#$3') (produces a b c)) + (then "no symbols are added" + (toplevel '#$4') (signals "invalid SID")))) diff --git a/conformance/system_macros/set_symbols.ion b/conformance/system_macros/set_symbols.ion index 57748d7..8c97de0 100644 --- a/conformance/system_macros/set_symbols.ion +++ b/conformance/system_macros/set_symbols.ion @@ -1,9 +1,82 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -// Test Cases: -// set_symbols can be invoked using any type of macro reference. -// the argument values may be zero or more non-null text values -// set_symbols does not have any side-effects on the macro table -// set_symbols replaces the current symbol table with a new symbol table that consists of the arguments of set_symbols -// annotations on any argument value should signal an error (because it's not allowed in the symbol table rather than because of any specific validation by the set_symbols macro) +(ion_1_1 "set_symbols can be invoked" + (each "in text with an unqualified macro name" + (text ''' (:set_symbols "") ''') + "in text with an unqualified macro address" + (text ''' (:11 "") ''') + "in text with a qualified macro name" + (text ''' (:$ion::set_symbols "") ''') + "in text with a qualified macro address 11" + (text ''' (:$ion::11 "") ''') + "in binary with a system macro address 11" + (binary "EF 0B 01 90") + "in binary with a user macro address" + (binary "0B 01 90") + (then "and produces only system values" + (produces)) + (then "and affects the symbol table" + (toplevel '#$1') + (produces '')))) + +(ion_1_1 "set_symbols can accept" + (then "an empty expression group" + (text "(:set_symbols)") + (then "with no error and producing no user values" + (produces)) + (then "and clears the symbol table" + (toplevel '#$1') + (signals "invalid symbol id"))) + (each "a single string" + (text "(:set_symbols '''a''')") + "a single symbol" + (text "(:set_symbols 'a')") + (then "with no error and producing no user values" + (produces)) + (then "and sets the symbol table" + (toplevel '#$1') + (produces 'a')) + (then "and clears any existing symbols" + (toplevel '#$2') + (signals "invalid symbol id"))) + (each "multiple strings" + (text ''' (:set_symbols "a" "b" "c") ''') + "multiple symbols" + (text ''' (:set_symbols 'a' 'b' 'c') ''') + "a mix of strings and symbols" + (text ''' (:set_symbols 'a' "b" 'c') ''') + (then "with no error and producing no user values" + (produces)) + (then "and sets the symbol table" + (toplevel '#$1' '#$2' '#$3') + (produces 'a' 'b' 'c')) + (then "and clears any existing symbols" + (toplevel '#$4') + (signals "invalid symbol id")))) + +(ion_1_1 "set_symbols does not accept" + (each "null" + (text "(:set_symbols null)") + "null.symbol" + (text "(:set_symbols null.symbol)") + "null.string" + (text "(:set_symbols null.string)") + "annotated arguments" // because of the symbol table syntax rather than any specific restriction of this macro + (text "(:set_symbols a::b)") + "symbols with unknown text and sid >0" + (text "(:set_symbols $256)") + (signals "invalid argument"))) + +(ion_1_1 "set_symbols does not have any side-effects on the symbol table" + (text "(:set_macros (macro x () X))") + (then "[PRECONDITION] macros are set as expected" + (text "(:x) (:0)") + (produces X X)) + (each (text "(:$ion::set_symbols)") + (text "(:$ion::set_symbols 'a')") + (text "(:$ion::set_symbols 'a' 'b')") + // TODO: If it's not too difficult, assert that no macros are added + (then "no macros are removed" + (text "(:x) (:0)") + (produces X X)))) From 852f8ce84e350bc000a86bb9a8f0458c0a14383e Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:13:58 -0800 Subject: [PATCH 2/3] Update conformance/system_macros/add_symbols.ion Co-authored-by: Zack Slayton --- conformance/system_macros/add_symbols.ion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conformance/system_macros/add_symbols.ion b/conformance/system_macros/add_symbols.ion index fc775d9..ca00de8 100644 --- a/conformance/system_macros/add_symbols.ion +++ b/conformance/system_macros/add_symbols.ion @@ -71,7 +71,7 @@ (text "(:add_symbols $256)") (signals "invalid argument"))) -(ion_1_1 "add_symbols does not have any side-effects on the symbol table" +(ion_1_1 "add_symbols does not have any side-effects on the macro table" (text "(:set_macros (macro x () X))") (then "[PRECONDITION] macros are set as expected" (text "(:x) (:0)") From 17b87275845b9c63c06fc3b013edc338a2386345 Mon Sep 17 00:00:00 2001 From: Matthew Pope <81593196+popematt@users.noreply.github.com> Date: Thu, 21 Nov 2024 15:15:47 -0800 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Tyler Gregg Co-authored-by: Zack Slayton --- conformance/system_macros/add_macros.ion | 2 +- conformance/system_macros/set_macros.ion | 2 +- conformance/system_macros/set_symbols.ion | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/conformance/system_macros/add_macros.ion b/conformance/system_macros/add_macros.ion index b1bdd4b..1d5d8d7 100644 --- a/conformance/system_macros/add_macros.ion +++ b/conformance/system_macros/add_macros.ion @@ -28,7 +28,7 @@ (produces X)) (then "then add_macros can accept" (then "an empty expression group" - (text "(:add_macros)") + (text "(:add_macros (::))") (then "with no error and producing no user values" (produces)) (then "and does not remove any macros" diff --git a/conformance/system_macros/set_macros.ion b/conformance/system_macros/set_macros.ion index 8b65872..e48b8b1 100644 --- a/conformance/system_macros/set_macros.ion +++ b/conformance/system_macros/set_macros.ion @@ -28,7 +28,7 @@ (produces X)) (then "then set_macros can accept" (then "an empty expression group" - (text "(:$ion::set_macros)") + (text "(:$ion::set_macros (::))") (then "with no error and producing no user values" (produces)) (then "and it removes existing macros" diff --git a/conformance/system_macros/set_symbols.ion b/conformance/system_macros/set_symbols.ion index 8c97de0..67f8b6f 100644 --- a/conformance/system_macros/set_symbols.ion +++ b/conformance/system_macros/set_symbols.ion @@ -22,7 +22,7 @@ (ion_1_1 "set_symbols can accept" (then "an empty expression group" - (text "(:set_symbols)") + (text "(:set_symbols (::))") (then "with no error and producing no user values" (produces)) (then "and clears the symbol table" @@ -68,7 +68,7 @@ (text "(:set_symbols $256)") (signals "invalid argument"))) -(ion_1_1 "set_symbols does not have any side-effects on the symbol table" +(ion_1_1 "set_symbols does not have any side-effects on the macro table" (text "(:set_macros (macro x () X))") (then "[PRECONDITION] macros are set as expected" (text "(:x) (:0)")