Skip to content

Commit

Permalink
test: refactor json_enum tests
Browse files Browse the repository at this point in the history
  • Loading branch information
esynr3z committed May 24, 2024
1 parent 163b10f commit 66a7135
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions tests/json_value_enum_unit_test.sv → tests/json_enum_unit_test.sv
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -61,21 +58,29 @@ 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;

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

0 comments on commit 66a7135

Please sign in to comment.