json: add enum to json_test to prevent regressions

pull/5173/head
Emily Hudson 2020-06-02 10:13:26 +01:00 committed by GitHub
parent 63b2d4be99
commit 46dbbd0ed0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -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 {