From 2e54a8cb0eadee32311e3570634d3492d102448b Mon Sep 17 00:00:00 2001 From: Hitalo Souza <63821277+enghitalo@users.noreply.github.com> Date: Tue, 3 Jan 2023 05:16:36 -0300 Subject: [PATCH] x.json2: update tests (#16847) --- .../json_test.v | 29 +++++++++++-------- .../json_todo_test.vv | 15 ---------- 2 files changed, 17 insertions(+), 27 deletions(-) diff --git a/vlib/x/json2/json_module_compatibility_test/json_test.v b/vlib/x/json2/json_module_compatibility_test/json_test.v index 9c700892bf..f671455b14 100644 --- a/vlib/x/json2/json_module_compatibility_test/json_test.v +++ b/vlib/x/json2/json_module_compatibility_test/json_test.v @@ -99,6 +99,21 @@ pub mut: point string [raw] } +fn test_raw_json_field() { + color := json.decode[Color]('{"space": "YCbCr", "point": {"Y": 123}}') or { + assert false + Color{} + } + assert color.point == '{"Y":123}' + assert color.space == 'YCbCr' +} + +fn test_bad_raw_json_field() { + color := json.decode[Color]('{"space": "YCbCr"}') or { return } + assert color.point == '' + assert color.space == 'YCbCr' +} + fn test_encode_map() { expected := '{"one":1,"two":2,"three":3,"four":4}' numbers := { @@ -113,9 +128,8 @@ fn test_encode_map() { // 'three': 3 // 'four': 4 // } - // out := json.encode(numbers) - out := numbers.str() - assert out == expected + assert json.encode(numbers) == expected + assert numbers.str() == expected } type ID = string @@ -155,15 +169,6 @@ fn test_generic() { assert result.x == 'test' } -fn test_raw_json_field() { - color := json.decode[Color]('{"space": "YCbCr", "point": {"Y": 123}}') or { - assert false - Color{} - } - assert color.point == '{"Y":123}' - assert color.space == 'YCbCr' -} - struct Foo[T] { pub: name string diff --git a/vlib/x/json2/json_module_compatibility_test/json_todo_test.vv b/vlib/x/json2/json_module_compatibility_test/json_todo_test.vv index 0c238cc1ec..6a696655de 100644 --- a/vlib/x/json2/json_module_compatibility_test/json_todo_test.vv +++ b/vlib/x/json2/json_module_compatibility_test/json_todo_test.vv @@ -139,21 +139,6 @@ fn test_encode_decode_time() { assert user2.reg_date.str() == '2020-12-22 07:23:00' } -struct Color { -pub mut: - space string - point string [raw] -} - -//! FIX: returning 0 -fn test_bad_raw_json_field() { - color := json.decode('{"space": "YCbCr"}') or { - return - } - assert color.point == '' - assert color.space == 'YCbCr' -} - struct City { name string }