From 66a71354d14605d5abc397bfb0f78e570e640c2a Mon Sep 17 00:00:00 2001 From: esynr3z Date: Fri, 24 May 2024 22:11:37 +0300 Subject: [PATCH] test: refactor json_enum tests --- ...um_unit_test.sv => json_enum_unit_test.sv} | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) rename tests/{json_value_enum_unit_test.sv => json_enum_unit_test.sv} (72%) diff --git a/tests/json_value_enum_unit_test.sv b/tests/json_enum_unit_test.sv similarity index 72% rename from tests/json_value_enum_unit_test.sv rename to tests/json_enum_unit_test.sv index e3a8666..de04bd0 100644 --- a/tests/json_value_enum_unit_test.sv +++ b/tests/json_enum_unit_test.sv @@ -2,12 +2,12 @@ `include "test_utils_macros.svh" // Tests of `json_enum` -module json_value_enum_unit_test; +module json_enum_unit_test; import svunit_pkg::svunit_testcase; import test_utils_pkg::*; import json_pkg::*; - string name = "json_value_enum_ut"; + string name = "json_enum_ut"; svunit_testcase svunit_ut; typedef json_enum#(dummy_e) json_dummy_enum; @@ -26,27 +26,24 @@ module json_value_enum_unit_test; `SVUNIT_TESTS_BEGIN - `SVTEST(create_new_test) - begin + `SVTEST(create_new_test) begin json_dummy_enum jenum; jenum = new(DUMMY_BAR); `FAIL_UNLESS(jenum.get_enum() == DUMMY_BAR) // it also behaves like json_string `FAIL_UNLESS_STR_EQUAL(jenum.get(), "DUMMY_BAR") - end - `SVTEST_END + end `SVTEST_END - `SVTEST(create_from_test) - begin + + `SVTEST(create_from_test) begin json_dummy_enum jenum = json_dummy_enum::from(DUMMY_BAR); `FAIL_UNLESS(jenum.get_enum() == DUMMY_BAR) // it also behaves like json_string `FAIL_UNLESS_STR_EQUAL(jenum.get(), "DUMMY_BAR") - end - `SVTEST_END + end `SVTEST_END + - `SVTEST(create_from_string_test) - begin + `SVTEST(create_from_string_test) begin json_dummy_enum jenum; json_result#(json_dummy_enum) jres; @@ -61,11 +58,10 @@ module json_value_enum_unit_test; jres = json_dummy_enum::from_string("DUMMY_BAZ"); `FAIL_IF(jres.is_err) `FAIL_UNLESS(jres.unwrap().get_enum() == DUMMY_BAZ) - end - `SVTEST_END + end `SVTEST_END + - `SVTEST(create_from_string_err_test) - begin + `SVTEST(create_from_string_err_test) begin json_dummy_enum jenum; json_result#(json_dummy_enum) jres; json_error error; @@ -73,9 +69,18 @@ module json_value_enum_unit_test; jres = json_dummy_enum::from_string("DUMMY_EGGS"); `FAIL_IF(jres.is_ok) `FAIL_UNLESS(jres.matches_err_eq(json_error::TYPE_CONVERSION, error)) - end - `SVTEST_END + end `SVTEST_END + + + `SVTEST(clone_enum_test) begin + json_dummy_enum orig = json_dummy_enum::from(DUMMY_FOO); + json_dummy_enum clone; + $cast(clone, orig.clone()); + `FAIL_IF(orig == clone) + `FAIL_UNLESS(orig.get() == clone.get()) + `FAIL_UNLESS(orig.enum_value == clone.enum_value) + end `SVTEST_END `SVUNIT_TESTS_END -endmodule : json_value_enum_unit_test +endmodule : json_enum_unit_test