Skip to content

Commit

Permalink
Adds data model conformance tests for nulls and booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
popematt committed Nov 15, 2024
1 parent 1d0cb6e commit a0acfb4
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 27 deletions.
20 changes: 0 additions & 20 deletions conformance/core/typed_null.ion

This file was deleted.

48 changes: 48 additions & 0 deletions conformance/data_model/annotations.ion
Original file line number Diff line number Diff line change
@@ -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")))
40 changes: 40 additions & 0 deletions conformance/data_model/boolean.ion
Original file line number Diff line number Diff line change
@@ -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")))
85 changes: 85 additions & 0 deletions conformance/data_model/null.ion
Original file line number Diff line number Diff line change
@@ -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))))
7 changes: 0 additions & 7 deletions conformance/null.ion

This file was deleted.

0 comments on commit a0acfb4

Please sign in to comment.