From ee6b23c2a780522c1a4ecf31eda44bf883c98954 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 18 Mar 2022 23:32:06 +0200 Subject: [PATCH] toml: use toml.parse_text and toml.parse_file in the tests --- examples/toml.v | 2 +- vlib/toml/README.md | 9 +++--- .../toml/tests/array_of_tables_1_level_test.v | 2 +- .../toml/tests/array_of_tables_2_level_test.v | 12 ++++---- vlib/toml/tests/array_of_tables_array_test.v | 2 +- .../tests/array_of_tables_edge_case_1_test.v | 2 +- .../tests/array_of_tables_edge_case_2_test.v | 15 ++++------ vlib/toml/tests/compact_test.v | 2 +- vlib/toml/tests/crlf_test.v | 4 +-- vlib/toml/tests/datetime_test.v | 2 +- vlib/toml/tests/default_to_test.v | 2 +- vlib/toml/tests/json_encoding_test.v | 15 ++++------ vlib/toml/tests/json_test.v | 2 +- vlib/toml/tests/key_test.v | 2 +- vlib/toml/tests/large_toml_file_test.v | 2 +- vlib/toml/tests/nested_test.v | 2 +- vlib/toml/tests/quoted_keys_test.v | 2 +- vlib/toml/tests/reflect_test.v | 2 +- vlib/toml/tests/spaced_keys_test.v | 2 +- vlib/toml/tests/strings_test.v | 10 +++---- vlib/toml/tests/table_test.v | 2 +- vlib/toml/tests/toml_bom_test.v | 6 ++-- vlib/toml/tests/toml_memory_corruption_test.v | 4 +-- vlib/toml/tests/toml_test.v | 4 +-- vlib/toml/tests/toml_types_test.v | 28 +++++++++---------- vlib/toml/tests/value_query_test.v | 8 +++--- 26 files changed, 70 insertions(+), 75 deletions(-) diff --git a/examples/toml.v b/examples/toml.v index 303aa5ede1..a245cf3510 100644 --- a/examples/toml.v +++ b/examples/toml.v @@ -38,7 +38,7 @@ hosts = [ ]' fn main() { - doc := toml.parse(toml_text) or { panic(err) } + doc := toml.parse_text(toml_text) or { panic(err) } title := doc.value('title').string() println('title: "$title"') ip := doc.value('servers.alpha.ip').string() diff --git a/vlib/toml/README.md b/vlib/toml/README.md index cdcc475039..8fd07c838f 100644 --- a/vlib/toml/README.md +++ b/vlib/toml/README.md @@ -8,7 +8,8 @@ Parsing files or `string`s containing TOML is easy. Simply import the `toml` module and do: ```v ignore -doc := toml.parse() or { panic(err) } +doc1 := toml.parse_text() or { panic(err) } +doc2 := toml.parse_file() or { panic(err) } ``` ## Example @@ -54,7 +55,7 @@ hosts = [ ]' fn main() { - doc := toml.parse(toml_text) or { panic(err) } + doc := toml.parse_text(toml_text) or { panic(err) } title := doc.value('title').string() println('title: "$title"') ip := doc.value('servers.alpha.ip').string() @@ -91,7 +92,7 @@ array = [ ] ' -doc := toml.parse(toml_text) or { panic(err) } +doc := toml.parse_text(toml_text) or { panic(err) } assert doc.value('val').bool() == true assert doc.value('table.array[0].a').string() == 'A' @@ -142,6 +143,6 @@ array = [ ] ' -doc := toml.parse(toml_text) or { panic(err) } +doc := toml.parse_text(toml_text) or { panic(err) } assert to.json(doc) == '{ "val": true, "table": { "array": [ { "a": "A" }, { "b": "B" } ] } }' ``` diff --git a/vlib/toml/tests/array_of_tables_1_level_test.v b/vlib/toml/tests/array_of_tables_1_level_test.v index 5a0495d4ab..971db6fb3e 100644 --- a/vlib/toml/tests/array_of_tables_1_level_test.v +++ b/vlib/toml/tests/array_of_tables_1_level_test.v @@ -18,7 +18,7 @@ color = "gray"' ) fn test_tables() { - mut toml_doc := toml.parse(toml_table_text) or { panic(err) } + mut toml_doc := toml.parse_text(toml_table_text) or { panic(err) } toml_json := to.json(toml_doc) diff --git a/vlib/toml/tests/array_of_tables_2_level_test.v b/vlib/toml/tests/array_of_tables_2_level_test.v index ae73b8cfe9..4ad2e94837 100644 --- a/vlib/toml/tests/array_of_tables_2_level_test.v +++ b/vlib/toml/tests/array_of_tables_2_level_test.v @@ -22,13 +22,13 @@ name = "Born in the USA" name = "Dancing in the Dark"' ) -fn test_nested_array_of_tables() { - mut toml_doc := toml.parse(toml_text) or { panic(err) } +const fprefix = os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.')) + +fn test_nested_array_of_tables() ? { + mut toml_doc := toml.parse_text(toml_text) ? toml_json := to.json(toml_doc) - eprintln(toml_json) - assert toml_json == os.read_file( - os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + - '.out') or { panic(err) } + + assert toml_json == os.read_file(fprefix + '.out') ? } diff --git a/vlib/toml/tests/array_of_tables_array_test.v b/vlib/toml/tests/array_of_tables_array_test.v index 5a005c9884..32671dc000 100644 --- a/vlib/toml/tests/array_of_tables_array_test.v +++ b/vlib/toml/tests/array_of_tables_array_test.v @@ -14,7 +14,7 @@ const ( ) fn test_nested_array_of_tables() { - mut toml_doc := toml.parse(toml_text) or { panic(err) } + mut toml_doc := toml.parse_text(toml_text) or { panic(err) } toml_json := to.json(toml_doc) diff --git a/vlib/toml/tests/array_of_tables_edge_case_1_test.v b/vlib/toml/tests/array_of_tables_edge_case_1_test.v index f4f18dac29..92e5e66235 100644 --- a/vlib/toml/tests/array_of_tables_edge_case_1_test.v +++ b/vlib/toml/tests/array_of_tables_edge_case_1_test.v @@ -6,7 +6,7 @@ fn test_array_of_tables_edge_case_file() { toml_file := os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + '.toml' - toml_doc := toml.parse(toml_file) or { panic(err) } + toml_doc := toml.parse_file(toml_file) or { panic(err) } toml_json := to.json(toml_doc) out_file := diff --git a/vlib/toml/tests/array_of_tables_edge_case_2_test.v b/vlib/toml/tests/array_of_tables_edge_case_2_test.v index f4f18dac29..0c30e8bfc9 100644 --- a/vlib/toml/tests/array_of_tables_edge_case_2_test.v +++ b/vlib/toml/tests/array_of_tables_edge_case_2_test.v @@ -2,17 +2,14 @@ import os import toml import toml.to -fn test_array_of_tables_edge_case_file() { - toml_file := - os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + - '.toml' - toml_doc := toml.parse(toml_file) or { panic(err) } +const fprefix = os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.')) + +fn test_array_of_tables_edge_case_file() ? { + toml_doc := toml.parse_file(os.real_path(fprefix + '.toml')) ? toml_json := to.json(toml_doc) - out_file := - os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + - '.out' - out_file_json := os.read_file(out_file) or { panic(err) } + + out_file_json := os.read_file(os.real_path(fprefix + '.out')) ? println(toml_json) assert toml_json == out_file_json } diff --git a/vlib/toml/tests/compact_test.v b/vlib/toml/tests/compact_test.v index c9ebc5b7f1..d662749261 100644 --- a/vlib/toml/tests/compact_test.v +++ b/vlib/toml/tests/compact_test.v @@ -29,7 +29,7 @@ hosts = [ ]' fn test_parse_compact_text() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } title := toml_doc.value('title') assert title == toml.Any('TOML Example') diff --git a/vlib/toml/tests/crlf_test.v b/vlib/toml/tests/crlf_test.v index ac95c8f9d3..07960c9385 100644 --- a/vlib/toml/tests/crlf_test.v +++ b/vlib/toml/tests/crlf_test.v @@ -4,7 +4,7 @@ fn test_crlf() { str_value := 'test string' mut toml_txt := 'crlf_string = "test string"\r\n # Comment with CRLF is not allowed' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('crlf_string') assert value == toml.Any(str_value) @@ -16,7 +16,7 @@ fn test_crlf_is_parsable_just_like_lf() ? { crlf_content := '# a comment\r\ntitle = "TOML Example"\r\n[database]\r\nserver = "192.168.1.1"\r\nports = [ 8000, 8001, 8002 ]\r\n' all := [crlf_content, crlf_content.replace('\r\n', '\n')] for content in all { - res := toml.parse(content) ? + res := toml.parse_text(content) ? assert res.value('title') == toml.Any('TOML Example') assert (res.value('database') as map[string]toml.Any)['server'] ? == toml.Any('192.168.1.1') } diff --git a/vlib/toml/tests/datetime_test.v b/vlib/toml/tests/datetime_test.v index 61d0269e06..4d656566c3 100644 --- a/vlib/toml/tests/datetime_test.v +++ b/vlib/toml/tests/datetime_test.v @@ -16,7 +16,7 @@ fn test_dates() { lt1 = 07:32:00 lt2 = 00:32:00.999999 ' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } // Re-use vars mut odt_time := toml.DateTime{'1979-05-27T07:32:00Z'} diff --git a/vlib/toml/tests/default_to_test.v b/vlib/toml/tests/default_to_test.v index 2bf2283f43..d4634d1925 100644 --- a/vlib/toml/tests/default_to_test.v +++ b/vlib/toml/tests/default_to_test.v @@ -3,7 +3,7 @@ import toml fn test_default_to() { default_value := 4321 mut toml_txt := 'var = 1234' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('tar').default_to(default_value).int() assert value == default_value } diff --git a/vlib/toml/tests/json_encoding_test.v b/vlib/toml/tests/json_encoding_test.v index bc58383c74..9368820348 100644 --- a/vlib/toml/tests/json_encoding_test.v +++ b/vlib/toml/tests/json_encoding_test.v @@ -2,17 +2,14 @@ import os import toml import toml.to -fn test_parse() { - toml_file := - os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + - '.toml' - toml_doc := toml.parse(toml_file) or { panic(err) } +const fprefix = os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.')) + +fn test_parse() ? { + toml_doc := toml.parse_file(os.real_path(fprefix + '.toml')) ? toml_json := to.json(toml_doc) - out_file := - os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + - '.out' - out_file_json := os.read_file(out_file) or { panic(err) } println(toml_json) + + out_file_json := os.read_file(os.real_path(fprefix + '.out')) ? assert toml_json == out_file_json } diff --git a/vlib/toml/tests/json_test.v b/vlib/toml/tests/json_test.v index bc58383c74..15b4190328 100644 --- a/vlib/toml/tests/json_test.v +++ b/vlib/toml/tests/json_test.v @@ -6,7 +6,7 @@ fn test_parse() { toml_file := os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + '.toml' - toml_doc := toml.parse(toml_file) or { panic(err) } + toml_doc := toml.parse_file(toml_file) or { panic(err) } toml_json := to.json(toml_doc) out_file := diff --git a/vlib/toml/tests/key_test.v b/vlib/toml/tests/key_test.v index d624c4d4fd..ceb3c8906b 100644 --- a/vlib/toml/tests/key_test.v +++ b/vlib/toml/tests/key_test.v @@ -6,7 +6,7 @@ fn test_keys() { toml_file := os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + '.toml' - toml_doc := toml.parse(toml_file) or { panic(err) } + toml_doc := toml.parse_file(toml_file) or { panic(err) } mut value := toml_doc.value('34-11') assert value.int() == 23 diff --git a/vlib/toml/tests/large_toml_file_test.v b/vlib/toml/tests/large_toml_file_test.v index 51daa01dc3..3bb4c30440 100644 --- a/vlib/toml/tests/large_toml_file_test.v +++ b/vlib/toml/tests/large_toml_file_test.v @@ -15,7 +15,7 @@ fn test_large_file() { '.toml' if os.exists(toml_file) { println('Testing parsing of large (${os.file_size(toml_file)} bytes) "$toml_file"...') - toml_doc := toml.parse(toml_file) or { panic(err) } + toml_doc := toml.parse_file(toml_file) or { panic(err) } println('OK [1/1] "$toml_file"...') // So it can be checked with `v -stats test ...` } } diff --git a/vlib/toml/tests/nested_test.v b/vlib/toml/tests/nested_test.v index dd0390e415..82950ef6de 100644 --- a/vlib/toml/tests/nested_test.v +++ b/vlib/toml/tests/nested_test.v @@ -25,7 +25,7 @@ enabled = true ' fn test_parse() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } // dump(toml_doc.ast) // assert false diff --git a/vlib/toml/tests/quoted_keys_test.v b/vlib/toml/tests/quoted_keys_test.v index 506668eada..3625e6e2fc 100644 --- a/vlib/toml/tests/quoted_keys_test.v +++ b/vlib/toml/tests/quoted_keys_test.v @@ -3,7 +3,7 @@ import toml fn test_quoted_keys() { str_value := 'V rocks!' toml_txt := 'a."b.c" = "V rocks!"' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('a."b.c"') assert value == toml.Any(str_value) diff --git a/vlib/toml/tests/reflect_test.v b/vlib/toml/tests/reflect_test.v index d166a637dd..e2a1bd1562 100644 --- a/vlib/toml/tests/reflect_test.v +++ b/vlib/toml/tests/reflect_test.v @@ -50,7 +50,7 @@ mut: } fn test_reflect() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } mut user := toml_doc.reflect() user.bio = toml_doc.value('bio').reflect() diff --git a/vlib/toml/tests/spaced_keys_test.v b/vlib/toml/tests/spaced_keys_test.v index f76efdf3d5..b9ea4f4685 100644 --- a/vlib/toml/tests/spaced_keys_test.v +++ b/vlib/toml/tests/spaced_keys_test.v @@ -12,7 +12,7 @@ fn test_spaced_keys() { [ tube . test . "test.test" ] h . "i.j." . "k" = "Cryptic" ' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } mut value := toml_doc.value('a."b.c"[0].d.e') assert value == toml.Any(str_value) assert value as string == str_value diff --git a/vlib/toml/tests/strings_test.v b/vlib/toml/tests/strings_test.v index a96b2e6574..76548de0ac 100644 --- a/vlib/toml/tests/strings_test.v +++ b/vlib/toml/tests/strings_test.v @@ -33,7 +33,7 @@ long = "\U000003B4"' ) fn test_multiline_strings() { - mut toml_doc := toml.parse(toml_multiline_text_1) or { panic(err) } + mut toml_doc := toml.parse_text(toml_multiline_text_1) or { panic(err) } mut value := toml_doc.value('multi1') assert value.string() == 'one' @@ -44,7 +44,7 @@ fn test_multiline_strings() { value = toml_doc.value('multi4') assert value.string() == 'one\ntwo\nthree\nfour\n' - toml_doc = toml.parse(toml_multiline_text_2) or { panic(err) } + toml_doc = toml.parse_text(toml_multiline_text_2) or { panic(err) } value = toml_doc.value('multi1') assert value.string() == 'one' value = toml_doc.value('multi2') @@ -57,7 +57,7 @@ fn test_multiline_strings() { toml_file := os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + '.toml' - toml_doc = toml.parse(toml_file) or { panic(err) } + toml_doc = toml.parse_file(toml_file) or { panic(err) } value = toml_doc.value('lit_one') assert value.string() == "'one quote'" value = toml_doc.value('lit_two') @@ -69,7 +69,7 @@ fn test_multiline_strings() { } fn test_unicode_escapes() { - mut toml_doc := toml.parse(toml_unicode_escapes) or { panic(err) } + mut toml_doc := toml.parse_text(toml_unicode_escapes) or { panic(err) } mut value := toml_doc.value('short') assert value.string() == '\u03B4' // <- This escape is handled by V @@ -81,7 +81,7 @@ fn test_literal_strings() { toml_file := os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + '.toml' - toml_doc := toml.parse(toml_file) or { panic(err) } + toml_doc := toml.parse_file(toml_file) or { panic(err) } assert toml_doc.value('lit1').string() == r'\' // '\' assert toml_doc.value('lit2').string() == r'\\' // '\\' diff --git a/vlib/toml/tests/table_test.v b/vlib/toml/tests/table_test.v index 43ade350b4..c10d6a1167 100644 --- a/vlib/toml/tests/table_test.v +++ b/vlib/toml/tests/table_test.v @@ -27,7 +27,7 @@ T = {a.b=2}' ) fn test_tables() { - mut toml_doc := toml.parse(toml_table_text) or { panic(err) } + mut toml_doc := toml.parse_text(toml_table_text) or { panic(err) } mut value := toml_doc.value('inline.a.b') assert value.int() == 42 diff --git a/vlib/toml/tests/toml_bom_test.v b/vlib/toml/tests/toml_bom_test.v index fda33f63a1..9ccf1fc614 100644 --- a/vlib/toml/tests/toml_bom_test.v +++ b/vlib/toml/tests/toml_bom_test.v @@ -17,7 +17,7 @@ const ( ) fn test_toml_with_bom() { - toml_doc := toml.parse(toml_text_with_utf8_bom) or { panic(err) } + toml_doc := toml.parse_text(toml_text_with_utf8_bom) or { panic(err) } toml_json := to.json(toml_doc) title := toml_doc.value('title') @@ -36,13 +36,13 @@ fn test_toml_with_bom() { // Re-cycle bad_toml_doc mut bad_toml_doc := empty_toml_document - bad_toml_doc = toml.parse(toml_text_with_utf16_bom) or { + bad_toml_doc = toml.parse_text(toml_text_with_utf16_bom) or { println(' $err.msg()') assert true empty_toml_document } - bad_toml_doc = toml.parse(toml_text_with_utf32_bom) or { + bad_toml_doc = toml.parse_text(toml_text_with_utf32_bom) or { println(' $err.msg()') assert true empty_toml_document diff --git a/vlib/toml/tests/toml_memory_corruption_test.v b/vlib/toml/tests/toml_memory_corruption_test.v index 9e0c518e79..b54e9398bb 100644 --- a/vlib/toml/tests/toml_memory_corruption_test.v +++ b/vlib/toml/tests/toml_memory_corruption_test.v @@ -7,7 +7,7 @@ const toml_text = os.read_file(os.real_path(os.join_path(os.dir(@FILE), 'testdat '.toml') or { panic(err) } fn test_toml_known_memory_corruption() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } owner := toml_doc.value('owner') as map[string]toml.Any any_name := owner.value('name') @@ -34,7 +34,7 @@ fn test_toml_known_memory_corruption_2() { lt1 = 07:32:00 lt2 = 00:32:00.999999 ' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } // ldt1 test section odt_time := toml.DateTime{'1979-05-27T07:32:00'} diff --git a/vlib/toml/tests/toml_test.v b/vlib/toml/tests/toml_test.v index 51f1dd4310..ceb08f475d 100644 --- a/vlib/toml/tests/toml_test.v +++ b/vlib/toml/tests/toml_test.v @@ -9,7 +9,7 @@ const toml_text = os.read_file( fn test_toml() { // File containing the complete text from the example in the official TOML project README.md: // https://github.com/toml-lang/toml/blob/3b11f6921da7b6f5db37af039aa021fee450c091/README.md#Example - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } toml_json := to.json(toml_doc) // NOTE Kept for easier debugging: @@ -98,7 +98,7 @@ fn test_toml_parse_text() { } fn test_toml_parse() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } toml_json := to.json(toml_doc) assert toml_json == os.read_file( os.real_path(os.join_path(os.dir(@FILE), 'testdata', os.file_name(@FILE).all_before_last('.'))) + diff --git a/vlib/toml/tests/toml_types_test.v b/vlib/toml/tests/toml_types_test.v index c870d6970d..2564299ac6 100644 --- a/vlib/toml/tests/toml_types_test.v +++ b/vlib/toml/tests/toml_types_test.v @@ -4,7 +4,7 @@ import strconv fn test_string() { str_value := 'test string' toml_txt := 'string = "test string"' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('string') assert value == toml.Any(str_value) @@ -14,7 +14,7 @@ fn test_string() { fn test_i64() { toml_txt := 'i64 = 120' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('i64') assert value == toml.Any(i64(120)) @@ -26,7 +26,7 @@ fn test_bool() { toml_txt := ' bool_true = true bool_false = false' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value_true := toml_doc.value('bool_true') assert value_true == toml.Any(true) @@ -46,7 +46,7 @@ bool_false = false' fn test_bool_key_is_not_value() { toml_txt := 'true = true false = false' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value_true := toml_doc.value('true') assert value_true == toml.Any(true) @@ -64,7 +64,7 @@ false = false' fn test_single_letter_key() { toml_txt := '[v] open_sourced = "Jun 22 2019 20:20:28"' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('v.open_sourced').string() assert value == 'Jun 22 2019 20:20:28' @@ -74,7 +74,7 @@ fn test_hex_values() { // Regression test // '0xb' is carefully chosen to include the 'b' character that also denotes binary via 0b prefix. toml_txt := 'hex = 0xb' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('hex') assert value as i64 == 11 @@ -85,7 +85,7 @@ fn test_comment_as_last_value() { toml_txt := ' test = 42 # this line has comment as last thing' - toml_doc := toml.parse(toml_txt) or { panic(err) } + toml_doc := toml.parse_text(toml_txt) or { panic(err) } value := toml_doc.value('test') assert value as i64 == 42 @@ -93,31 +93,31 @@ test = 42 } fn test_nan_and_inf_values() { - mut toml_doc := toml.parse('nan = nan') or { panic(err) } + mut toml_doc := toml.parse_text('nan = nan') or { panic(err) } mut value := toml_doc.value('nan') assert value.string() == 'nan' - toml_doc = toml.parse('nan = nan#comment') or { panic(err) } + toml_doc = toml.parse_text('nan = nan#comment') or { panic(err) } value = toml_doc.value('nan') assert value.string() == 'nan' - toml_doc = toml.parse('nan = -nan') or { panic(err) } + toml_doc = toml.parse_text('nan = -nan') or { panic(err) } value = toml_doc.value('nan') assert value.string() == 'nan' - toml_doc = toml.parse('nan = +nan') or { panic(err) } + toml_doc = toml.parse_text('nan = +nan') or { panic(err) } value = toml_doc.value('nan') assert value.string() == 'nan' - toml_doc = toml.parse('inf = inf') or { panic(err) } + toml_doc = toml.parse_text('inf = inf') or { panic(err) } value = toml_doc.value('inf') assert value.u64() == strconv.double_plus_infinity - toml_doc = toml.parse('inf = +inf') or { panic(err) } + toml_doc = toml.parse_text('inf = +inf') or { panic(err) } value = toml_doc.value('inf') assert value.u64() == strconv.double_plus_infinity - toml_doc = toml.parse('inf = -inf') or { panic(err) } + toml_doc = toml.parse_text('inf = -inf') or { panic(err) } value = toml_doc.value('inf') assert value.u64() == strconv.double_minus_infinity } diff --git a/vlib/toml/tests/value_query_test.v b/vlib/toml/tests/value_query_test.v index 1c8312368a..b7d6d76bea 100644 --- a/vlib/toml/tests/value_query_test.v +++ b/vlib/toml/tests/value_query_test.v @@ -50,7 +50,7 @@ colors = [ ) fn test_value_query_in_array() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } mut value := toml_doc.value('themes[0].colors[1]').string() assert value == 'black' value = toml_doc.value('themes[1].colors[0]').string() @@ -67,7 +67,7 @@ fn test_value_query_in_array() { } fn test_any_value_query() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } themes := toml_doc.value('themes') assert themes.value('[0].colors[0]').string() == 'red' @@ -94,7 +94,7 @@ fn test_any_value_query() { } fn test_inf_and_nan_query() { - toml_doc := toml.parse(toml_text) or { panic(err) } + toml_doc := toml.parse_text(toml_text) or { panic(err) } value := toml_doc.value('values.nan').string() assert value == 'nan' @@ -106,7 +106,7 @@ fn test_inf_and_nan_query() { } fn test_any_value_query_2() { - toml_doc := toml.parse(toml_text_2) or { panic(err) } + toml_doc := toml.parse_text(toml_text_2) or { panic(err) } defaults := toml_doc.value('defaults') assert defaults.value('run.flags[0]').string() == '-f 1' assert defaults.value('env[0].RUN_TIME').int() == 5