-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds test cases for add/set_symbols and add/set_macros (#136)
--------- Co-authored-by: Zack Slayton <[email protected]> Co-authored-by: Tyler Gregg <[email protected]>
- Loading branch information
1 parent
14e8ce8
commit ca9410f
Showing
4 changed files
with
329 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 macro 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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 macro 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)))) |