From 1ab8853216a63a2810247bcf8936dd3f244c007a Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 1 Jul 2021 20:15:59 -0700 Subject: [PATCH 1/3] Create assertion tests for floats and strings --- tests/assertions/basics.n | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/assertions/basics.n diff --git a/tests/assertions/basics.n b/tests/assertions/basics.n new file mode 100644 index 00000000..7617851e --- /dev/null +++ b/tests/assertions/basics.n @@ -0,0 +1,26 @@ +// No equivalent in the documentation 😳 + +// Floats are double-precision :postpissedchil: + +// Division of nonzero numbers by zero; negative zero +let inf = 1.0 / 0.0 +assert value 1.0 / -0.0 == -inf +assert value 0.0 == -0.0 + +// NaN +let nan = inf - inf +assert value nan /= nan +assert value 0.0 / 0.0 /= 0.0 / 0.0 + +assert value 0.1 + 0.2 == 0.30000000000000004 + +assert value 9007199254740992.0 + 1.0 == 9007199254740992.0 + +// Strings + +assert value "\{🕴}" == "🕴" +assert value "\0\b\t\n\v\f\r\"\\" == "\u{0}\u{8}\u{9}\u{a}\u{b}\u{c}\u{d}\u{22}\u{5c}" + +// Chars + +assert value \v == \u{b} From 1f5ff7e7767ba002f720519276f80a00c28df5b7 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 1 Jul 2021 20:27:14 -0700 Subject: [PATCH 2/3] Add syntax tests for literals to make sure they're parsed properly --- tests/syntax/literals.n | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/syntax/literals.n diff --git a/tests/syntax/literals.n b/tests/syntax/literals.n new file mode 100644 index 00000000..69bb5f38 --- /dev/null +++ b/tests/syntax/literals.n @@ -0,0 +1,19 @@ +// Number and string literal syntax to ensure they're supported + +let binary = 0b10101 +let octal = 0o70707 +let hex = 0x123AbC + +// TODO: Do we allow something like `50e10`? +let scinot = -5.000000000000001e-231 + +let newline = \n +let char = \{🐑} +let unicode = \u{1f382} + +let allTogether = "\n\{🐑}\u{1f382}\\\\\\\\" + +let unit = () + +let trailingComma = { a: (1, 2,); b: 2; } +let inList: map[str, str,] = mapFrom([("ah", "pple",), ("ahh", "ppple",),],) From 9edb5cec13b434e48a86cfc4acf8165a3d003417 Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 1 Jul 2021 20:33:50 -0700 Subject: [PATCH 3/3] Add value assertions to the list and record tests --- tests/assertions/tuples-lists-records.n | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/tests/assertions/tuples-lists-records.n b/tests/assertions/tuples-lists-records.n index 8beb79f5..34eb5134 100644 --- a/tests/assertions/tuples-lists-records.n +++ b/tests/assertions/tuples-lists-records.n @@ -1,9 +1,20 @@ // Based on docs/features/tuples_lists_records.md -assert type 1, \{a} : int, char +let tuplevalue = 1, \{a} +assert type tuplevalue : int, char let recordValue = { value: 1 } assert type recordValue : { value: int } -assert type recordValue.value : int -assert type ["a", "b", "c"] : list[str] +let value = recordvalue.value +assert type value : int +assert value value == 1 + +let listvalue = ["a", "b", "c"] +assert type listvalue : list[str] + +assert value append("d", listvalue) == ["a", "b", "c", "d"] +assert value listvalue == ["a", "b", "c"] + +let listindexvalue = itemAt(1, listvalue) +assert value listindexvalue == yes("b")