From 17b154da4392634a706b9b1cac73ba7a6ecc30ab Mon Sep 17 00:00:00 2001 From: Vic Nightfall Date: Wed, 7 Feb 2024 21:25:59 +0100 Subject: [PATCH] Work on the test cases --- src/testrunner.pr | 2 +- std/process.pr | 2 +- std/shared.pr | 14 ++-- test/runtime/test_vector.pr | 8 +-- test/test_compiler.pr | 123 +++++++++++++++++------------------- test/test_lexer.pr | 68 ++++++++++---------- test/test_map.pr | 2 +- test/test_parser.pr | 4 +- test/test_runtime.pr | 22 +++---- test/test_strings.pr | 4 +- version | 2 +- 11 files changed, 122 insertions(+), 129 deletions(-) diff --git a/src/testrunner.pr b/src/testrunner.pr index f946efad..96373969 100644 --- a/src/testrunner.pr +++ b/src/testrunner.pr @@ -103,7 +103,7 @@ if runner { test_env.err = *get_stderr test_env.assertion_handler = *assertion_handler - let test = symbol.value !(def (*runtime::TestEnvironment) -> ()) + let test = symbol.value !(def *runtime::TestEnvironment -> []) test(*test_env) flush(std::stdout()) diff --git a/std/process.pr b/std/process.pr index 7941fde3..71284f01 100644 --- a/std/process.pr +++ b/std/process.pr @@ -152,7 +152,7 @@ import std } export def wait(process: *Process, timeout: ulong = -1) { - var pfd = [process.fd !int, POLLIN, 0] !linux::s_pollfd; + var pfd = [fd = process.fd !int, events = POLLIN, revents = 0] !linux::s_pollfd; if linux::poll(*pfd, 1, timeout !int) == 0 { return } diff --git a/std/shared.pr b/std/shared.pr index aab24f16..1c5c793a 100644 --- a/std/shared.pr +++ b/std/shared.pr @@ -106,7 +106,7 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) { if init { let main_sym = find_symbol(*library, "main::__main__::([[char]])") if main_sym.exists { - let main = main_sym.get().value !(def ([[char]]) -> ()) + let main = main_sym.get().value !(def ([[char]]) -> []) // FIXME Pass in actual command line arguments let args = zero_allocate(type [char], 0) main(args) @@ -121,7 +121,7 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) { if finalize { let finalizer_sym = find_symbol(library, "main::__finalizer__::()") if finalizer_sym.exists { - let finalizer = finalizer_sym.get().value !(def () -> ()) + let finalizer = finalizer_sym.get().value !(def -> []) finalizer() } } @@ -231,15 +231,15 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) { } let library = [ - path, - handle, - symbols.to_array() + path = path, + handle = handle, + symbols = symbols.to_array() ] !Library if init { let main_sym = find_symbol(*library, "main::__main__::([[char]])") if main_sym.exists { - let main = main_sym.get().value !(def ([[char]]) -> ()) + let main = main_sym.get().value !(def ([[char]]) -> []) // FIXME Pass in actual command line arguments let args = zero_allocate(type [char], 0) main(args) @@ -253,7 +253,7 @@ export def find_symbol(library: *Library, name: String) -> Optional(Symbol) { if finalize { let finalizer_sym = find_symbol(library, "main::__finalizer__::()") if finalizer_sym.exists { - let finalizer = finalizer_sym.get().value !(def () -> ()) + let finalizer = finalizer_sym.get().value !(def -> []) finalizer() } } diff --git a/test/runtime/test_vector.pr b/test/runtime/test_vector.pr index 1d17a9d4..65f46304 100644 --- a/test/runtime/test_vector.pr +++ b/test/runtime/test_vector.pr @@ -80,12 +80,12 @@ def push(vec: &Vector, elem: &) { def test_vector { - let s: &S = [0] !S + let s: &S = [a = 0] !S let vec = make() vec.push(s) - vec.push([20] !S) - vec.push([30] !S) - vec.push([40] !S) + vec.push([a = 20] !S) + vec.push([a = 30] !S) + vec.push([a = 40] !S) let vec2 = copy(vec) diff --git a/test/test_compiler.pr b/test/test_compiler.pr index fb9ca4d9..f36b5c52 100644 --- a/test/test_compiler.pr +++ b/test/test_compiler.pr @@ -227,10 +227,10 @@ def #test test_vardecl { let baz, (bar) = 0, 1 """ var res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "byte" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "long" - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][2]["left"][1]["value"]["type_tag"]["name"].as_string() == "long" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "byte" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "long" + assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(2)("left")(1)("value")("type_tag")("name").as_string() == "long" } def #test test_vardecl_fail { @@ -308,11 +308,11 @@ def #test test_literals { let v5 = false """ var res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[char]" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "char" - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "double" - assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[char]" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "char" + assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "double" + assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "bool" } def #test test_switch { @@ -388,13 +388,13 @@ def #test test_operators { """ let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][5]["left"][0]["value"]["type_tag"]["name"].as_string() == "long" - assert res["body"][6]["left"][0]["value"]["type_tag"]["name"].as_string() == "long" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(5)("left")(0)("value")("type_tag")("name").as_string() == "long" + assert res("body")(6)("left")(0)("value")("type_tag")("name").as_string() == "long" } def #test test_operators_fail { @@ -586,21 +586,21 @@ def #test test_struct { } """ let res = compile(str) - let A = res["body"][0]["right"][0]["type_tag"] - assert A["size"].as_double() == 24 - assert A["align"].as_double() == 8 + let A = res("body")(0)("right")(0)("type_tag") + assert A("size").as_double() == 24 + assert A("align").as_double() == 8 - let B = res["body"][1]["right"][0]["type_tag"] - assert B["size"].as_double() == 4 - assert B["align"].as_double() == 2 + let B = res("body")(1)("right")(0)("type_tag") + assert B("size").as_double() == 4 + assert B("align").as_double() == 2 - let C = res["body"][2]["right"][0]["type_tag"] - assert C["size"].as_double() == 8 - assert C["align"].as_double() == 4 + let C = res("body")(2)("right")(0)("type_tag") + assert C("size").as_double() == 8 + assert C("align").as_double() == 4 - let D = res["body"][3]["right"][0]["type_tag"] - assert D["size"].as_double() == 8 - assert D["align"].as_double() == 8 + let D = res("body")(3)("right")(0)("type_tag") + assert D("size").as_double() == 8 + assert D("align").as_double() == 8 } def #test test_struct_lit { @@ -628,12 +628,12 @@ def #test test_struct_lit { let g = [b = [a = e] !A, c = f] !B def ret_a -> A { - return {10} + return [a = 10] } let h: A = {10} var i: A - i = {10} + i = [a = 10] type C = struct { a: int @@ -765,9 +765,9 @@ def #test test_pointers { """ let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int" - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "*int" + assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int" } def #test test_pointers_fail { @@ -803,15 +803,15 @@ def #test test_ref { let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "&" - assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int" - assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int" - assert res["body"][5]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int" - assert res["body"][6]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][7]["left"][0]["value"]["type_tag"]["name"].as_string() == "&int" - assert res["body"][8]["left"][0]["value"]["type_tag"]["name"].as_string() == "&float" - assert res["body"][9]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "&int" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "&" + assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "&int" + assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "&int" + assert res("body")(5)("left")(0)("value")("type_tag")("name").as_string() == "&int" + assert res("body")(6)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(7)("left")(0)("value")("type_tag")("name").as_string() == "&int" + assert res("body")(8)("left")(0)("value")("type_tag")("name").as_string() == "&float" + assert res("body")(9)("left")(0)("value")("type_tag")("name").as_string() == "*int" } def #test test_convert { @@ -835,14 +835,14 @@ def #test test_convert { """ let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "float" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "float" - assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "uint" - assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool" - assert res["body"][5]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool" - assert res["body"][6]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int" - assert res["body"][7]["left"][0]["value"]["type_tag"]["name"].as_string() == "bool" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "float" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "float" + assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "uint" + assert res("body")(4)("left")(0)("value")("type_tag")("name").as_string() == "bool" + assert res("body")(5)("left")(0)("value")("type_tag")("name").as_string() == "bool" + assert res("body")(6)("left")(0)("value")("type_tag")("name").as_string() == "*int" + assert res("body")(7)("left")(0)("value")("type_tag")("name").as_string() == "bool" } def #test test_member_access { @@ -857,26 +857,19 @@ def #test test_member_access { """ let res = compile(str) - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "double" + assert res("body")(2)("left")(0)("value")("type_tag")("name").as_string() == "int" + assert res("body")(3)("left")(0)("value")("type_tag")("name").as_string() == "double" } def #test test_array_subscript { let str = """ var a: [4; int] let b = a(2) - - var c = 10 - var d = *c - let e = d(2) """ let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[4; int]" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][2]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" - assert res["body"][3]["left"][0]["value"]["type_tag"]["name"].as_string() == "*int" - assert res["body"][4]["left"][0]["value"]["type_tag"]["name"].as_string() == "int" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[4; int]" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "int" } def #test test_array_lit { @@ -886,8 +879,8 @@ def #test test_array_lit { """ let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[4; int]" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "[int]" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[4; int]" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "[int]" } def #test test_array_inference { @@ -897,8 +890,8 @@ def #test test_array_inference { """ let res = compile(str) - assert res["body"][0]["left"][0]["value"]["type_tag"]["name"].as_string() == "[4; int]" - assert res["body"][1]["left"][0]["value"]["type_tag"]["name"].as_string() == "[int]" + assert res("body")(0)("left")(0)("value")("type_tag")("name").as_string() == "[4; int]" + assert res("body")(1)("left")(0)("value")("type_tag")("name").as_string() == "[int]" } def #test test_array_inference_fail { diff --git a/test/test_lexer.pr b/test/test_lexer.pr index b0d36cf6..fe67fce2 100644 --- a/test/test_lexer.pr +++ b/test/test_lexer.pr @@ -13,42 +13,42 @@ def #test test_empty_file { } def #test test_float_literal { - assert lex("123.45678")[0] == json::parse("""{\ + assert lex("123.45678")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 123.45678 }""") - assert lex(".5")[0] == json::parse("""{\ + assert lex(".5")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 0.5 }""") - assert lex("10.")[0] == json::parse("""{\ + assert lex("10.")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 10 }""") - assert lex("10E10")[0] == json::parse("""{\ + assert lex("10E10")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 100000000000 }""") - assert lex("10.e10")[0] == json::parse("""{\ + assert lex("10.e10")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 100000000000 }""") - assert lex("10E+10")[0] == json::parse("""{\ + assert lex("10E+10")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 100000000000 }""") - assert lex("10E-5")[0] == json::parse("""{\ + assert lex("10E-5")(0) == json::parse("""{\ "kind": "FLOAT", "line": 0, "column": 0, "value": 0.0001 }""") } def #test test_int_literal { - assert lex("156")[0] == json::parse("""{\ + assert lex("156")(0) == json::parse("""{\ "kind": "INTEGER", "line": 0, "column": 0, "value": 156 }""") - assert lex("0b100100")[0] == json::parse("""{\ + assert lex("0b100100")(0) == json::parse("""{\ "kind": "INTEGER", "line": 0, "column": 0, "value": 36 }""") - assert lex("0xDEADBABE")[0] == json::parse("""{\ + assert lex("0xDEADBABE")(0) == json::parse("""{\ "kind": "INTEGER", "line": 0, "column": 0, "value": 3735927486 }""") - assert lex("0o172")[0] == json::parse("""{\ + assert lex("0o172")(0) == json::parse("""{\ "kind": "INTEGER", "line": 0, "column": 0, "value": 122 }""") } def #test test_char_literal { - assert lex("'A'")[0] == json::parse("""{\ + assert lex("'A'")(0) == json::parse("""{\ "kind": "CHAR", "line": 0, "column": 0, "value": 65 }""") assert lex("'A' 'B'") == json::parse("""[\ @@ -58,27 +58,27 @@ def #test test_char_literal { { "kind": "EOF", "line": 0, "column": 6 } ]""") - assert lex("'\\a'")[0] == json::parse("""{\ + assert lex("'\\a'")(0) == json::parse("""{\ "kind": "CHAR", "line": 0, "column": 0, "value": 7 }""") - assert lex("'\\xFF'")[0] == json::parse("""{\ + assert lex("'\\xFF'")(0) == json::parse("""{\ "kind": "CHAR", "line": 0, "column": 0, "value": 255 }""") } def #test test_char_literal_error { - assert lex("'A")[0] == json::parse("""{\ + assert lex("'A")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Unexpected end of file while parsing character" }""") - assert lex("'\\d'")[0] == json::parse("""{\ + assert lex("'\\d'")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Invalid escape sequence" }""") - assert lex("'\\x'")[0] == json::parse("""{\ + assert lex("'\\x'")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Invalid escape sequence" }""") } def #test test_string_literal { - assert lex("\"this is a test\"")[0] == json::parse("""{\ + assert lex("\"this is a test\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "this is a test" }""") @@ -89,44 +89,44 @@ def #test test_string_literal { { "kind": "EOF", "line": 0, "column": 12 } ]""") - assert lex("\"\\a\\b\\f\\n\\r\\t\\v\\'\\\"\\\\\"")[0] == json::parse("""{\ + assert lex("\"\\a\\b\\f\\n\\r\\t\\v\\'\\\"\\\\\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "\\u0007\\u0008\\u000C\\u000A\\u000D\\u0009\\u000B\\u0027\\u0022\\u005C" }""") - assert lex("\"\\xFF\"")[0] == json::parse("""{\ + assert lex("\"\\xFF\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "\xFF" }""") - assert lex("\"\\u01FF\"")[0] == json::parse("""{\ + assert lex("\"\\u01FF\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "\u01FF" }""") - assert lex("\"\\u88AA\"")[0] == json::parse("""{\ + assert lex("\"\\u88AA\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "\u88AA" }""") - assert lex("\"\\U0010FFFF\"")[0] == json::parse("""{\ + assert lex("\"\\U0010FFFF\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "\U0010FFFF" }""") - assert lex("\"\n\n\"")[0] == json::parse("""{\ + assert lex("\"\n\n\"")(0) == json::parse("""{\ "kind": "STRING", "line": 0, "column": 0, "value": "\\n\\n" }""") } def #test test_string_literal_error { - assert lex("\"this is a test")[0] == json::parse("""{\ + assert lex("\"this is a test")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Unexpected end of file while parsing string literal" }""") - assert lex("\"test \\d \"")[0] == json::parse("""{\ + assert lex("\"test \\d \"")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Invalid escape sequence" }""") - assert lex("\"\\UGHRR\"")[0] == json::parse("""{\ + assert lex("\"\\UGHRR\"")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Invalid escape sequence" }""") - assert lex("\"\\UFF0000FF\"")[0] == json::parse("""{\ + assert lex("\"\\UFF0000FF\"")(0) == json::parse("""{\ "kind": "ERROR", "line": 0, "column": 0, "value": "Invalid unicode sequence" }""") } def #test test_identifier { - assert lex("foo_bar")[0] == json::parse("""{\ + assert lex("foo_bar")(0) == json::parse("""{\ "kind": "IDENTIFIER", "line": 0, "column": 0, "value": "foo_bar" }""") @@ -145,16 +145,16 @@ def #test test_identifier { ]""") } def #test test_pragma { - assert lex("#union")[0] == json::parse("""{\ + assert lex("#union")(0) == json::parse("""{\ "kind": "PRAGMA", "line": 0, "column": 0, "value": "#union" }""") - assert lex("##compiler_dep")[0] == json::parse("""{\ + assert lex("##compiler_dep")(0) == json::parse("""{\ "kind": "PRAGMA", "line": 0, "column": 0, "value": "##compiler_dep" }""") } def #test test_comment { - assert lex("//This is a test")[0] == json::parse("""{\ + assert lex("//This is a test")(0) == json::parse("""{\ "kind": "COMMENT", "line": 0, "column": 0, "value": "//This is a test" }""") @@ -168,11 +168,11 @@ def #test test_comment { { "kind": "COMMENT", "line": 1, "column": 16, "value": "//Test" }, { "kind": "EOF", "line": 1, "column": 21 } }]""") - assert lex("/*This*/")[0] == json::parse("""{\ + assert lex("/*This*/")(0) == json::parse("""{\ "kind": "COMMENT", "line": 0, "column": 0, "value": "/*This*/" }""") - assert lex("/*Nested/*Comment*/*/")[0] == json::parse("""{\ + assert lex("/*Nested/*Comment*/*/")(0) == json::parse("""{\ "kind": "COMMENT", "line": 0, "column": 0, "value": "/*Nested/*Comment*/*/" }""") } diff --git a/test/test_map.pr b/test/test_map.pr index 781e75cb..e032cc6a 100644 --- a/test/test_map.pr +++ b/test/test_map.pr @@ -45,7 +45,7 @@ def #test test_map_resize { assert m("4") == 4 } -def is_in(array: &(Str), key: String) -> bool { +def is_in(array: &[Str], key: String) -> bool { for var i in 0..array.size { let value = array(i) if value == key { diff --git a/test/test_parser.pr b/test/test_parser.pr index d26c4a77..3c790e71 100644 --- a/test/test_parser.pr +++ b/test/test_parser.pr @@ -7,10 +7,10 @@ def parse(str: String) -> &Json { def program(jsn: &Json) -> &Json { let obj = json::make_object() - obj["kind"] = "Program" + obj("kind") = "Program" let body = json::make_array() body.push(jsn) - obj["body"] = body + obj("body") = body return obj } diff --git a/test/test_runtime.pr b/test/test_runtime.pr index 114f201a..577b43be 100644 --- a/test/test_runtime.pr +++ b/test/test_runtime.pr @@ -76,7 +76,7 @@ def #test test_print { print("Hello World ", 1, " ", 'x', " ", 10.5, " ", b, "\n") error("Hello World ", 1, " ", 'x', " ", 10.5, " ", b, "\n") - let point: Point = {10, 20} + let point: Point = [x = 10, y = 20] print(point, "\n") let array = [1, 2, 3, 4] @@ -291,9 +291,9 @@ def #test test_structs { } def test_structs { - let s = { + let s = [ c = 10 - } !Struct + ] !Struct assert s.a == null assert s.c == 10 assert s.b == 0 @@ -312,14 +312,14 @@ def #test test_unions { } def test_unions { - let u = { - "some string" - } !Union + let u = [ + a = "some string" + ] !Union print(u, "\n") - let u2 = { + let u2 = [ b = 20 - } !Union + ] !Union u2.b = 120 print(u2.c, "\n") @@ -464,7 +464,7 @@ def #test test_ucs { def inc(a: int) -> int { return a + 1} def test_ucs { - let s: Struct2 = { 10, null } + let s: Struct2 = [a = 10, t = null] assert s.function() == 10 assert s.function.inc == 11 @@ -491,9 +491,9 @@ def #test test_anonymous { def test_anonymous { var s: Struct3 - s = {10, {20, 30}} + s = [a = 10, b = [c = 20, d = 30]] s.a = 10 - s.b = {20, 30} + s.b = [c = 20, d = 30] s.e = 0x4034800000000000 print(s.f, "\n") diff --git a/test/test_strings.pr b/test/test_strings.pr index d13e5345..d39b2ec9 100644 --- a/test/test_strings.pr +++ b/test/test_strings.pr @@ -96,7 +96,7 @@ type MyString = struct { str: Str } -export def get_item(s: &MyString, index: size_t) -> char { +export def apply(s: &MyString, index: size_t) -> char { return s.str(index) } export def length(s: &MyString) -> size_t { @@ -104,7 +104,7 @@ export def length(s: &MyString) -> size_t { } def #test test_custom_str { - let a: MyString = ["some string"] !MyString + let a: MyString = [str = "some string"] !MyString let s: String = a let slc = s.slice(0, 4) let sbs = s.substring(0, 4) diff --git a/version b/version index 47322021..5fb6fa47 100644 --- a/version +++ b/version @@ -1 +1 @@ -VERSION=0.3.9 \ No newline at end of file +VERSION=0.3.10 \ No newline at end of file