json: add enum to json_test to prevent regressions
parent
63b2d4be99
commit
46dbbd0ed0
|
@ -1,16 +1,23 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
enum JobTitle {
|
||||||
|
manager
|
||||||
|
executive
|
||||||
|
worker
|
||||||
|
}
|
||||||
|
|
||||||
struct Employee {
|
struct Employee {
|
||||||
name string
|
name string
|
||||||
age int
|
age int
|
||||||
salary f32
|
salary f32
|
||||||
|
title JobTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_simple() {
|
fn test_simple() {
|
||||||
x := Employee{'Peter', 28, 95000.5}
|
x := Employee{'Peter', 28, 95000.5, .worker}
|
||||||
s := json.encode(x)
|
s := json.encode(x)
|
||||||
eprintln('Employee x: $s')
|
eprintln('Employee x: $s')
|
||||||
assert s == '{"name":"Peter","age":28,"salary":95000.5}'
|
assert s == '{"name":"Peter","age":28,"salary":95000.5,"title":2}'
|
||||||
y := json.decode(Employee, s) or {
|
y := json.decode(Employee, s) or {
|
||||||
assert false
|
assert false
|
||||||
Employee{}
|
Employee{}
|
||||||
|
@ -19,6 +26,7 @@ fn test_simple() {
|
||||||
assert y.name == 'Peter'
|
assert y.name == 'Peter'
|
||||||
assert y.age == 28
|
assert y.age == 28
|
||||||
assert y.salary == 95000.5
|
assert y.salary == 95000.5
|
||||||
|
assert y.title == .worker
|
||||||
}
|
}
|
||||||
|
|
||||||
struct User2 {
|
struct User2 {
|
||||||
|
|
Loading…
Reference in New Issue