Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring back optional field test #1067

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bool/bool.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ pub fn to_int(self : Bool) -> Int {

pub fn to_int64(self : Bool) -> Int64 {
if self {
1L
1
} else {
0L
0
}
}

pub fn to_uint(self : Bool) -> UInt {
if self {
1U
1
} else {
0U
0
}
}

pub fn to_uint64(self : Bool) -> UInt64 {
if self {
1UL
1
} else {
0UL
0
}
}

Expand Down
4 changes: 2 additions & 2 deletions builtin/json.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub trait ToJson {

pub fn Bool::to_json(self : Bool) -> Json {
if self {
True
true
} else {
False
false
}
}

Expand Down
36 changes: 13 additions & 23 deletions json/to_json_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,19 @@ test "Option::to_json" {
)
}

// test "optinal field" {
// let opt = { x: Some(42), t: Some(Some(42)) }
// inspect!(
// opt.to_json(),
// content=
// #|Object({"x": Array([Number(42)]), "t": Array([Array([Number(42)])])})
// ,
// )
// let opt = { x: None, t: None }
// inspect!(
// opt.to_json(),
// content=
// #|Object({"x": Null, "t": Null})
// ,
// )
// let opt = { x: None, t: Some(None) }
// inspect!(
// opt.to_json(),
// content=
// #|Object({"x": Null, "t": Array([Null])})
// ,
// )
// }
test "optional field" {
let opt = [
{ x: Some(42), t: Some(Some(42)) },
{ x: None, t: None },
{ x: None, t: Some(None) },
]
inspect!(
opt.to_json() |> @json.stringify,
content=
#|[{"x":42,"t":[42]},{},{"t":null}]
,
)
}

test "optional field round trip" {
let opt = { x: Some(42), t: Some(Some(42)) }
Expand Down
6 changes: 3 additions & 3 deletions rational/rational_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ test "from_double array" {
let a : Array[Double] = [
0.5, 5, 29.97, -29.97, 63.5, 126.5, 127.0, 127.5, -63.5, -126.5, -127.0, -127.5,
]
inspect_double_array!(
a,
content="[Ok(1/2), Ok(5), Ok(2997/100), Ok(-2997/100), Ok(127/2), Ok(253/2), Ok(127), Ok(255/2), Ok(-127/2), Ok(-253/2), Ok(-127), Ok(-255/2)]",
inspect!(
a.map(fn { x => @rational.from_double?(x).unwrap() }),
content="[1/2, 5, 2997/100, -2997/100, 127/2, 253/2, 127, 255/2, -127/2, -253/2, -127, -255/2]",
)
let a = [
-10.0e200, 10.0e200, @double.infinity, @double.neg_infinity, @double.not_a_number,
Expand Down