Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for E-expressions using simple system macros. #100

Merged
merged 2 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions conformance/eexp/arg_inlining.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Inlining of multiple return values into E-expression arguments.


(ion_1_1
toddjonker marked this conversation as resolved.
Show resolved Hide resolved
(each (toplevel ('#$:$ion:make_list' 1 2 ('#$:values') 3 4))
toddjonker marked this conversation as resolved.
Show resolved Hide resolved
(toplevel ('#$:$ion:make_list' 1 ('#$:values' 2 3) 4))
(toplevel ('#$:$ion:make_list' ('#$:values' 1 2 3 4)))
(produces [1, 2, 3, 4]))
(each (toplevel ('#$:$ion:make_sexp' 1 2 ('#$:values') 3 4))
(toplevel ('#$:$ion:make_sexp' 1 ('#$:values' 2 3) 4))
(toplevel ('#$:$ion:make_sexp' ('#$:values' 1 2 3 4)))
(produces (1 2 3 4))))
91 changes: 91 additions & 0 deletions conformance/eexp/basic_system_macros.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0


// void

(ion_1_1
(each (toplevel 1 ('#$:$ion:void') 2)
(toplevel 1 ('#$:$ion:0') 2)
(toplevel 1 ('#$:void') 2)
(produces 1 2)))

// TODO should this stay true?
(ion_1_1
(toplevel 1 ('#$:$ion:void' true ('#$:void' false)) 2)
(produces 1 2))


// values

(ion_1_1
(each (toplevel 1 ('#$:$ion:values') 2)
toddjonker marked this conversation as resolved.
Show resolved Hide resolved
(toplevel 1 ('#$:$ion:1') 2)
(toplevel 1 ('#$:values') 2)
(produces 1 2))
(each (toplevel 1 ('#$:$ion:values' a) 2)
(toplevel 1 ('#$:$ion:1' a) 2)
(toplevel 1 ('#$:values' a) 2)
(produces 1 a 2))
(each (toplevel 1 ('#$:$ion:values' a b) 2)
(toplevel 1 ('#$:$ion:1' a b) 2)
(toplevel 1 ('#$:values' a b) 2)
(produces 1 a b 2)))


// make_string

// TODO Error when argument isn't text

(ion_1_1
(each (toplevel ('#$:make_string'))
(toplevel ('#$:make_string' ""))
(toplevel ('#$:make_string' ''))
(produces ""))
// accepts both strings and symbols
(each (toplevel ('#$:make_string' "a" "b"))
(toplevel ('#$:make_string' a b ))
(toplevel ('#$:make_string' "a" b ))
(toplevel ('#$:make_string' a "b"))
(produces "ab"))
// null.string and null.symbol act like ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; does $0 also behave this way? I think I expected null arguments to be an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question, I tend to forget about $0. Heck, we also have absent symbols to deal with.

I cut amazon-ion/ion-docs#324 to deal with that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spec'd nulls to act like "" because their presence doesn't seem problematic enough to treat exceptionally. This way all (known) symbol and string values are accepted without error.

(The cases you call out are arguably encoding defects, so I think they deserve more global handling.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a bit more detail on my thought process: the typed signature of this macro would be (text::v*) and I think its preferable for it to succeed given any text value. So that would include null.string and null.symbol for sure, and $0 is technically a valid non-null symbol. All of the above have no text, so I conclude that its reasonable to accept and ignore them (which happens to be indistinguishable from treating them as "").

(each (toplevel ('#$:make_string' null.string "ab" null.symbol ""))
(toplevel ('#$:make_string' "a" null.string 'b' null.symbol))
(toplevel ('#$:make_string' null.symbol "a" null.string "b"))
(produces "ab")))


// make_symbol

// TODO Error when argument isn't text

(ion_1_1
(each (toplevel ('#$:make_symbol'))
(toplevel ('#$:make_symbol' ""))
(toplevel ('#$:make_symbol' ''))
(produces ''))
// accepts both strings and symbols
(each (toplevel ('#$:make_symbol' "a" "b"))
(toplevel ('#$:make_symbol' a b ))
(toplevel ('#$:make_symbol' "a" b ))
(toplevel ('#$:make_symbol' a "b"))
(produces 'ab'))
// null.string and null.symbol act like ""
(each (toplevel ('#$:make_symbol' null.string "ab" null.symbol ""))
(toplevel ('#$:make_symbol' "a" null.string 'b' null.symbol))
(toplevel ('#$:make_symbol' null.symbol "a" null.string "b"))
(produces 'ab')))


// make_list

(ion_1_1
(toplevel ('#$:$ion:make_list') ('#$:$ion:make_list' 1 2))
(produces [] [1, 2]))


// make_sexp

(ion_1_1
(toplevel ('#$:$ion:make_sexp') ('#$:$ion:make_sexp' 1 2))
(produces () (1 2)))
20 changes: 20 additions & 0 deletions conformance/eexp/element_inlining.ion
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

// Inlining of multiple return values into container elements.


(ion_1_1
(each (toplevel [1, 2, ('#$:values'), 3, 4])
(toplevel [1, ('#$:values' 2), ('#$:values' 3), 4])
(toplevel [1, ('#$:values' 2 3), 4])
(toplevel [('#$:values' 1 2 3 4)])
(produces [1, 2, 3, 4]))
(each (toplevel (1 2 ('#$:values') 3 4))
(toplevel (1 ('#$:values' 2) ('#$:values' 3) 4))
(toplevel (1 ('#$:values' 2 3) 4))
(toplevel ( ('#$:values' 1 2 3 4) ))
(produces (1 2 3 4))))

// TODO Inlining into structs.
// We don't have a way for `toplevel` to express things like { (:foo) }