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 authored and bobzhang committed Jan 10, 2025
1 parent 2a56c38 commit a3b7c0b
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 4 deletions.
2 changes: 1 addition & 1 deletion json/from_json.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 International Digital Economy Academy
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down
50 changes: 49 additions & 1 deletion json/from_json_test.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 International Digital Economy Academy
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down 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")
}
40 changes: 38 additions & 2 deletions json/to_json_test.mbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 International Digital Economy Academy
// Copyright 2025 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -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 a3b7c0b

Please sign in to comment.