From a0acfb4d086cc2b4cd83c54c7896b34181dfaaf1 Mon Sep 17 00:00:00 2001 From: Matthew Pope Date: Thu, 14 Nov 2024 13:29:40 -0800 Subject: [PATCH] Adds data model conformance tests for nulls and booleans --- conformance/core/typed_null.ion | 20 ------ conformance/data_model/annotations.ion | 48 +++++++++++++++ conformance/data_model/boolean.ion | 40 ++++++++++++ conformance/data_model/null.ion | 85 ++++++++++++++++++++++++++ conformance/null.ion | 7 --- 5 files changed, 173 insertions(+), 27 deletions(-) delete mode 100644 conformance/core/typed_null.ion create mode 100644 conformance/data_model/annotations.ion create mode 100644 conformance/data_model/boolean.ion create mode 100644 conformance/data_model/null.ion delete mode 100644 conformance/null.ion diff --git a/conformance/core/typed_null.ion b/conformance/core/typed_null.ion deleted file mode 100644 index 46a5d2c..0000000 --- a/conformance/core/typed_null.ion +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - - -// TODO Add text/binary inputs - -(ion_1_x "Null denotations" - (then (toplevel null.blob ) (denotes (Null blob ))) - (then (toplevel null.bool ) (denotes (Null bool ))) - (then (toplevel null.clob ) (denotes (Null clob ))) - (then (toplevel null.decimal ) (denotes (Null decimal ))) - (then (toplevel null.float ) (denotes (Null float ))) - (then (toplevel null.int ) (denotes (Null int ))) - (then (toplevel null.list ) (denotes (Null list ))) - (then (toplevel null.null ) (denotes (Null ))) - (then (toplevel null.sexp ) (denotes (Null sexp ))) - (then (toplevel null.string ) (denotes (Null string ))) - (then (toplevel null.struct ) (denotes (Null struct ))) - (then (toplevel null.symbol ) (denotes (Null symbol ))) - (then (toplevel null.timestamp) (denotes (Null timestamp)))) diff --git a/conformance/data_model/annotations.ion b/conformance/data_model/annotations.ion new file mode 100644 index 0000000..3c6d507 --- /dev/null +++ b/conformance/data_model/annotations.ion @@ -0,0 +1,48 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +// TODO: +// * Ion 1.0 binary annotations +// * In Ion 1.1 binary, +// * SID annotations +// * FlexSym annotations (inline, SID, and system symbols) +// * In text (any version) +// * Text Annotations (quoted and unquoted, including quoted keywords) +// * Text SID Annotations +// * non-symbols cannot be used as annotations +// * specifically, annotations must be single quoted if they are quoted +// * operator symbols must be quoted to be used as an annotation, even in s-expressions +// * dangling annotations must signal an error +// * In binary (any version) +// * Annotations cannot be applied to NOP +// * In all encodings +// * Any number of annotations is allowed (in any encoding) +// * Annotations can be applied to any type of value (all prior tests should be annotating a small integer) +// +// Less common scenarios: +// * Add a test case with multiple values that are annotated to help ensure that there's +// no leaking annotation state between values + +(ion_1_x "in text, unquoted keywords cannot be used as an annotation" + (each (text "true::0") + (text "false::0") + (text "null::0") + (text "null.null::0") + (text "null.bool::0") + (text "null.int::0") + (text "null.float::0") + (text "null.decimal::0") + (text "null.timestamp::0") + (text "null.string::0") + (text "null.symbol::0") + (text "null.blob::0") + (text "null.clob::0") + (text "null.list::0") + (text "null.sexp::0") + (text "null.struct::0") + (text "nan::0") + (text "+inf::0") + (text "-inf::0") + // For some implementations, this could also fail because it reads a value and + // then sees "::" with no preceding symbol token. + (signals "cannot use unquoted keyword as an annotation"))) diff --git a/conformance/data_model/boolean.ion b/conformance/data_model/boolean.ion new file mode 100644 index 0000000..865f168 --- /dev/null +++ b/conformance/data_model/boolean.ion @@ -0,0 +1,40 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +(document "the boolean value false" + (each "in Ion 1.0 binary" + (binary "E0 01 00 EA 10") + "in Ion 1.0 text" + (text "false") + "in Ion 1.1 binary" + (binary "E0 01 01 EA 6F") + "in Ion 1.1 text" + (text "$ion_1_1 false") + (denotes false))) + +(document "the boolean value true" + (each "in Ion 1.0 binary" + (binary "E0 01 00 EA 11") + "in Ion 1.0 text" + (text "true") + "in Ion 1.1 binary" + (binary "E0 01 01 EA 6E") + "in Ion 1.1 text" + (text "$ion_1_1 true") + (denotes true))) + +(ion_1_0 "in Ion 1.0 binary, the boolean type id lower nibble may not be 2..E (inclusive)" + (each (binary 0x12) + (binary 0x13) + (binary 0x14) + (binary 0x15) + (binary 0x16) + (binary 0x17) + (binary 0x18) + (binary 0x19) + (binary 0x1A) + (binary 0x1B) + (binary 0x1C) + (binary 0x1D) + (binary 0x1E) + (signals "illegal type descriptor"))) diff --git a/conformance/data_model/null.ion b/conformance/data_model/null.ion new file mode 100644 index 0000000..3fdc8a0 --- /dev/null +++ b/conformance/data_model/null.ion @@ -0,0 +1,85 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +(ion_1_x "null values in text" + (then (text "null" ) (denotes (Null ))) + (then (text "null.null" ) (denotes (Null ))) + (then (text "null.blob" ) (denotes (Null blob ))) + (then (text "null.bool" ) (denotes (Null bool ))) + (then (text "null.clob" ) (denotes (Null clob ))) + (then (text "null.decimal" ) (denotes (Null decimal ))) + (then (text "null.float" ) (denotes (Null float ))) + (then (text "null.int" ) (denotes (Null int ))) + (then (text "null.list" ) (denotes (Null list ))) + (then (text "null.sexp" ) (denotes (Null sexp ))) + (then (text "null.string" ) (denotes (Null string ))) + (then (text "null.struct" ) (denotes (Null struct ))) + (then (text "null.symbol" ) (denotes (Null symbol ))) + (then (text "null.timestamp") (denotes (Null timestamp)))) + +(ion_1_x "malformed nulls in text should signal an error" + (each (text "null.") + (text "null.1") + (text "null.ion") + (text "null.array") + (signals "invalid type"))) + +(ion_1_x "in text, typed null suffix parsing has precedence over sexp operator rules" + (each (text "(null.)") + (text "(null.-)") + (text "(null..)") + (text "(null.true)") + (text "(null.1)") + (text "(null.nan)") + (text "(null.+inf)") + (text "(null.foo)") + (text "(null.[])") + (text "(null.())") + (text "(null.{})") + (signals "invalid type"))) + +(ion_1_0 "null values in Ion 1.0 binary" + (then (binary 0x0F) (denotes (Null ))) + (then (binary 0x1F) (denotes (Null bool ))) + (then (binary 0x2F) (denotes (Null int ))) + (then (binary 0x3F) (denotes (Null int ))) + (then (binary 0x4F) (denotes (Null float ))) + (then (binary 0x5F) (denotes (Null decimal ))) + (then (binary 0x6F) (denotes (Null timestamp))) + (then (binary 0x7F) (denotes (Null symbol ))) + (then (binary 0x8F) (denotes (Null string ))) + (then (binary 0x9F) (denotes (Null clob ))) + (then (binary 0xAF) (denotes (Null blob ))) + (then (binary 0xBF) (denotes (Null list ))) + (then (binary 0xCF) (denotes (Null sexp ))) + (then (binary 0xDF) (denotes (Null struct )))) + +(ion_1_1 "null values in Ion 1.1 binary" + (then (binary 0xEA) (denotes (Null ))) + (then (binary 0xEB 0x00) (denotes (Null bool ))) + (then (binary 0xEB 0x01) (denotes (Null int ))) + (then (binary 0xEB 0x02) (denotes (Null float ))) + (then (binary 0xEB 0x03) (denotes (Null decimal ))) + (then (binary 0xEB 0x04) (denotes (Null timestamp))) + (then (binary 0xEB 0x05) (denotes (Null string ))) + (then (binary 0xEB 0x06) (denotes (Null symbol ))) + (then (binary 0xEB 0x07) (denotes (Null blob ))) + (then (binary 0xEB 0x08) (denotes (Null clob ))) + (then (binary 0xEB 0x09) (denotes (Null list ))) + (then (binary 0xEB 0x0A) (denotes (Null sexp ))) + (then (binary 0xEB 0x0B) (denotes (Null struct )))) + +(ion_1_x "Null denotations" + (then (toplevel null.blob ) (denotes (Null blob ))) + (then (toplevel null.bool ) (denotes (Null bool ))) + (then (toplevel null.clob ) (denotes (Null clob ))) + (then (toplevel null.decimal ) (denotes (Null decimal ))) + (then (toplevel null.float ) (denotes (Null float ))) + (then (toplevel null.int ) (denotes (Null int ))) + (then (toplevel null.list ) (denotes (Null list ))) + (then (toplevel null.null ) (denotes (Null ))) + (then (toplevel null.sexp ) (denotes (Null sexp ))) + (then (toplevel null.string ) (denotes (Null string ))) + (then (toplevel null.struct ) (denotes (Null struct ))) + (then (toplevel null.symbol ) (denotes (Null symbol ))) + (then (toplevel null.timestamp) (denotes (Null timestamp)))) diff --git a/conformance/null.ion b/conformance/null.ion deleted file mode 100644 index f7fd3e3..0000000 --- a/conformance/null.ion +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -(ion_1_x - "Verify basic pass-through behavior between `toplevel` and `produces`" - (toplevel null null.null a::null) - (produces null.null null.null a::null))