Skip to content

Commit

Permalink
test: record from/to json behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-jerry-ye committed Jan 8, 2025
1 parent 925253e commit d8aaedb
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
48 changes: 48 additions & 0 deletions json/from_json_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,51 @@ test "jsonvalue" {
,
)
}

test "int roundtrip" {
let u = (123).to_json()
let v : Int = @json.from_json!(u)
inspect!(v, content="123")
let u = (-123).to_json()
let v : Int = @json.from_json!(u)
inspect!(v, content="-123")
}

test "uint roundtrip" {
let u = 123U.to_json()
let v : UInt = @json.from_json!(u)
inspect!(v, content="123")
let u = 4294967295U.to_json()
let v : UInt = @json.from_json!(u)
inspect!(v, content="4294967295")
}

test "uint" {
let v : UInt = @json.from_json!(Number(4294967295))
inspect!(v, content="4294967295")
let v : UInt = @json.from_json!(Number(-1))
inspect!(v, content="0")
let v : UInt = @json.from_json!(Number(4294967296))
inspect!(v, content="4294967295")
}

test "int64 roundtrip" {
let u = 123L.to_json()
let v : Int64 = @json.from_json!(u)
inspect!(v, content="123")
let u = 9223372036854775807L.to_json()
let v : Int64 = @json.from_json!(u)
inspect!(v, content="9223372036854775807")
let u = (-9223372036854775808L).to_json()
let v : Int64 = @json.from_json!(u)
inspect!(v, content="-9223372036854775808")
}

test "uint64 roundtrip" {
let u = 123UL.to_json()
let v : UInt64 = @json.from_json!(u)
inspect!(v, content="123")
let u = 18446744073709551615UL.to_json()
let v : UInt64 = @json.from_json!(u)
inspect!(v, content="18446744073709551615")
}
38 changes: 37 additions & 1 deletion json/to_json_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,44 @@ test "Int::to_json" {
inspect!((42).to_json(), content="Number(42)")
}

test "UInt::to_json" {
inspect!(42U.to_json(), content="Number(42)")
}

test "Int64::to_json" {
inspect!(42L.to_json(), content="Number(42)")
inspect!(
42L.to_json(),
content=
#|String("42")
,
)
inspect!(
(-9223372036854775808L).to_json(),
content=
#|String("-9223372036854775808")
,
)
inspect!(
9223372036854775807L.to_json(),
content=
#|String("9223372036854775807")
,
)
}

test "UInt64::to_json" {
inspect!(
42UL.to_json(),
content=
#|String("42")
,
)
inspect!(
18446744073709551615UL.to_json(),
content=
#|String("18446744073709551615")
,
)
}

test "Double::to_json" {
Expand Down

0 comments on commit d8aaedb

Please sign in to comment.