Skip to content

Commit

Permalink
x.json2.decoder2: include missing test for #22730 (#23051)
Browse files Browse the repository at this point in the history
  • Loading branch information
enghitalo authored Dec 3, 2024
1 parent 6ac1d08 commit b2c5eca
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions vlib/x/json2/decoder2/tests/json_sumtype_test.v
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ pub struct Dog {

type Sum = int | string | bool | []string

type StructSumTypes = Stru | Stru2

pub struct Stru {
val int
val2 string
val3 Stru2
val4 int
val5 int
}

pub struct Stru2 {
a int
steak string
}

fn test_simple_sum_type() {
assert json.decode[Sum]('1')! == Sum(1)

Expand Down Expand Up @@ -78,4 +93,7 @@ fn test_sum_type_struct() {
assert json.decode[Animal]('{"cat_name": "Tom"}')! == Animal(Cat{'Tom'})
assert json.decode[Animal]('{"dog_name": "Rex"}')! == Animal(Cat{''})
assert json.decode[Animal]('{"dog_name": "Rex", "_type": "Dog"}')! == Animal(Dog{'Rex'})

// struct sumtype in random order
assert json.decode[StructSumTypes]('{"_type": "Stru", "val": 1, "val2": "lala", "val3": {"a": 2, "steak": "leleu"}, "val4": 2147483000, "val5": 2147483000}')! == StructSumTypes(Stru{1, 'lala', Stru2{2, 'leleu'}, 2147483000, 2147483000})
}

0 comments on commit b2c5eca

Please sign in to comment.