From aaaf8cb890fb14b556bbc437c9bbf2ef399fc55e Mon Sep 17 00:00:00 2001 From: sylvanc Date: Sat, 11 Mar 2017 12:28:07 +0000 Subject: [PATCH 1/3] Arrays as sequences Previously, a comma ',' was used to separate array elements. In Pony, a comma is the tuple operator, and as a result, an array appeared to be composed of a tuple of elements. This change defines an array as a sequence of elements instead. As a result, no separator is needed when elements are on new lines, or a semicolon ';' (i.e. the sequence operator) can be used when elements are on the same line. This change means that all instances of ',' in Pony indicate a tuple (including, logically speaking, parameter lists, arguments, type arguments, etc.) and all instances of ';' indicate a sequence. --- packages/buffered/_test.pony | 51 ++++---- packages/builtin_test/_test.pony | 90 +++++++------- packages/collections/_test.pony | 18 +-- packages/collections/persistent/_test.pony | 76 ++++++------ packages/crypto/_test.pony | 4 +- packages/files/_test.pony | 26 ++-- packages/glob/_test.pony | 12 +- packages/itertools/_test.pony | 133 +++++++++++---------- packages/net/_test.pony | 4 +- packages/options/_test.pony | 8 +- packages/ponybench/_test.pony | 10 +- packages/ponybench/pony_bench.pony | 12 +- packages/process/_test.pony | 2 +- packages/regex/_test.pony | 10 +- packages/serialise/_test.pony | 12 +- packages/strings/_test.pony | 15 +-- src/libponyc/ast/parser.c | 6 +- src/libponyc/expr/array.c | 10 +- src/libponyc/expr/control.c | 8 +- src/libponyc/expr/literal.c | 11 +- test/libponyc/badpony.cc | 2 +- test/libponyc/literal_inference.cc | 20 ++-- 22 files changed, 278 insertions(+), 262 deletions(-) diff --git a/packages/buffered/_test.pony b/packages/buffered/_test.pony index 6642e56cd3..c5fea5f9c1 100644 --- a/packages/buffered/_test.pony +++ b/packages/buffered/_test.pony @@ -19,22 +19,22 @@ class iso _TestReader is UnitTest let b = Reader b.append(recover [as U8: - 0x42, - 0xDE, 0xAD, - 0xAD, 0xDE, - 0xDE, 0xAD, 0xBE, 0xEF, - 0xEF, 0xBE, 0xAD, 0xDE, - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED, 0xFA, 0xCE, - 0xCE, 0xFA, 0xED, 0xFE, 0xEF, 0xBE, 0xAD, 0xDE, - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED, 0xFA, 0xCE, - 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED, 0xFA, 0xCE, - 0xCE, 0xFA, 0xED, 0xFE, 0xEF, 0xBE, 0xAD, 0xDE, - 0xCE, 0xFA, 0xED, 0xFE, 0xEF, 0xBE, 0xAD, 0xDE + 0x42 + 0xDE; 0xAD + 0xAD; 0xDE + 0xDE; 0xAD; 0xBE; 0xEF + 0xEF; 0xBE; 0xAD; 0xDE + 0xDE; 0xAD; 0xBE; 0xEF; 0xFE; 0xED; 0xFA; 0xCE + 0xCE; 0xFA; 0xED; 0xFE; 0xEF; 0xBE; 0xAD; 0xDE + 0xDE; 0xAD; 0xBE; 0xEF; 0xFE; 0xED; 0xFA; 0xCE + 0xDE; 0xAD; 0xBE; 0xEF; 0xFE; 0xED; 0xFA; 0xCE + 0xCE; 0xFA; 0xED; 0xFE; 0xEF; 0xBE; 0xAD; 0xDE + 0xCE; 0xFA; 0xED; 0xFE; 0xEF; 0xBE; 0xAD; 0xDE ] end) - b.append(recover [as U8: 'h', 'i'] end) - b.append(recover [as U8: '\n', 't', 'h', 'e'] end) - b.append(recover [as U8: 'r', 'e', '\r', '\n'] end) + b.append(recover [as U8: 'h'; 'i'] end) + b.append(recover [as U8: '\n'; 't'; 'h'; 'e'] end) + b.append(recover [as U8: 'r'; 'e'; '\r'; '\n'] end) // These expectations peek into the buffer without consuming bytes. h.assert_eq[U8](b.peek_u8(), 0x42) @@ -64,24 +64,25 @@ class iso _TestReader is UnitTest h.assert_eq[String](b.line(), "hi") h.assert_eq[String](b.line(), "there") - b.append(recover [as U8: 'h', 'i'] end) + b.append(recover [as U8: 'h'; 'i'] end) try b.line() h.fail("shouldn't have a line") end - b.append(recover [as U8: '!', '\n'] end) + b.append(recover [as U8: '!'; '\n'] end) h.assert_eq[String](b.line(), "hi!") - b.append(recover [as U8: 's', 't', 'r', '1'] end) + b.append(recover [as U8: 's'; 't'; 'r'; '1'] end) try b.read_until(0) h.fail("should fail reading until 0") end b.append(recover [as U8: 0] end) - b.append(recover [as U8: 'f', 'i', 'e', 'l', 'd', '1', ';', - 'f', 'i', 'e', 'l', 'd', '2', ';', ';'] end) + b.append(recover [as U8: + 'f'; 'i'; 'e'; 'l'; 'd'; '1'; ';' + 'f'; 'i'; 'e'; 'l'; 'd'; '2'; ';'; ';'] end) h.assert_eq[String](String.from_array(b.read_until(0)), "str1") h.assert_eq[String](String.from_array(b.read_until(';')), "field1") h.assert_eq[String](String.from_array(b.read_until(';')), "field2") @@ -111,9 +112,11 @@ class iso _TestWriter is UnitTest .>u128_be(0xDEADBEEFFEEDFACEDEADBEEFFEEDFACE) .>u128_le(0xDEADBEEFFEEDFACEDEADBEEFFEEDFACE) - wb.write(recover [as U8: 'h', 'i'] end) - wb.writev(recover [as Array[U8]: [as U8: '\n', 't', 'h', 'e'], - [as U8: 'r', 'e', '\r', '\n']] end) + wb.write(recover [as U8: 'h'; 'i'] end) + wb.writev(recover + [as Array[U8]: + [as U8: '\n'; 't'; 'h'; 'e'] + [as U8: 'r'; 'e'; '\r'; '\n']] end) for bs in wb.done().values() do try @@ -149,12 +152,12 @@ class iso _TestWriter is UnitTest h.assert_eq[String](b.line(), "hi") h.assert_eq[String](b.line(), "there") - b.append(recover [as U8: 'h', 'i'] end) + b.append(recover [as U8: 'h'; 'i'] end) try b.line() h.fail("shouldn't have a line") end - b.append(recover [as U8: '!', '\n'] end) + b.append(recover [as U8: '!'; '\n'] end) h.assert_eq[String](b.line(), "hi!") diff --git a/packages/builtin_test/_test.pony b/packages/builtin_test/_test.pony index bf32459139..38bb4e9541 100644 --- a/packages/builtin_test/_test.pony +++ b/packages/builtin_test/_test.pony @@ -176,7 +176,7 @@ class iso _TestStringRunes is UnitTest fun apply(h: TestHelper) ? => let s = "\u16ddx\ufb04" - let expect = [as U32: 0x16dd, 'x', 0xfb04] + let expect = [as U32: 0x16dd; 'x'; 0xfb04] let result = Array[U32] for c in s.runes() do @@ -503,10 +503,10 @@ class iso _TestStringIsNullTerminated is UnitTest h.assert_false("0123456".trim(2, 4).is_null_terminated()) h.assert_true(String.from_iso_array(recover - ['a', 'b', 'c'] + ['a'; 'b'; 'c'] end).is_null_terminated()) h.assert_false(String.from_iso_array(recover - ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] // power of two sized array + ['a'; 'b'; 'c'; 'd'; 'e'; 'f'; 'g'; 'h'] // power of two sized array end).is_null_terminated()) @@ -698,9 +698,9 @@ class iso _TestStringJoin is UnitTest fun apply(h: TestHelper) => h.assert_eq[String]("_".join(["zomg"]), "zomg") - h.assert_eq[String]("_".join(["hi", "there"]), "hi_there") - h.assert_eq[String](" ".join(["1", "", "2", ""]), "1 2 ") - h.assert_eq[String](" ".join([as Stringable: U32(1), U32(4)]), "1 4") + h.assert_eq[String]("_".join(["hi"; "there"]), "hi_there") + h.assert_eq[String](" ".join(["1"; ""; "2"; ""]), "1 2 ") + h.assert_eq[String](" ".join([as Stringable: U32(1); U32(4)]), "1 4") h.assert_eq[String](" ".join(Array[String]), "") @@ -931,11 +931,11 @@ class iso _TestStringFromArray is UnitTest fun name(): String => "builtin/String.from_array" fun apply(h: TestHelper) => - let s_null = String.from_array(recover ['f', 'o', 'o', 0] end) + let s_null = String.from_array(recover ['f'; 'o'; 'o'; 0] end) h.assert_eq[String](s_null, "foo\x00") h.assert_eq[USize](s_null.size(), 4) - let s_no_null = String.from_array(recover ['f', 'o', 'o'] end) + let s_no_null = String.from_array(recover ['f'; 'o'; 'o'] end) h.assert_eq[String](s_no_null, "foo") h.assert_eq[USize](s_no_null.size(), 3) @@ -944,13 +944,13 @@ class iso _TestStringFromIsoArray is UnitTest fun name(): String => "builtin/String.from_iso_array" fun apply(h: TestHelper) => - let s = recover val String.from_iso_array(recover ['f', 'o', 'o'] end) end + let s = recover val String.from_iso_array(recover ['f'; 'o'; 'o'] end) end h.assert_eq[String](s, "foo") h.assert_eq[USize](s.size(), 3) h.assert_true((s.space() == 3) xor s.is_null_terminated()) let s2 = recover val String.from_iso_array(recover - ['1', '1', '1', '1', '1', '1', '1', '1'] + ['1'; '1'; '1'; '1'; '1'; '1'; '1'; '1'] end) end h.assert_eq[String](s2, "11111111") h.assert_eq[USize](s2.size(), 8) @@ -962,7 +962,7 @@ class iso _TestStringSpace is UnitTest fun apply(h: TestHelper) => let s = String.from_iso_array(recover - ['1', '1', '1', '1', '1', '1', '1', '1'] + ['1'; '1'; '1'; '1'; '1'; '1'; '1'; '1'] end) h.assert_eq[USize](s.size(), 8) @@ -975,7 +975,7 @@ class iso _TestStringRecalc is UnitTest fun apply(h: TestHelper) => let s: String ref = String.from_iso_array(recover - ['1', '1', '1', '1', '1', '1', '1', '1'] + ['1'; '1'; '1'; '1'; '1'; '1'; '1'; '1'] end) s.recalc() h.assert_eq[USize](s.size(), 8) @@ -989,7 +989,7 @@ class iso _TestStringRecalc is UnitTest h.assert_true(s2.is_null_terminated()) let s3: String ref = String.from_iso_array(recover - ['1', 0, 0, 0, 0, 0, 0, '1'] + ['1'; 0; 0; 0; 0; 0; 0; '1'] end) s3.truncate(1) s3.recalc() @@ -1003,7 +1003,7 @@ class iso _TestStringTruncate is UnitTest fun apply(h: TestHelper) => let s = recover ref String.from_iso_array(recover - ['1', '1', '1', '1', '1', '1', '1', '1'] + ['1'; '1'; '1'; '1'; '1'; '1'; '1'; '1'] end) end s.truncate(s.space()) h.assert_true(s.is_null_terminated()) @@ -1027,8 +1027,8 @@ class iso _TestArrayAppend is UnitTest fun name(): String => "builtin/Array.append" fun apply(h: TestHelper) ? => - var a = ["one", "two", "three"] - var b = ["four", "five", "six"] + var a = ["one"; "two"; "three"] + var b = ["four"; "five"; "six"] a.append(b) h.assert_eq[USize](a.size(), 6) h.assert_eq[String]("one", a(0)) @@ -1038,8 +1038,8 @@ class iso _TestArrayAppend is UnitTest h.assert_eq[String]("five", a(4)) h.assert_eq[String]("six", a(5)) - a = ["one", "two", "three"] - b = ["four", "five", "six"] + a = ["one"; "two"; "three"] + b = ["four"; "five"; "six"] a.append(b, 1) h.assert_eq[USize](a.size(), 5) h.assert_eq[String]("one", a(0)) @@ -1048,8 +1048,8 @@ class iso _TestArrayAppend is UnitTest h.assert_eq[String]("five", a(3)) h.assert_eq[String]("six", a(4)) - a = ["one", "two", "three"] - b = ["four", "five", "six"] + a = ["one"; "two"; "three"] + b = ["four"; "five"; "six"] a.append(b, 1, 1) h.assert_eq[USize](a.size(), 4) h.assert_eq[String]("one", a(0)) @@ -1062,8 +1062,8 @@ class iso _TestArrayConcat is UnitTest fun name(): String => "builtin/Array.concat" fun apply(h: TestHelper) ? => - var a = ["one", "two", "three"] - var b = ["four", "five", "six"] + var a = ["one"; "two"; "three"] + var b = ["four"; "five"; "six"] a.concat(b.values()) h.assert_eq[USize](a.size(), 6) h.assert_eq[String]("one", a(0)) @@ -1073,8 +1073,8 @@ class iso _TestArrayConcat is UnitTest h.assert_eq[String]("five", a(4)) h.assert_eq[String]("six", a(5)) - a = ["one", "two", "three"] - b = ["four", "five", "six"] + a = ["one"; "two"; "three"] + b = ["four"; "five"; "six"] a.concat(b.values(), 1) h.assert_eq[USize](a.size(), 5) h.assert_eq[String]("one", a(0)) @@ -1083,8 +1083,8 @@ class iso _TestArrayConcat is UnitTest h.assert_eq[String]("five", a(3)) h.assert_eq[String]("six", a(4)) - a = ["one", "two", "three"] - b = ["four", "five", "six"] + a = ["one"; "two"; "three"] + b = ["four"; "five"; "six"] a.concat(b.values(), 1, 1) h.assert_eq[USize](a.size(), 4) h.assert_eq[String]("one", a(0)) @@ -1100,7 +1100,7 @@ class iso _TestArraySlice is UnitTest fun name(): String => "builtin/Array.slice" fun apply(h: TestHelper) ? => - let a = ["one", "two", "three", "four", "five"] + let a = ["one"; "two"; "three"; "four"; "five"] let b = a.slice(1, 4) h.assert_eq[USize](b.size(), 3) @@ -1136,10 +1136,10 @@ class iso _TestArrayTrim is UnitTest fun name(): String => "builtin/Array.trim" fun apply(h: TestHelper) => - let orig: Array[U8] val = recover [0, 1, 2, 3, 4, 5, 6] end - h.assert_array_eq[U8]([as U8: 4, 5], orig.trim(4, 6)) - h.assert_array_eq[U8]([as U8: 4, 5, 6], orig.trim(4, 7)) - h.assert_array_eq[U8]([as U8: 4, 5, 6], orig.trim(4)) + let orig = recover val [as U8: 0; 1; 2; 3; 4; 5; 6] end + h.assert_array_eq[U8]([as U8: 4; 5], orig.trim(4, 6)) + h.assert_array_eq[U8]([as U8: 4; 5; 6], orig.trim(4, 7)) + h.assert_array_eq[U8]([as U8: 4; 5; 6], orig.trim(4)) h.assert_array_eq[U8](Array[U8], orig.trim(4, 4)) h.assert_array_eq[U8](Array[U8], orig.trim(4, 1)) @@ -1151,11 +1151,11 @@ class iso _TestArrayTrimInPlace is UnitTest fun name(): String => "builtin/Array.trim_in_place" fun apply(h: TestHelper) => - case(h, [4, 5], [0, 1, 2, 3, 4, 5, 6], 4, 6) - case(h, [4, 5, 6], [0, 1, 2, 3, 4, 5, 6], 4, 7) - case(h, [4, 5, 6], [0, 1, 2, 3, 4, 5, 6], 4) - case(h, Array[U8], [0, 1, 2, 3, 4, 5, 6], 4, 4) - case(h, Array[U8], [0, 1, 2, 3, 4, 5, 6], 4, 1) + case(h, [4; 5], [0; 1; 2; 3; 4; 5; 6], 4, 6) + case(h, [4; 5; 6], [0; 1; 2; 3; 4; 5; 6], 4, 7) + case(h, [4; 5; 6], [0; 1; 2; 3; 4; 5; 6], 4) + case(h, Array[U8], [0; 1; 2; 3; 4; 5; 6], 4, 4) + case(h, Array[U8], [0; 1; 2; 3; 4; 5; 6], 4, 1) fun case(h: TestHelper, expected: Array[U8], orig: Array[U8], from: USize, to: USize = -1) @@ -1171,19 +1171,19 @@ class iso _TestArrayInsert is UnitTest fun name(): String => "builtin/Array.insert" fun apply(h: TestHelper) ? => - let a = ["one", "three"] + let a = ["one"; "three"] a.insert(0, "zero") - h.assert_array_eq[String](["zero", "one", "three"], a) + h.assert_array_eq[String](["zero"; "one"; "three"], a) - let b = ["one", "three"] + let b = ["one"; "three"] b.insert(1, "two") - h.assert_array_eq[String](["one", "two", "three"], b) + h.assert_array_eq[String](["one"; "two"; "three"], b) - let c = ["one", "three"] + let c = ["one"; "three"] c.insert(2, "four") - h.assert_array_eq[String](["one", "three", "four"], c) + h.assert_array_eq[String](["one"; "three"; "four"], c) - h.assert_error({()? => ["one", "three"].insert(3, "invalid") }) + h.assert_error({()? => ["one"; "three"].insert(3, "invalid") }) class iso _TestArrayValuesRewind is UnitTest """ @@ -1192,7 +1192,7 @@ class iso _TestArrayValuesRewind is UnitTest fun name(): String => "builtin/ArrayValues.rewind" fun apply(h: TestHelper) ? => - let av = [as U32: 1, 2, 3, 4].values() + let av = [as U32: 1; 2; 3; 4].values() h.assert_eq[U32](1, av.next()) h.assert_eq[U32](2, av.next()) @@ -1221,7 +1221,7 @@ class iso _TestArrayFind is UnitTest fun name(): String => "builtin/Array.find" fun apply(h: TestHelper) ? => - let a: Array[ISize] = [0, 1, 2, 3, 4, 1] + let a = [as ISize: 0; 1; 2; 3; 4; 1] h.assert_eq[USize](1, a.find(1)) h.assert_eq[USize](5, a.find(1 where offset = 3)) h.assert_eq[USize](5, a.find(1 where nth = 1)) diff --git a/packages/collections/_test.pony b/packages/collections/_test.pony index 5b5d458286..a49d5185ae 100644 --- a/packages/collections/_test.pony +++ b/packages/collections/_test.pony @@ -56,7 +56,7 @@ class iso _TestListsFrom is UnitTest fun name(): String => "collections/Lists/from()" fun apply(h: TestHelper) ? => - let a = List[U32].from([1, 3, 5, 7, 9]) + let a = List[U32].from([1; 3; 5; 7; 9]) h.assert_eq[USize](a.size(), 5) h.assert_eq[U32](a(0), 1) @@ -514,17 +514,17 @@ class iso _TestSort is UnitTest fun apply(h: TestHelper) => test_sort[USize](h, - [23, 26, 31, 41, 53, 58, 59, 84, 93, 97], - [31, 41, 59, 26, 53, 58, 97, 93, 23, 84]) + [23; 26; 31; 41; 53; 58; 59; 84; 93; 97], + [31; 41; 59; 26; 53; 58; 97; 93; 23; 84]) test_sort[I64](h, - [-5467984, -784, 0, 0, 42, 59, 74, 238, 905, 959, 7586, 7586, 9845], - [74, 59, 238, -784, 9845, 959, 905, 0, 0, 42, 7586, -5467984, 7586]) + [-5467984; -784; 0; 0; 42; 59; 74; 238; 905; 959; 7586; 7586; 9845], + [74; 59; 238; -784; 9845; 959; 905; 0; 0; 42; 7586; -5467984; 7586]) test_sort[F64](h, - [-959.7485, -784.0, 2.3, 7.8, 7.8, 59.0, 74.3, 238.2, 905, 9845.768], - [74.3, 59.0, 238.2, -784.0, 2.3, 9845.768, -959.7485, 905, 7.8, 7.8]) + [-959.7485; -784.0; 2.3; 7.8; 7.8; 59.0; 74.3; 238.2; 905; 9845.768], + [74.3; 59.0; 238.2; -784.0; 2.3; 9845.768; -959.7485; 905; 7.8; 7.8]) test_sort[String](h, - ["", "%*&^*&^&", "***", "Hello", "bar", "f00", "foo", "foo"], - ["", "Hello", "foo", "bar", "foo", "f00", "%*&^*&^&", "***"]) + [""; "%*&^*&^&"; "***"; "Hello"; "bar"; "f00"; "foo"; "foo"], + [""; "Hello"; "foo"; "bar"; "foo"; "f00"; "%*&^*&^&"; "***"]) fun test_sort[A: (Comparable[A] val & Stringable)]( h: TestHelper, diff --git a/packages/collections/persistent/_test.pony b/packages/collections/persistent/_test.pony index 1b0e241c6b..0b5292f5e2 100644 --- a/packages/collections/persistent/_test.pony +++ b/packages/collections/persistent/_test.pony @@ -57,7 +57,7 @@ class iso _TestListFrom is UnitTest fun name(): String => "collections/persistent/Lists/from()" fun apply(h: TestHelper) ? => - let l1 = Lists[U32]([1, 2, 3]) + let l1 = Lists[U32]([1; 2; 3]) h.assert_eq[USize](l1.size(), 3) h.assert_eq[U32](l1.head(), 1) @@ -65,7 +65,7 @@ class iso _TestListApply is UnitTest fun name(): String => "collections/persistent/List/apply()" fun apply(h: TestHelper) ? => - let l1 = Lists[U32]([1, 2, 3]) + let l1 = Lists[U32]([1; 2; 3]) h.assert_eq[U32](l1(0), 1) h.assert_eq[U32](l1(1), 2) h.assert_eq[U32](l1(2), 3) @@ -79,7 +79,7 @@ class iso _TestListValues is UnitTest fun name(): String => "collections/persistent/List/values()" fun apply(h: TestHelper) ? => - let iter = Lists[U32]([1, 2, 3]).values() + let iter = Lists[U32]([1; 2; 3]).values() h.assert_true(iter.has_next()) h.assert_eq[U32](iter.next(), 1) h.assert_true(iter.has_next()) @@ -95,19 +95,19 @@ class iso _TestListConcat is UnitTest fun name(): String => "collections/persistent/List/concat()" fun apply(h: TestHelper) ? => - let l1 = Lists[U32]([1, 2, 3]) - let l2 = Lists[U32]([4, 5, 6]) + let l1 = Lists[U32]([1; 2; 3]) + let l2 = Lists[U32]([4; 5; 6]) let l3 = l1.concat(l2) let l4 = l3.reverse() h.assert_eq[USize](l3.size(), 6) - h.assert_true(Lists[U32].eq(l3, Lists[U32]([1,2,3,4,5,6]))) - h.assert_true(Lists[U32].eq(l4, Lists[U32]([6,5,4,3,2,1]))) + h.assert_true(Lists[U32].eq(l3, Lists[U32]([1; 2; 3; 4; 5; 6]))) + h.assert_true(Lists[U32].eq(l4, Lists[U32]([6; 5; 4; 3; 2; 1]))) let l5 = Lists[U32].empty() let l6 = l5.reverse() let l7 = l6.concat(l1) h.assert_eq[USize](l6.size(), 0) - h.assert_true(Lists[U32].eq(l7, Lists[U32]([1,2,3]))) + h.assert_true(Lists[U32].eq(l7, Lists[U32]([1; 2; 3]))) let l8 = Lists[U32]([1]) let l9 = l8.reverse() @@ -117,48 +117,49 @@ class iso _TestListMap is UnitTest fun name(): String => "collections/persistent/Lists/map()" fun apply(h: TestHelper) ? => - let l5 = Lists[U32]([1, 2, 3]).map[U32]({(x: U32): U32 => x * 2 }) - h.assert_true(Lists[U32].eq(l5, Lists[U32]([2,4,6]))) + let l5 = Lists[U32]([1; 2; 3]).map[U32]({(x: U32): U32 => x * 2 }) + h.assert_true(Lists[U32].eq(l5, Lists[U32]([2; 4; 6]))) class iso _TestListFlatMap is UnitTest fun name(): String => "collections/persistent/Lists/flat_map()" fun apply(h: TestHelper) ? => - let f = {(x: U32): List[U32] => Lists[U32]([x - 1, x, x + 1]) } - let l6 = Lists[U32]([2, 5, 8]).flat_map[U32](f) - h.assert_true(Lists[U32].eq(l6, Lists[U32]([1,2,3,4,5,6,7,8,9]))) + let f = {(x: U32): List[U32] => Lists[U32]([x - 1; x; x + 1]) } + let l6 = Lists[U32]([2; 5; 8]).flat_map[U32](f) + h.assert_true(Lists[U32].eq(l6, Lists[U32]([1; 2; 3; 4; 5; 6; 7; 8; 9]))) class iso _TestListFilter is UnitTest fun name(): String => "collections/persistent/Lists/filter()" fun apply(h: TestHelper) ? => let is_even = {(x: U32): Bool => (x % 2) == 0 } - let l7 = Lists[U32]([1,2,3,4,5,6,7,8]).filter(is_even) - h.assert_true(Lists[U32].eq(l7, Lists[U32]([2,4,6,8]))) + let l7 = Lists[U32]([1; 2; 3; 4; 5; 6; 7; 8]).filter(is_even) + h.assert_true(Lists[U32].eq(l7, Lists[U32]([2; 4; 6; 8]))) class iso _TestListFold is UnitTest fun name(): String => "collections/persistent/Lists/fold()" fun apply(h: TestHelper) ? => let add = {(acc: U32, x: U32): U32 => acc + x } - let value = Lists[U32]([1,2,3]).fold[U32](add, 0) + let value = Lists[U32]([1; 2; 3]).fold[U32](add, 0) h.assert_eq[U32](value, 6) let doubleAndPrepend = {(acc: List[U32], x: U32): List[U32] => acc.prepend(x * 2) } let l8 = - Lists[U32]([1,2,3]).fold[List[U32]](doubleAndPrepend, Lists[U32].empty()) - h.assert_true(Lists[U32].eq(l8, Lists[U32]([6,4,2]))) + Lists[U32]([1; 2; 3]).fold[List[U32]]( + doubleAndPrepend, Lists[U32].empty()) + h.assert_true(Lists[U32].eq(l8, Lists[U32]([6; 4; 2]))) class iso _TestListEveryExists is UnitTest fun name(): String => "collections/persistent/Lists/every()exists()" fun apply(h: TestHelper) => let is_even = {(x: U32): Bool => (x % 2) == 0 } - let l9 = Lists[U32]([4,2,10]) - let l10 = Lists[U32]([1,1,3]) - let l11 = Lists[U32]([1,1,2]) - let l12 = Lists[U32]([2,2,3]) + let l9 = Lists[U32]([4; 2; 10]) + let l10 = Lists[U32]([1; 1; 3]) + let l11 = Lists[U32]([1; 1; 2]) + let l12 = Lists[U32]([2; 2; 3]) let l13 = Lists[U32].empty() h.assert_eq[Bool](l9.every(is_even), true) h.assert_eq[Bool](l10.every(is_even), false) @@ -176,19 +177,19 @@ class iso _TestListPartition is UnitTest fun apply(h: TestHelper) ? => let is_even = {(x: U32): Bool => (x % 2) == 0 } - let l = Lists[U32]([1,2,3,4,5,6]) + let l = Lists[U32]([1; 2; 3; 4; 5; 6]) (let hits, let misses) = l.partition(is_even) - h.assert_true(Lists[U32].eq(hits, Lists[U32]([2,4,6]))) - h.assert_true(Lists[U32].eq(misses, Lists[U32]([1,3,5]))) + h.assert_true(Lists[U32].eq(hits, Lists[U32]([2; 4; 6]))) + h.assert_true(Lists[U32].eq(misses, Lists[U32]([1; 3; 5]))) class iso _TestListDrop is UnitTest fun name(): String => "collections/persistent/List/drop()" fun apply(h: TestHelper) ? => - let l = Lists[String](["a","b","c","d","e"]) - let l2 = Lists[U32]([1,2]) + let l = Lists[String](["a"; "b"; "c"; "d"; "e"]) + let l2 = Lists[U32]([1; 2]) let empty = Lists[String].empty() - h.assert_true(Lists[String].eq(l.drop(3), Lists[String](["d","e"]))) + h.assert_true(Lists[String].eq(l.drop(3), Lists[String](["d"; "e"]))) h.assert_true(Lists[U32].eq(l2.drop(3), Lists[U32].empty())) h.assert_true(Lists[String].eq(empty.drop(3), Lists[String].empty())) @@ -197,20 +198,21 @@ class iso _TestListDropWhile is UnitTest fun apply(h: TestHelper) ? => let is_even = {(x: U32): Bool => (x % 2) == 0 } - let l = Lists[U32]([4,2,6,1,3,4,6]) + let l = Lists[U32]([4; 2; 6; 1; 3; 4; 6]) let empty = Lists[U32].empty() - h.assert_true(Lists[U32].eq(l.drop_while(is_even), Lists[U32]([1,3,4,6]))) + h.assert_true(Lists[U32].eq(l.drop_while(is_even), + Lists[U32]([1; 3; 4; 6]))) h.assert_true(Lists[U32].eq(empty.drop_while(is_even), Lists[U32].empty())) class iso _TestListTake is UnitTest fun name(): String => "collections/persistent/List/take()" fun apply(h: TestHelper) ? => - let l = Lists[String](["a","b","c","d","e"]) - let l2 = Lists[U32]([1,2]) + let l = Lists[String](["a"; "b"; "c"; "d"; "e"]) + let l2 = Lists[U32]([1; 2]) let empty = Lists[String].empty() - h.assert_true(Lists[String].eq(l.take(3), Lists[String](["a","b","c"]))) - h.assert_true(Lists[U32].eq(l2.take(3), Lists[U32]([1,2]))) + h.assert_true(Lists[String].eq(l.take(3), Lists[String](["a"; "b"; "c"]))) + h.assert_true(Lists[U32].eq(l2.take(3), Lists[U32]([1; 2]))) h.assert_true(Lists[String].eq(empty.take(3), Lists[String].empty())) class iso _TestListTakeWhile is UnitTest @@ -218,9 +220,9 @@ class iso _TestListTakeWhile is UnitTest fun apply(h: TestHelper) ? => let is_even = {(x: U32): Bool => (x % 2) == 0 } - let l = Lists[U32]([4,2,6,1,3,4,6]) + let l = Lists[U32]([4; 2; 6; 1; 3; 4; 6]) let empty = Lists[U32].empty() - h.assert_true(Lists[U32].eq(l.take_while(is_even), Lists[U32]([4,2,6]))) + h.assert_true(Lists[U32].eq(l.take_while(is_even), Lists[U32]([4; 2; 6]))) h.assert_true(Lists[U32].eq(empty.take_while(is_even), Lists[U32].empty())) class iso _TestMap is UnitTest @@ -241,7 +243,7 @@ class iso _TestMap is UnitTest h.assert_eq[U32](m4("a"), 4) h.assert_eq[U32](m5("c"), 0) - let vs = [as (String, U32): ("a", 2), ("b", 3), ("d", 4), ("e", 5)] + let vs = [as (String, U32): ("a", 2); ("b", 3); ("d", 4); ("e", 5)] let m6 = Map[String,U32].concat(vs.values()) let m7 = m6("a") = 10 h.assert_eq[U32](m6("a"), 2) diff --git a/packages/crypto/_test.pony b/packages/crypto/_test.pony index b2226298a7..792a739f2c 100644 --- a/packages/crypto/_test.pony +++ b/packages/crypto/_test.pony @@ -24,8 +24,8 @@ class iso _TestConstantTimeCompare is UnitTest let s2 = "54321" let s3 = "123456" let s4 = "1234" - let s5 = recover val [U8(0), U8(0), U8(0), U8(0), U8(0)] end - let s6 = String.from_array(recover [U8(0), U8(0), U8(0), U8(0), U8(0)] end) + let s5 = recover val [U8(0); U8(0); U8(0); U8(0); U8(0)] end + let s6 = String.from_array(recover [U8(0); U8(0); U8(0); U8(0); U8(0)] end) let s7 = "" h.assert_true(ConstantTimeCompare(s1, s1)) h.assert_false(ConstantTimeCompare(s1, s2)) diff --git a/packages/files/_test.pony b/packages/files/_test.pony index 6ad562afb5..096e197eda 100644 --- a/packages/files/_test.pony +++ b/packages/files/_test.pony @@ -67,18 +67,18 @@ class iso _TestWalk is UnitTest fun name(): String => "files/FilePath.walk" fun apply(h: TestHelper) ? => let top = _FileHelper.make_files( - h, ["a/1", "a/2", "b", "c/3", "c/4", "d/5", "d/6"]) + h, ["a/1"; "a/2"; "b"; "c/3"; "c/4"; "d/5"; "d/6"]) try top.walk( {(dir: FilePath, entries: Array[String] ref)(p = top.path, h) => if dir.path == p then - h.assert_array_eq_unordered[String](["b", "c", "a", "d"], entries) + h.assert_array_eq_unordered[String](["b"; "c"; "a"; "d"], entries) elseif dir.path.at("a", -1) then - h.assert_array_eq_unordered[String](["1", "2"], entries) + h.assert_array_eq_unordered[String](["1"; "2"], entries) elseif dir.path.at("c", -1) then - h.assert_array_eq_unordered[String](["3", "4"], entries) + h.assert_array_eq_unordered[String](["3"; "4"], entries) elseif dir.path.at("d", -1) then - h.assert_array_eq_unordered[String](["5", "6"], entries) + h.assert_array_eq_unordered[String](["5"; "6"], entries) else h.fail("Unexpected dir: " + dir.path) end @@ -160,10 +160,10 @@ class iso _TestPathSplit is UnitTest ifdef windows then var path = "\\foo\\bar\\dir\\" let expect = [ - ("\\foo\\bar\\dir", ""), - ("\\foo\\bar", "dir"), - ("\\foo", "bar"), - (".", "foo"), + ("\\foo\\bar\\dir", "") + ("\\foo\\bar", "dir") + ("\\foo", "bar") + (".", "foo") ("", ".") ] for parts in expect.values() do @@ -176,10 +176,10 @@ class iso _TestPathSplit is UnitTest else var path = "/foo/bar/dir/" let expect = [ - ("/foo/bar/dir", ""), - ("/foo/bar", "dir"), - ("/foo", "bar"), - (".", "foo"), + ("/foo/bar/dir", "") + ("/foo/bar", "dir") + ("/foo", "bar") + (".", "foo") ("", ".") ] for parts in expect.values() do diff --git a/packages/glob/_test.pony b/packages/glob/_test.pony index 94f264afd8..df91ae6bea 100644 --- a/packages/glob/_test.pony +++ b/packages/glob/_test.pony @@ -99,14 +99,14 @@ class iso _TestFilter is UnitTest fun name(): String => "files/Glob.filter" fun apply(h: TestHelper) ? => - let m = Glob.filter([ "12/a/Bcd", "12/q/abd", "34/b/Befd"], "*/?/B*d") + let m = Glob.filter([ "12/a/Bcd"; "12/q/abd"; "34/b/Befd"], "*/?/B*d") h.assert_eq[USize](2, m.size()) h.assert_eq[String](m(0)._1, "12/a/Bcd") - h.assert_array_eq[String](["12", "a", "c"], m(0)._2) + h.assert_array_eq[String](["12"; "a"; "c"], m(0)._2) h.assert_eq[String](m(1)._1, "34/b/Befd") - h.assert_array_eq[String](["34", "b", "ef"], m(1)._2) + h.assert_array_eq[String](["34"; "b"; "ef"], m(1)._2) class iso _TestGlob is UnitTest fun name(): String => "files/FilePath.glob" @@ -118,10 +118,10 @@ class iso _TestGlob is UnitTest res fun apply(h: TestHelper) ? => - let top = _FileHelper.make_files(h, ["a/1", "a/2", "b", "c/1", "c/4"]) + let top = _FileHelper.make_files(h, ["a/1"; "a/2"; "b"; "c/1"; "c/4"]) try h.assert_array_eq_unordered[String]( - ["a/1", "c/1"], _rel(top, Glob.glob(top, "*/1"))) + ["a/1"; "c/1"], _rel(top, Glob.glob(top, "*/1"))) h.assert_array_eq_unordered[String]( Array[String], _rel(top, Glob.glob(top, "1"))) then @@ -138,7 +138,7 @@ class iso _TestIGlob is UnitTest res fun apply(h: TestHelper) ? => - let top = _FileHelper.make_files(h, ["a/1", "a/2", "b", "c/1", "c/4"]) + let top = _FileHelper.make_files(h, ["a/1"; "a/2"; "b"; "c/1"; "c/4"]) try Glob.iglob(top, "*/1", {(f: FilePath, matches: Array[String])(top, h) => try diff --git a/packages/itertools/_test.pony b/packages/itertools/_test.pony index 2949fc2723..47fd5289f1 100644 --- a/packages/itertools/_test.pony +++ b/packages/itertools/_test.pony @@ -38,19 +38,19 @@ class iso _TestChain is UnitTest fun apply(h: TestHelper) => None let input0: Array[String] = Array[String] - let input1 = ["a", "b", "c"] - let input2 = ["d", "e", "f"] - let expected = ["a", "b", "c", "d", "e", "f"] + let input1 = ["a"; "b"; "c"] + let input2 = ["d"; "e"; "f"] + let expected = ["a"; "b"; "c"; "d"; "e"; "f"] var actual = Array[String] - for x in Chain[String]([input1.values(), input2.values()].values()) do + for x in Chain[String]([input1.values(); input2.values()].values()) do actual.push(x) end h.assert_array_eq[String](expected, actual) actual.clear() - for x in Chain[String]([input0.values(), input1.values(), input2.values()]. + for x in Chain[String]([input0.values(); input1.values(); input2.values()]. values()) do actual.push(x) end @@ -58,7 +58,7 @@ class iso _TestChain is UnitTest h.assert_array_eq[String](expected, actual) actual.clear() - for x in Chain[String]([input1.values(), input2.values(), input0.values()]. + for x in Chain[String]([input1.values(); input2.values(); input0.values()]. values()) do actual.push(x) end @@ -73,7 +73,7 @@ class iso _TestChain is UnitTest h.assert_array_eq[String](input0, actual) actual.clear() - for x in Chain[String]([input0.values(), input0.values()].values()) do + for x in Chain[String]([input0.values(); input0.values()].values()) do actual.push(x) end @@ -89,7 +89,8 @@ class iso _TestChain is UnitTest h.assert_false(Chain[String](Array[Iterator[String]].values()).has_next()) - let chain = Chain[String]([input0.values(), input1.values(), input0.values()].values()) + let chain = Chain[String]( + [input0.values(); input1.values(); input0.values()].values()) h.assert_true(chain.has_next()) try chain.next() @@ -104,17 +105,17 @@ class iso _TestZip is UnitTest fun name(): String => "itertools/Zip" fun apply(h: TestHelper) => - let input1 = ["a", "b", "c"] - let input2 = [as U32: 1, 2, 3, 4] - let input3 = [as F32: 75.8, 90.1, 82.7, 13.4, 17.9] - let input4 = [as I32: 51, 62, 73, 84] - let input5 = [as USize: 14, 27, 39] - - let expected1 = ["a", "b", "c"] - let expected2 = [as U32: 1, 2, 3] - let expected3 = [as F32: 75.8, 90.1, 82.7] - let expected4 = [as I32: 51, 62, 73] - let expected5 = [as USize: 14, 27, 39] + let input1 = ["a"; "b"; "c"] + let input2 = [as U32: 1; 2; 3; 4] + let input3 = [as F32: 75.8; 90.1; 82.7; 13.4; 17.9] + let input4 = [as I32: 51; 62; 73; 84] + let input5 = [as USize: 14; 27; 39] + + let expected1 = ["a"; "b"; "c"] + let expected2 = [as U32: 1; 2; 3] + let expected3 = [as F32: 75.8; 90.1; 82.7] + let expected4 = [as I32: 51; 62; 73] + let expected5 = [as USize: 14; 27; 39] let actual1 = Array[String] let actual2 = Array[U32] @@ -144,7 +145,7 @@ class iso _TestRepeat is UnitTest fun apply(h: TestHelper) => let input = "a" - let expected = ["a", "a", "a"] + let expected = ["a"; "a"; "a"] var actual = Array[String] let repeater = Repeat[String]("a") @@ -160,8 +161,8 @@ class iso _TestTake is UnitTest fun apply(h: TestHelper) => let take: USize = 3 - let input = ["a", "b", "c", "d", "e"] - let expected = ["a", "b", "c"] + let input = ["a"; "b"; "c"; "d"; "e"] + let expected = ["a"; "b"; "c"] var actual = Array[String] for x in Take[String](input.values(), take) do @@ -174,8 +175,8 @@ class iso _TestCycle is UnitTest fun name(): String => "itertools/Cycle" fun apply(h: TestHelper) => - let input = ["a", "b", "c"] - let expected = ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"] + let input = ["a"; "b"; "c"] + let expected = ["a"; "b"; "c"; "a"; "b"; "c"; "a"; "b"; "c"; "a"] var actual: Array[String] = Array[String] let cycle = Cycle[String](input.values()) @@ -200,8 +201,8 @@ class iso _TestMapFn is UnitTest fun name(): String => "itertools/MapFn" fun apply(h: TestHelper) => - let input = ["a", "b", "c"] - let expected = ["ab", "bb", "cb"] + let input = ["a"; "b"; "c"] + let expected = ["ab"; "bb"; "cb"] let actual = Array[String] let fn = {(x: String): String => x + "b" } @@ -215,10 +216,10 @@ class iso _TestFilter is UnitTest fun name(): String => "itertools/Filter" fun apply(h: TestHelper) => - let input1 = ["ax", "bxx", "c", "dx", "exx", "f", "g", "hx"] - let input2 = ["ax", "bxx", "c", "dx", "exx", "f", "g"] - let input3 = ["c", "dx", "exx", "f", "g"] - let expected = ["c", "f", "g"] + let input1 = ["ax"; "bxx"; "c"; "dx"; "exx"; "f"; "g"; "hx"] + let input2 = ["ax"; "bxx"; "c"; "dx"; "exx"; "f"; "g"] + let input3 = ["c"; "dx"; "exx"; "f"; "g"] + let expected = ["c"; "f"; "g"] let actual = Array[String] let fn1 = {(x: String): Bool => x.size() == 1 } @@ -248,7 +249,7 @@ class iso _TestIterAll is UnitTest fun name(): String => "itertools/Iter.all" fun apply(h: TestHelper) ? => - let input = [as I64: 1, 3, 6, 7, 9] + let input = [as I64: 1; 3; 6; 7; 9] let is_positive = {(n: I64): Bool => n > 0 } h.assert_true(Iter[I64](input.values()).all(is_positive)) input(2) = -6 @@ -258,7 +259,7 @@ class iso _TestIterAny is UnitTest fun name(): String => "itertools/Iter.any" fun apply(h: TestHelper) ? => - let input = [as I64: -1, -3, 6, -7, -9] + let input = [as I64: -1; -3; 6; -7; -9] let is_positive = {(n: I64): Bool => n > 0 } h.assert_true(Iter[I64](input.values()).any(is_positive)) input(2) = -6 @@ -268,7 +269,7 @@ class iso _TestIterCollect is UnitTest fun name(): String => "itertools/Iter.collect" fun apply(h: TestHelper) => - let input = [as I64: 1, 2, 3, 4, 5] + let input = [as I64: 1; 2; 3; 4; 5] h.assert_array_eq[I64]( input, Iter[I64](input.values()).collect(Array[I64])) @@ -277,7 +278,7 @@ class iso _TestIterCount is UnitTest fun name(): String => "itertools/Iter.count" fun apply(h: TestHelper) => - let input1 = [as I64: 1, 2, 3, 4, 5] + let input1 = [as I64: 1; 2; 3; 4; 5] h.assert_eq[USize]( input1.size(), Iter[I64](input1.values()).count()) @@ -291,8 +292,8 @@ class iso _TestIterCycle is UnitTest fun name(): String => "itertools/Iter.cycle" fun apply(h: TestHelper) => - let input = ["a", "b", "c"] - let expected = ["a", "b", "c", "a", "b", "c", "a", "b", "c", "a"] + let input = ["a"; "b"; "c"] + let expected = ["a"; "b"; "c"; "a"; "b"; "c"; "a"; "b"; "c"; "a"] let actual: Array[String] = Array[String] let cycle = Iter[String](input.values()).cycle() @@ -317,8 +318,8 @@ class iso _TestIterEnum is UnitTest fun name(): String => "itertools/Iter.enum" fun apply(h: TestHelper) ? => - let input = ["a", "b", "c"] - let expected = [as (USize, String): (0, "a"), (1, "b"), (2, "c")] + let input = ["a"; "b"; "c"] + let expected = [as (USize, String): (0, "a"); (1, "b"); (2, "c")] let iter = Iter[String](input.values()).enum() @@ -334,10 +335,10 @@ class iso _TestIterFilter is UnitTest fun name(): String => "itertools/Iter.filter" fun apply(h: TestHelper) => - let input1 = ["ax", "bxx", "c", "dx", "exx", "f", "g", "hx"] - let input2 = ["ax", "bxx", "c", "dx", "exx", "f", "g"] - let input3 = ["c", "dx", "exx", "f", "g"] - let expected = ["c", "f", "g"] + let input1 = ["ax"; "bxx"; "c"; "dx"; "exx"; "f"; "g"; "hx"] + let input2 = ["ax"; "bxx"; "c"; "dx"; "exx"; "f"; "g"] + let input3 = ["c"; "dx"; "exx"; "f"; "g"] + let expected = ["c"; "f"; "g"] let actual = Array[String] let fn1 = {(x: String): Bool => x.size() == 1 } @@ -367,7 +368,7 @@ class iso _TestIterFind is UnitTest fun name(): String => "itertools/Iter.find" fun apply(h: TestHelper) ? => - let input = [as I64: 1, 2, 3, -4, 5] + let input = [as I64: 1; 2; 3; -4; 5] h.assert_error({()(input) ? => Iter[I64](input.values()).find({(x: I64): Bool => x == 0 }) }) @@ -386,7 +387,7 @@ class iso _TestIterFold is UnitTest fun name(): String => "itertools/Iter.fold" fun apply(h: TestHelper) ? => - let ns = [as I64: 1, 2, 3, 4, 5, 6] + let ns = [as I64: 1; 2; 3; 4; 5; 6] let fn = {(sum: I64, n: I64): I64 => sum + n } let sum = Iter[I64](ns.values()).fold[I64](fn, 0) h.assert_eq[I64](sum, 21) @@ -406,11 +407,11 @@ class iso _TestIterLast is UnitTest h.assert_eq[I64]( 1, Iter[I64](input2.values()).last()) - let input3 = [as I64: 1, 2] + let input3 = [as I64: 1; 2] h.assert_eq[I64]( 2, Iter[I64](input3.values()).last()) - let input4 = [as I64: 1, 2, 3] + let input4 = [as I64: 1; 2; 3] h.assert_eq[I64]( 3, Iter[I64](input4.values()).last()) @@ -419,8 +420,8 @@ class iso _TestIterMap is UnitTest fun name(): String => "itertools/Iter.map" fun apply(h: TestHelper) => - let input = ["a", "b", "c"] - let expected = ["ab", "bb", "cb"] + let input = ["a"; "b"; "c"] + let expected = ["ab"; "bb"; "cb"] let actual = Array[String] let fn = {(x: String): String => x + "b" } @@ -434,7 +435,7 @@ class iso _TestIterNth is UnitTest fun name(): String => "itertools/Iter.nth" fun apply(h: TestHelper) ? => - let input = [as USize: 1, 2, 3] + let input = [as USize: 1; 2; 3] h.assert_eq[USize]( 1, Iter[USize](input.values()).nth(1)) @@ -455,7 +456,7 @@ class iso _TestIterRun is UnitTest h.expect_action("3") h.expect_action("error") - let xs = [as I64: 1, 2, 3] + let xs = [as I64: 1; 2; 3] h.long_test(100_000_000) @@ -489,7 +490,7 @@ class iso _TestIterSkipWhile is UnitTest fun name(): String => "itertools/Iter.skip_while" fun apply(h: TestHelper) ? => - let input = [as I64: -1, 0, 1, 2, 3] + let input = [as I64: -1; 0; 1; 2; 3] h.assert_eq[I64]( 1, Iter[I64](input.values()).skip_while({(x: I64): Bool => x <= 0 }).next()) @@ -502,8 +503,8 @@ class iso _TestIterTake is UnitTest fun apply(h: TestHelper) => let take: USize = 3 - let input = ["a", "b", "c", "d", "e"] - let expected = ["a", "b", "c"] + let input = ["a"; "b"; "c"; "d"; "e"] + let expected = ["a"; "b"; "c"] var actual = Array[String] for x in Iter[String](input.values()).take(take) do @@ -516,9 +517,9 @@ class iso _TestIterTakeWhile is UnitTest fun name(): String => "itertools/Iter.take_while" fun apply(h: TestHelper) => - let input = [as I64: -1, 0, 1, 2, 3] + let input = [as I64: -1; 0; 1; 2; 3] h.assert_array_eq[I64]( - [as I64: -1, 0], + [as I64: -1; 0], Iter[I64](input.values()).take_while({(x: I64): Bool => x < 1 }) .collect(Array[I64])) h.assert_array_eq[I64]( @@ -534,17 +535,17 @@ class iso _TestIterZip is UnitTest fun name(): String => "itertools/Iter.zip" fun apply(h: TestHelper) => - let input1 = ["a", "b", "c"] - let input2 = [as U32: 1, 2, 3, 4] - let input3 = [as F32: 75.8, 90.1, 82.7, 13.4, 17.9] - let input4 = [as I32: 51, 62, 73, 84] - let input5 = [as USize: 14, 27, 39] - - let expected1 = ["a", "b", "c"] - let expected2 = [as U32: 1, 2, 3] - let expected3 = [as F32: 75.8, 90.1, 82.7] - let expected4 = [as I32: 51, 62, 73] - let expected5 = [as USize: 14, 27, 39] + let input1 = ["a"; "b"; "c"] + let input2 = [as U32: 1; 2; 3; 4] + let input3 = [as F32: 75.8; 90.1; 82.7; 13.4; 17.9] + let input4 = [as I32: 51; 62; 73; 84] + let input5 = [as USize: 14; 27; 39] + + let expected1 = ["a"; "b"; "c"] + let expected2 = [as U32: 1; 2; 3] + let expected3 = [as F32: 75.8; 90.1; 82.7] + let expected4 = [as I32: 51; 62; 73] + let expected5 = [as USize: 14; 27; 39] let actual1 = Array[String] let actual2 = Array[U32] diff --git a/packages/net/_test.pony b/packages/net/_test.pony index 38426c0fdc..d9c51bddc3 100644 --- a/packages/net/_test.pony +++ b/packages/net/_test.pony @@ -97,7 +97,7 @@ class _TestPong is UDPNotify let s = String.>append(consume data) _h.assert_eq[String box](s, "ping!") sock.writev( - recover val [[U8('p'), U8('o'), U8('n'), U8('g'), U8('!')]] end, + recover val [[U8('p'); U8('o'); U8('n'); U8('g'); U8('!')]] end, from) class iso _TestBroadcast is UnitTest @@ -290,7 +290,7 @@ class _TestTCPWritevNotifyClient is TCPConnectionNotify fun ref connected(conn: TCPConnection ref) => _h.complete_action("client connect") - conn.writev(recover ["hello", ", hello"] end) + conn.writev(recover ["hello"; ", hello"] end) fun ref connect_failed(conn: TCPConnection ref) => _h.fail_action("client connect") diff --git a/packages/options/_test.pony b/packages/options/_test.pony index 1f7d04e812..ff8ec668d7 100644 --- a/packages/options/_test.pony +++ b/packages/options/_test.pony @@ -19,7 +19,7 @@ class iso _TestLongOptions is UnitTest fun name(): String => "options/Options.longOptions" fun apply(h: TestHelper) => - let options = Options(["--none", "--i64", "12345", "--f64=67.890"]) + let options = Options(["--none"; "--i64"; "12345"; "--f64=67.890"]) var none: Bool = false var i64: I64 = -1 var f64: F64 = -1 @@ -47,7 +47,7 @@ class iso _TestShortOptions is UnitTest fun name(): String => "options/Options.shortOptions" fun apply(h: TestHelper) => - let options = Options(["-n", "-i", "12345", "-f67.890"]) + let options = Options(["-n"; "-i"; "12345"; "-f67.890"]) var none: Bool = false var i64: I64 = -1 var f64: F64 = -1 @@ -99,7 +99,7 @@ class iso _TestCombineShortArg is UnitTest fun name(): String => "options/Options.combineShortArg" fun apply(h: TestHelper) => - let options = Options(["-ab99", "-ac", "99"]) + let options = Options(["-ab99"; "-ac"; "99"]) var aaa: Bool = false var bbb: I64 = -1 var ccc: I64 = -1 @@ -127,7 +127,7 @@ class iso _TestArgLeadingDash is UnitTest fun name(): String => "options/Options.testArgLeadingDash" fun apply(h: TestHelper) => - let options = Options(["--aaa", "-2", "--bbb=-2"]) + let options = Options(["--aaa"; "-2"; "--bbb=-2"]) var aaa: I64 = -1 var bbb: I64 = -1 options diff --git a/packages/ponybench/_test.pony b/packages/ponybench/_test.pony index 69252055a2..bc1b2d763a 100644 --- a/packages/ponybench/_test.pony +++ b/packages/ponybench/_test.pony @@ -12,11 +12,11 @@ class iso _TestAutoOps is UnitTest fun apply(h: TestHelper) => let ao = _AutoOps(1_000_000_000, 100_000_000) let tests: Array[(U64, U64, U64)] = [ - (10, 1000, 1000), - (20, 1000, 2000), - (30, 1000, 3000), - (40, 1000, 5000), - (50, 1000, 5000), + (10, 1000, 1000) + (20, 1000, 2000) + (30, 1000, 3000) + (40, 1000, 5000) + (50, 1000, 5000) (60, 1000, 10000) ] for (ops, time, expected) in tests.values() do diff --git a/packages/ponybench/pony_bench.pony b/packages/ponybench/pony_bench.pony index 429e31628b..56d9ca59f6 100644 --- a/packages/ponybench/pony_bench.pony +++ b/packages/ponybench/pony_bench.pony @@ -114,14 +114,20 @@ actor PonyBench be _result(name: String, ops: U64, nspo: U64) => _remove(name) - let sl = [name, "\t", Format.int[U64](ops where width=10), "\t", - Format.int[U64](nspo where width=10), " ns/op"] + let sl = + [ name + "\t" + Format.int[U64](ops where width=10) + "\t" + Format.int[U64](nspo where width=10) + " ns/op" + ] _env.out.print(String.join(sl)) _next() be _failure(name: String, timeout: Bool) => _remove(name) - let sl = [ANSI.red(), "**** FAILED Benchmark: ", name] + let sl = [ANSI.red(); "**** FAILED Benchmark: "; name] if timeout then sl.push(" (timeout)") end diff --git a/packages/process/_test.pony b/packages/process/_test.pony index 9374b80075..4865c0d58e 100644 --- a/packages/process/_test.pony +++ b/packages/process/_test.pony @@ -177,7 +177,7 @@ class iso _TestExpect is UnitTest fun ref dispose(process: ProcessMonitor ref, child_exit_code: I32) => _h.assert_eq[I32](child_exit_code, 0) - _h.assert_array_eq[String](_out, ["he", "llo ", "th", "ere!"]) + _h.assert_array_eq[String](_out, ["he"; "llo "; "th"; "ere!"]) _h.complete(true) end end try diff --git a/packages/regex/_test.pony b/packages/regex/_test.pony index 3d202a67ba..619a1451d3 100644 --- a/packages/regex/_test.pony +++ b/packages/regex/_test.pony @@ -36,19 +36,19 @@ class iso _TestGroups is UnitTest h.assert_eq[String](m1(0), "123.456") h.assert_eq[String](m1(1), "123") h.assert_eq[String](m1(2), "456") - h.assert_array_eq[String](m1.groups(), ["123", "456"]) + h.assert_array_eq[String](m1.groups(), ["123"; "456"]) let m2 = r("123.") h.assert_eq[String](m2(0), "123.") h.assert_eq[String](m2(1), "123") h.assert_error({()? => m2(2) }) - h.assert_array_eq[String](m2.groups(), ["123", ""]) + h.assert_array_eq[String](m2.groups(), ["123"; ""]) let m3 = r(".456") h.assert_eq[String](m3(0), ".456") h.assert_error({()? => m3(1) }) h.assert_eq[String](m3(2), "456") - h.assert_array_eq[String](m3.groups(), ["", "456"]) + h.assert_array_eq[String](m3.groups(), [""; "456"]) class iso _TestEq is UnitTest """ @@ -68,10 +68,10 @@ class iso _TestSplit is UnitTest fun name(): String => "regex/Regex.split" fun apply(h: TestHelper) ? => - h.assert_array_eq[String](["ab", "cd", "ef"], + h.assert_array_eq[String](["ab"; "cd"; "ef"], Regex("\\d+").split("ab12cd34ef")) h.assert_array_eq[String](["abcdef"], Regex("\\d*").split("abcdef")) - h.assert_array_eq[String](["abc", "def"], Regex("\\d*").split("abc1def")) + h.assert_array_eq[String](["abc"; "def"], Regex("\\d*").split("abc1def")) class iso _TestError is UnitTest """ diff --git a/packages/serialise/_test.pony b/packages/serialise/_test.pony index a70fea0b9f..718512a6f7 100644 --- a/packages/serialise/_test.pony +++ b/packages/serialise/_test.pony @@ -132,25 +132,25 @@ class iso _TestArrays is UnitTest let serialise = SerialiseAuth(ambient) let deserialise = DeserialiseAuth(ambient) - let x1: Array[U128] = [1, 2, 3] + let x1: Array[U128] = [1; 2; 3] var sx = Serialised(serialise, x1) let y1 = sx(deserialise) as Array[U128] h.assert_true(x1 isnt y1) h.assert_array_eq[U128](x1, y1) - let x2: Array[Bool] = [true, false, true] + let x2: Array[Bool] = [true; false; true] sx = Serialised(serialise, x2) let y2 = sx(deserialise) as Array[Bool] h.assert_true(x2 isnt y2) h.assert_array_eq[Bool](x2, y2) - let x3: Array[U32] = [1, 2, 3] + let x3: Array[U32] = [1; 2; 3] sx = Serialised(serialise, x3) let y3 = sx(deserialise) as Array[U32] h.assert_true(x3 isnt y3) h.assert_array_eq[U32](x3, y3) - let x4: Array[(U16, Bool)] = [(1, true), (2, false), (3, true)] + let x4: Array[(U16, Bool)] = [(1, true); (2, false); (3, true)] sx = Serialised(serialise, x4) let y4 = sx(deserialise) as Array[(U16, Bool)] h.assert_true(x4 isnt y4) @@ -162,14 +162,14 @@ class iso _TestArrays is UnitTest i = i + 1 end - let x5: Array[String] = ["hi", "there", "folks"] + let x5: Array[String] = ["hi"; "there"; "folks"] sx = Serialised(serialise, x5) let y5 = sx(deserialise) as Array[String] h.assert_true(x5 isnt y5) h.assert_array_eq[String](x5, y5) let x6: Array[_StructWords] = - [as _StructWords: _StructWords, _StructWords, _StructWords] + [as _StructWords: _StructWords; _StructWords; _StructWords] sx = Serialised(serialise, x6) let y6 = sx(deserialise) as Array[_StructWords] h.assert_true(x6 isnt y6) diff --git a/packages/strings/_test.pony b/packages/strings/_test.pony index 6fe4d7a5b8..3d662387ab 100644 --- a/packages/strings/_test.pony +++ b/packages/strings/_test.pony @@ -16,10 +16,11 @@ class iso _TestStringsCommonPrefix is UnitTest fun apply(h: TestHelper) => h.assert_eq[String]("", CommonPrefix(Array[String])) h.assert_eq[String]("", CommonPrefix([""])) - h.assert_eq[String]("", CommonPrefix(["", "asdf"])) - h.assert_eq[String]("", CommonPrefix(["qwer", "asdf"])) - h.assert_eq[String]("", CommonPrefix(["asdf", "asdf", "qwer"])) - h.assert_eq[String]("asdf", CommonPrefix(["asdf", "asdf"])) - h.assert_eq[String]("as", CommonPrefix(["asdf", "asdf", "aser"])) - h.assert_eq[String]("a", CommonPrefix(["a", "asdf", "asdf", "aser"])) - h.assert_eq[String]("12", CommonPrefix([as Stringable: U32(1234), U32(12)])) + h.assert_eq[String]("", CommonPrefix([""; "asdf"])) + h.assert_eq[String]("", CommonPrefix(["qwer"; "asdf"])) + h.assert_eq[String]("", CommonPrefix(["asdf"; "asdf"; "qwer"])) + h.assert_eq[String]("asdf", CommonPrefix(["asdf"; "asdf"])) + h.assert_eq[String]("as", CommonPrefix(["asdf"; "asdf"; "aser"])) + h.assert_eq[String]("a", CommonPrefix(["a"; "asdf"; "asdf"; "aser"])) + h.assert_eq[String]("12", CommonPrefix( + [as Stringable: U32(1234); U32(12)])) diff --git a/src/libponyc/ast/parser.c b/src/libponyc/ast/parser.c index dd2b8313a8..cf53d0d3e2 100644 --- a/src/libponyc/ast/parser.c +++ b/src/libponyc/ast/parser.c @@ -394,8 +394,7 @@ DEF(array); AST_NODE(TK_ARRAY); SKIP(NULL, TK_LSQUARE, TK_LSQUARE_NEW); OPT RULE("element type", arraytype); - RULE("array element", rawseq); - WHILE(TK_COMMA, RULE("array element", rawseq)); + RULE("array elements", rawseq); TERMINATE("array literal", TK_RSQUARE); DONE(); @@ -405,8 +404,7 @@ DEF(nextarray); AST_NODE(TK_ARRAY); SKIP(NULL, TK_LSQUARE_NEW); OPT RULE("element type", arraytype); - RULE("array element", rawseq); - WHILE(TK_COMMA, RULE("array element", rawseq)); + RULE("array elements", rawseq); TERMINATE("array literal", TK_RSQUARE); DONE(); diff --git a/src/libponyc/expr/array.c b/src/libponyc/expr/array.c index d2d3dd061a..b74795bf20 100644 --- a/src/libponyc/expr/array.c +++ b/src/libponyc/expr/array.c @@ -14,11 +14,11 @@ bool expr_array(pass_opt_t* opt, ast_t** astp) { ast_t* ast = *astp; - size_t size = ast_childcount(ast) - 1; ast_t* type = NULL; bool told_type = false; - AST_GET_CHILDREN(ast, type_spec, first_child); + AST_GET_CHILDREN(ast, type_spec, elements); + size_t size = ast_childcount(elements); if(ast_id(type_spec) != TK_NONE) { @@ -26,7 +26,7 @@ bool expr_array(pass_opt_t* opt, ast_t** astp) told_type = true; } - for(ast_t* ele = first_child; ele != NULL; ele = ast_sibling(ele)) + for(ast_t* ele = ast_child(elements); ele != NULL; ele = ast_sibling(ele)) { ast_t* c_type = ast_type(ele); @@ -112,7 +112,9 @@ bool expr_array(pass_opt_t* opt, ast_t** astp) ast_swap(ast, call); *astp = call; - for(ast_t* ele = ast_childidx(ast, 1); ele != NULL; ele = ast_sibling(ele)) + elements = ast_childidx(ast, 1); + + for(ast_t* ele = ast_child(elements); ele != NULL; ele = ast_sibling(ele)) { BUILD(append_chain, ast, NODE(TK_CHAIN, TREE(*astp) ID("push"))); diff --git a/src/libponyc/expr/control.c b/src/libponyc/expr/control.c index 819db83769..1889fd884e 100644 --- a/src/libponyc/expr/control.c +++ b/src/libponyc/expr/control.c @@ -14,6 +14,12 @@ bool expr_seq(pass_opt_t* opt, ast_t* ast) { + ast_t* parent = ast_parent(ast); + + // This sequence will be handled when the array literal is handled. + if(ast_id(parent) == TK_ARRAY) + return true; + bool ok = true; // Any expression other than the last that is still literal is an error @@ -47,8 +53,6 @@ bool expr_seq(pass_opt_t* opt, ast_t* ast) if(!ast_has_scope(ast)) return ok; - ast_t* parent = ast_parent(ast); - switch(ast_id(parent)) { case TK_TRY: diff --git a/src/libponyc/expr/literal.c b/src/libponyc/expr/literal.c index 3690b470cf..3a937d0c93 100644 --- a/src/libponyc/expr/literal.c +++ b/src/libponyc/expr/literal.c @@ -589,16 +589,15 @@ static bool coerce_group(ast_t** astp, ast_t* target_type, lit_chain_t* chain, chain_add(chain, &link, cardinality); - // Process each group element separately - ast_t* p = ast_child(literal_expr); - if(ast_id(literal_expr) == TK_ARRAY) { - // The first child of an array AST is the forced type, skip it - p = ast_sibling(p); + // The first child of an array AST is the forced type, the second child is + // the sequence of elements. + literal_expr = ast_childidx(literal_expr, 1); } - for(; p != NULL; p = ast_sibling(p)) + // Process each group element separately + for(ast_t* p = ast_child(literal_expr); p != NULL; p = ast_sibling(p)) { ast_t* p_type = ast_type(p); diff --git a/test/libponyc/badpony.cc b/test/libponyc/badpony.cc index a44edc0401..2bf8da7621 100644 --- a/test/libponyc/badpony.cc +++ b/test/libponyc/badpony.cc @@ -310,7 +310,7 @@ TEST_F(BadPonyTest, IndexArrayWithBrackets) const char* src = "actor Main\n" "new create(env: Env) =>\n" - "let xs = [as I64: 1, 2, 3]\n" + "let xs = [as I64: 1; 2; 3]\n" "xs[1]"; TEST_ERRORS_1(src, "Value formal parameters not yet supported"); diff --git a/test/libponyc/literal_inference.cc b/test/libponyc/literal_inference.cc index ff66383e23..84f73f30d4 100644 --- a/test/libponyc/literal_inference.cc +++ b/test/libponyc/literal_inference.cc @@ -34,12 +34,12 @@ class LiteralTest : public PassTest } } - void check_type(const char* type_name, token_id tk_type, ast_t* ast) + void check_type(const char* type_name, token_id tk_type, ast_t* ast) { ast_t* type = ast_type(ast); ASSERT_ID(tk_type, type); - switch(tk_type) + switch(tk_type) { case TK_NOMINAL: ASSERT_STREQ(type_name, ast_name(ast_childidx(type, 1))); // Child index 1 of a nominal is the type name @@ -281,7 +281,7 @@ TEST_F(LiteralTest, CantInfer_Array_UnambiguousUnion ) TEST_F(LiteralTest, CantInfer_Match_LiteralMatchValue ) { - const char* src = + const char* src = "class Foo10c\n" " fun test(): Bool => \n" " match 8\n" @@ -294,7 +294,7 @@ TEST_F(LiteralTest, CantInfer_Match_LiteralMatchValue ) TEST_F(LiteralTest, CantInfer_Match_InvalidElse) { - const char* src = + const char* src = "class Foo11c\n" " fun test(q: Bool): I16 => \n" " match q\n" @@ -310,13 +310,13 @@ TEST_F(LiteralTest, CantInfer_Match_InvalidElse) TEST_F(LiteralTest, CantInfer_Literal_Unused) { - const char* src = + const char* src = "class Foo12c\n" " fun test(q: Bool): F64 ? => 79; error\n"; TEST_ERROR(src); } - + TEST_F(LiteralTest, CantInfer_While_InvalidReturnValue) { @@ -331,7 +331,7 @@ TEST_F(LiteralTest, CantInfer_While_InvalidReturnValue) TEST_ERROR(src); } - + TEST_F(LiteralTest, CantInfer_While_InvalidElseValue ) { @@ -460,9 +460,9 @@ TEST_F(LiteralTest, Let_TupleOfGeneric) "class Foo[A: U8, B: U32]\n" " new create() =>\n" " (let x: A, let y: A) = (16, 32)"; - + TEST_COMPILE(src); - + DO(check_type("A", TK_TYPEPARAMREF, numeric_literal(16))); DO(check_type("A", TK_TYPEPARAMREF, numeric_literal(32))); } @@ -734,7 +734,7 @@ TEST_F(LiteralTest, Array_ParameterOfArrayOfUnion) { const char* src = "class Foo4a\n" - " fun run() => test([8, \"\"])\n" + " fun run() => test([8; \"\"])\n" " fun test(a: Array[ (String | I32) ] ): Bool => true\n"; TEST_COMPILE(src); From 01fc66ce94c050a366daa0244d5d24cd08a3a57b Mon Sep 17 00:00:00 2001 From: sylvanc Date: Fri, 24 Mar 2017 20:06:34 +0000 Subject: [PATCH 2/3] remove space --- packages/glob/_test.pony | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/glob/_test.pony b/packages/glob/_test.pony index df91ae6bea..a3a80bbe41 100644 --- a/packages/glob/_test.pony +++ b/packages/glob/_test.pony @@ -99,7 +99,7 @@ class iso _TestFilter is UnitTest fun name(): String => "files/Glob.filter" fun apply(h: TestHelper) ? => - let m = Glob.filter([ "12/a/Bcd"; "12/q/abd"; "34/b/Befd"], "*/?/B*d") + let m = Glob.filter(["12/a/Bcd"; "12/q/abd"; "34/b/Befd"], "*/?/B*d") h.assert_eq[USize](2, m.size()) h.assert_eq[String](m(0)._1, "12/a/Bcd") From be0f9df5934bf9f5c4ca7cea583f064b8b3bc433 Mon Sep 17 00:00:00 2001 From: sylvanc Date: Fri, 24 Mar 2017 20:07:06 +0000 Subject: [PATCH 3/3] update pony.g --- pony.g | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pony.g b/pony.g index 04ec4c779d..51235cbd3f 100644 --- a/pony.g +++ b/pony.g @@ -192,7 +192,7 @@ nextatom | 'this' | literal | LPAREN_NEW rawseq tuple? ')' - | LSQUARE_NEW ('as' type ':')? rawseq (',' rawseq)* ']' + | LSQUARE_NEW ('as' type ':')? rawseq ']' | 'object' ('\\' ID (',' ID)* '\\')? cap? ('is' type)? members 'end' | '{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap? | 'lambda' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq 'end' @@ -205,7 +205,7 @@ atom | 'this' | literal | ('(' | LPAREN_NEW) rawseq tuple? ')' - | ('[' | LSQUARE_NEW) ('as' type ':')? rawseq (',' rawseq)* ']' + | ('[' | LSQUARE_NEW) ('as' type ':')? rawseq ']' | 'object' ('\\' ID (',' ID)* '\\')? cap? ('is' type)? members 'end' | '{' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq '}' cap? | 'lambda' ('\\' ID (',' ID)* '\\')? cap? ID? typeparams? ('(' | LPAREN_NEW) params? ')' lambdacaptures? (':' type)? '?'? '=>' rawseq 'end'