mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
toml: minor cleanup in toml tests (#16679)
This commit is contained in:
parent
db2111235e
commit
fd472d2d41
6
.github/workflows/toml_ci.yml
vendored
6
.github/workflows/toml_ci.yml
vendored
@ -45,7 +45,7 @@ jobs:
|
|||||||
git -C $TOML_BS_TESTS_PATH checkout $TOML_BS_TESTS_PINNED_COMMIT
|
git -C $TOML_BS_TESTS_PATH checkout $TOML_BS_TESTS_PINNED_COMMIT
|
||||||
|
|
||||||
- name: Run BurntSushi TOML tests
|
- name: Run BurntSushi TOML tests
|
||||||
run: ./v vlib/toml/tests/burntsushi.toml-test_test.v
|
run: ./v vlib/toml/tests/burntsushi_toml_test.v
|
||||||
|
|
||||||
# Tests found at gist
|
# Tests found at gist
|
||||||
- name: Get large_toml_file_test.toml
|
- name: Get large_toml_file_test.toml
|
||||||
@ -61,7 +61,7 @@ jobs:
|
|||||||
git -C $TOML_IARNA_TESTS_PATH checkout $TOML_IARNA_TESTS_PINNED_COMMIT
|
git -C $TOML_IARNA_TESTS_PATH checkout $TOML_IARNA_TESTS_PINNED_COMMIT
|
||||||
|
|
||||||
- name: Run iarna TOML tests
|
- name: Run iarna TOML tests
|
||||||
run: ./v -gc boehm vlib/toml/tests/iarna.toml-spec-tests_test.v
|
run: ./v -gc boehm vlib/toml/tests/iarna_toml_spec_test.v
|
||||||
|
|
||||||
# Tests found at https://github.com/alexcrichton/toml-rs
|
# Tests found at https://github.com/alexcrichton/toml-rs
|
||||||
- name: Clone alexcrichton/toml-rs
|
- name: Clone alexcrichton/toml-rs
|
||||||
@ -70,4 +70,4 @@ jobs:
|
|||||||
git -C $TOML_AC_TESTS_PATH checkout $TOML_AC_TESTS_PINNED_COMMIT
|
git -C $TOML_AC_TESTS_PATH checkout $TOML_AC_TESTS_PINNED_COMMIT
|
||||||
|
|
||||||
- name: Run alexcrichton TOML tests
|
- name: Run alexcrichton TOML tests
|
||||||
run: ./v vlib/toml/tests/alexcrichton.toml-rs-tests_test.v
|
run: ./v vlib/toml/tests/alexcrichton_toml_rs_test.v
|
||||||
|
@ -135,7 +135,7 @@ fn test_alexcrichton_toml_rs() {
|
|||||||
if !hide_oks {
|
if !hide_oks {
|
||||||
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
||||||
}
|
}
|
||||||
toml_doc := toml.parse_file(valid_test_file)?
|
toml_doc := toml.parse_file(valid_test_file)!
|
||||||
|
|
||||||
v_toml_json_path := os.join_path(compare_work_dir_root,
|
v_toml_json_path := os.join_path(compare_work_dir_root,
|
||||||
os.file_name(valid_test_file).all_before_last('.') + '.v.json')
|
os.file_name(valid_test_file).all_before_last('.') + '.v.json')
|
@ -82,7 +82,7 @@ fn test_burnt_sushi_tomltest() {
|
|||||||
if !hide_oks {
|
if !hide_oks {
|
||||||
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
||||||
}
|
}
|
||||||
toml_doc := toml.parse_file(valid_test_file)?
|
toml_doc := toml.parse_file(valid_test_file)!
|
||||||
valid++
|
valid++
|
||||||
}
|
}
|
||||||
println('${valid}/${valid_test_files.len} TOML files were parsed correctly')
|
println('${valid}/${valid_test_files.len} TOML files were parsed correctly')
|
@ -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'
|
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')]
|
all := [crlf_content, crlf_content.replace('\r\n', '\n')]
|
||||||
for content in all {
|
for content in all {
|
||||||
res := toml.parse_text(content)?
|
res := toml.parse_text(content)!
|
||||||
assert res.value('title') == toml.Any('TOML Example')
|
assert res.value('title') == toml.Any('TOML Example')
|
||||||
assert (res.value('database') as map[string]toml.Any)['server']! == toml.Any('192.168.1.1')
|
assert (res.value('database') as map[string]toml.Any)['server']! == toml.Any('192.168.1.1')
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ fn test_iarna_toml_spec_tests() {
|
|||||||
if !hide_oks {
|
if !hide_oks {
|
||||||
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
||||||
}
|
}
|
||||||
toml_doc := toml.parse_file(valid_test_file)?
|
toml_doc := toml.parse_file(valid_test_file)!
|
||||||
valid++
|
valid++
|
||||||
}
|
}
|
||||||
println('${valid}/${valid_test_files.len} TOML files were parsed correctly')
|
println('${valid}/${valid_test_files.len} TOML files were parsed correctly')
|
||||||
@ -112,12 +112,12 @@ fn test_iarna_toml_spec_tests() {
|
|||||||
println('Testing value output of ${valid_test_files.len} valid TOML files using "${jq}"...')
|
println('Testing value output of ${valid_test_files.len} valid TOML files using "${jq}"...')
|
||||||
|
|
||||||
if os.exists(compare_work_dir_root) {
|
if os.exists(compare_work_dir_root) {
|
||||||
os.rmdir_all(compare_work_dir_root)?
|
os.rmdir_all(compare_work_dir_root)!
|
||||||
}
|
}
|
||||||
os.mkdir_all(compare_work_dir_root)?
|
os.mkdir_all(compare_work_dir_root)!
|
||||||
|
|
||||||
jq_normalize_path := os.join_path(compare_work_dir_root, 'normalize.jq')
|
jq_normalize_path := os.join_path(compare_work_dir_root, 'normalize.jq')
|
||||||
os.write_file(jq_normalize_path, jq_normalize)?
|
os.write_file(jq_normalize_path, jq_normalize)!
|
||||||
|
|
||||||
valid = 0
|
valid = 0
|
||||||
e = 0
|
e = 0
|
||||||
@ -177,7 +177,7 @@ fn test_iarna_toml_spec_tests() {
|
|||||||
run([python, '-c',
|
run([python, '-c',
|
||||||
"'import sys, yaml, json; json.dump(yaml.load(sys.stdin, Loader=yaml.FullLoader), sys.stdout, indent=4)'",
|
"'import sys, yaml, json; json.dump(yaml.load(sys.stdin, Loader=yaml.FullLoader), sys.stdout, indent=4)'",
|
||||||
'<', iarna_yaml_path, '>', converted_json_path]) or {
|
'<', iarna_yaml_path, '>', converted_json_path]) or {
|
||||||
contents := os.read_file(iarna_yaml_path)?
|
contents := os.read_file(iarna_yaml_path)!
|
||||||
// NOTE there's known errors with the python convertion method.
|
// NOTE there's known errors with the python convertion method.
|
||||||
// For now we just ignore them as it's a broken tool - not a wrong test-case.
|
// For now we just ignore them as it's a broken tool - not a wrong test-case.
|
||||||
// Uncomment this print to see/check them.
|
// Uncomment this print to see/check them.
|
||||||
@ -193,26 +193,26 @@ fn test_iarna_toml_spec_tests() {
|
|||||||
if !hide_oks {
|
if !hide_oks {
|
||||||
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
println('OK [${i + 1}/${valid_test_files.len}] "${valid_test_file}"...')
|
||||||
}
|
}
|
||||||
toml_doc := toml.parse_file(valid_test_file)?
|
toml_doc := toml.parse_file(valid_test_file)!
|
||||||
|
|
||||||
v_toml_json_path := os.join_path(compare_work_dir_root, '${valid_test_file_name}.v.json')
|
v_toml_json_path := os.join_path(compare_work_dir_root, '${valid_test_file_name}.v.json')
|
||||||
iarna_toml_json_path := os.join_path(compare_work_dir_root, '${valid_test_file_name}.json')
|
iarna_toml_json_path := os.join_path(compare_work_dir_root, '${valid_test_file_name}.json')
|
||||||
|
|
||||||
os.write_file(v_toml_json_path, to_iarna(toml_doc.ast.table, converted_from_yaml))?
|
os.write_file(v_toml_json_path, to_iarna(toml_doc.ast.table, converted_from_yaml))!
|
||||||
|
|
||||||
if converted_json_path == '' {
|
if converted_json_path == '' {
|
||||||
converted_json_path = valid_test_file.all_before_last('.') + '.json'
|
converted_json_path = valid_test_file.all_before_last('.') + '.json'
|
||||||
}
|
}
|
||||||
iarna_json := os.read_file(converted_json_path)?
|
iarna_json := os.read_file(converted_json_path)!
|
||||||
os.write_file(iarna_toml_json_path, iarna_json)?
|
os.write_file(iarna_toml_json_path, iarna_json)!
|
||||||
|
|
||||||
v_normalized_json := run([jq, '-S', '-f "${jq_normalize_path}"', v_toml_json_path]) or {
|
v_normalized_json := run([jq, '-S', '-f "${jq_normalize_path}"', v_toml_json_path]) or {
|
||||||
contents := os.read_file(v_toml_json_path)?
|
contents := os.read_file(v_toml_json_path)!
|
||||||
panic(err.msg() + '\n${contents}')
|
panic(err.msg() + '\n${contents}')
|
||||||
}
|
}
|
||||||
cmd := [jq, '-S', '-f "${jq_normalize_path}"', iarna_toml_json_path]
|
cmd := [jq, '-S', '-f "${jq_normalize_path}"', iarna_toml_json_path]
|
||||||
iarna_normalized_json := run(cmd) or {
|
iarna_normalized_json := run(cmd) or {
|
||||||
contents := os.read_file(v_toml_json_path)?
|
contents := os.read_file(v_toml_json_path)!
|
||||||
panic(err.msg() + '\n${contents}\n\ncmd: ${cmd.join(' ')}')
|
panic(err.msg() + '\n${contents}\n\ncmd: ${cmd.join(' ')}')
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,7 +245,7 @@ fn test_iarna_toml_spec_tests() {
|
|||||||
println('OK [${i + 1}/${invalid_test_files.len}] "${invalid_test_file}"...')
|
println('OK [${i + 1}/${invalid_test_files.len}] "${invalid_test_file}"...')
|
||||||
}
|
}
|
||||||
if toml_doc := toml.parse_file(invalid_test_file) {
|
if toml_doc := toml.parse_file(invalid_test_file) {
|
||||||
content_that_should_have_failed := os.read_file(invalid_test_file)?
|
content_that_should_have_failed := os.read_file(invalid_test_file)!
|
||||||
println(' This TOML should have failed:\n${'-'.repeat(40)}\n${content_that_should_have_failed}\n${'-'.repeat(40)}')
|
println(' This TOML should have failed:\n${'-'.repeat(40)}\n${content_that_should_have_failed}\n${'-'.repeat(40)}')
|
||||||
assert false
|
assert false
|
||||||
} else {
|
} else {
|
Loading…
x
Reference in New Issue
Block a user