Skip to content
Draft
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
240 changes: 234 additions & 6 deletions debug/debug_test.mbt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,109 @@ fn output(x : Result[Unit, Error]) -> StringView {
}
}

///|
enum Point {
Point(x~ : Int, y~ : Int)
} derive(Eq, Debug)

///|
test "assert_eq for extra value kinds" {
inspect(
output(try? @debug.assert_eq(-2.0, 1.0)),
content=(
#|FAILED: `-2 != 1`
#|diff:
#|--2 +1
),
)
inspect(
output(try? @debug.assert_eq(((1.5 : Float), 1), ((1.5 : Float), 2))),
content=(
#|FAILED: `(1.5, 1) != (1.5, 2)`
#|diff:
#|(1.5, -1, +2)
),
)
inspect(
output(try? @debug.assert_eq(('a', 1), ('a', 2))),
content=(
#|FAILED: `('a', 1) != ('a', 2)`
#|diff:
#|('a', -1, +2)
),
)
inspect(
output(try? @debug.assert_eq({ "x": 1, "y": 2 }, { "x": 1, "y": 3 })),
content=(
#|FAILED: `{ "x": 1, "y": 2 } != { "x": 1, "y": 3 }`
#|diff:
#|{ "x": 1, "y": -2 +3 }
),
)
inspect(
output(
try? @debug.assert_eq(Point::Point(x=1, y=2), Point::Point(x=1, y=3)),
),
content=(
#|FAILED: `Point(x=1, y=2) != Point(x=1, y=3)`
#|diff:
#|Point(x=1, -y=2, +y=3)
),
)
inspect(
output(
try? @debug.assert_eq(@list.from_array([1, 2]), @list.from_array([1, 3])),
),
content=(
#|FAILED: `<List: [1, 2]> != <List: [1, 3]>`
#|diff:
#|<List: -[1, 2], +[1, 3]>
),
)
}

///|
test "assert_eq for matcher paths" {
inspect(
output(try? @debug.assert_eq([1, 2, 3], [2, 1, 3])),
content=(
#|FAILED: `[1, 2, 3] != [2, 1, 3]`
#|diff:
#|[1, ~2
#| -> 2, 3]
),
)
inspect(
output(try? @debug.assert_eq(([1, 3], [2]), ([3], [1, 2]))),
content=(
#|FAILED: `([1, 3], [2]) != ([3], [1, 2])`
#|diff:
#|-([1, 3], [2]) +([3], [1, 2])
),
)
inspect(
output(
try? @debug.assert_eq({ "a": [1, 3], "b": [2] }, { "a": [3], "b": [1, 2] }),
),
content=(
#|FAILED: `{ "a": [1, 3], "b": [2] } != { "a": [3], "b": [1, 2] }`
#|diff:
#|{ "a": [~1
#| -> 1, 3], "b": [2] }
),
)
inspect(
output(
try? @debug.assert_eq({ "a": [1, 2], "b": [3] }, { "a": [2], "b": [9, 3] }),
),
content=(
#|FAILED: `{ "a": [1, 2], "b": [3] } != { "a": [2], "b": [9, 3] }`
#|diff:
#|{ "a": [-1, 2], "b": [+9, 3] }
),
)
}

///|
test "assert_eq" {
inspect(output(try? @debug.assert_eq(1, 1)), content="ok")
Expand All @@ -72,23 +175,23 @@ test "assert_eq" {
content=(
#|FAILED: `[1, 2, 3] != [1, 222, 3]`
#|diff:
#|[1, -2 +222, 3]
#|[1, -2, +222, 3]
),
)
inspect(
output(try? @debug.assert_eq((true, "string", 123), (true, "s", 1))),
content=(
#|FAILED: `(true, "string", 123) != (true, "s", 1)`
#|diff:
#|(true, -"string" +"s", -123 +1)
#|(true, -"string", -123, +"s", +1)
),
)
inspect(
output(try? @debug.assert_eq({ "k1": 1.0, "k2": 2 }, { "k1": 2, "k3": 5 })),
content=(
#|FAILED: `{ "k1": 1, "k2": 2 } != { "k1": 2, "k3": 5 }`
#|diff:
#|{ "k1": -1 +2, -"k2": 2 +"k3": 5 }
#|{ "k1": -1 +2, -"k2": 2, +"k3": 5 }
),
)
inspect(
Expand All @@ -100,7 +203,7 @@ test "assert_eq" {
content=(
#|FAILED: `Some(1) != Some(2)`
#|diff:
#|Some(-1 +2)
#|Some(-1, +2)
),
)
inspect(
Expand Down Expand Up @@ -152,15 +255,140 @@ test "assert_eq for arrays" {
content=(
#|FAILED: `[1, 2, 3, 4] != [1, 4]`
#|diff:
#|[1, -2 +4, -3, -4]
#|[1, -2, -3, 4]
),
)
inspect(
output(try? @debug.assert_eq([1, 4], [1, 2, 3, 4])),
content=(
#|FAILED: `[1, 4] != [1, 2, 3, 4]`
#|diff:
#|[1, -4 +2, +3, +4]
#|[1, +2, +3, 4]
),
)
inspect(
output(try? @debug.assert_eq([1, 3, 4], [1, 2, 3, 4])),
content=(
#|FAILED: `[1, 3, 4] != [1, 2, 3, 4]`
#|diff:
#|[1, +2, 3, 4]
),
)
inspect(
output(try? @debug.assert_eq([1, 2, 3, 4], [1, 3, 4])),
content=(
#|FAILED: `[1, 2, 3, 4] != [1, 3, 4]`
#|diff:
#|[1, -2, 3, 4]
),
)
inspect(
output(try? @debug.assert_eq([2, 3], [1, 2, 3])),
content=(
#|FAILED: `[2, 3] != [1, 2, 3]`
#|diff:
#|[+1, 2, 3]
),
)
inspect(
output(try? @debug.assert_eq([1, 2, 3], [1, 3])),
content=(
#|FAILED: `[1, 2, 3] != [1, 3]`
#|diff:
#|[1, -2, 3]
),
)
}

///|
test "assert_eq for maps" {
inspect(output(try? @debug.assert_eq({ "a": 1 }, { "a": 1 })), content="ok")
inspect(
output(try? @debug.assert_eq({ "a": 1, "b": 2 }, { "a": 1, "b": 3 })),
content=(
#|FAILED: `{ "a": 1, "b": 2 } != { "a": 1, "b": 3 }`
#|diff:
#|{ "a": 1, "b": -2 +3 }
),
)
inspect(
output(try? @debug.assert_eq({ "a": 1 }, { "a": 1, "b": 2 })),
content=(
#|FAILED: `{ "a": 1 } != { "a": 1, "b": 2 }`
#|diff:
#|{ "a": 1, +"b": 2 }
),
)
inspect(
output(try? @debug.assert_eq({ "a": 1, "b": 2 }, { "a": 1 })),
content=(
#|FAILED: `{ "a": 1, "b": 2 } != { "a": 1 }`
#|diff:
#|{ "a": 1, -"b": 2 }
),
)
inspect(
output(try? @debug.assert_eq({ "a": 1, "b": 2 }, { "b": 2, "a": 1 })),
content="ok",
)
}

///|
test "assert_eq for nested structures" {
inspect(
output(try? @debug.assert_eq([[1, 3], [4]], [[1, 2, 3], [4]])),
content=(
#|FAILED: `[[1, 3], [4]] != [[1, 2, 3], [4]]`
#|diff:
#|[[1, +2, 3], [4]]
),
)
inspect(
output(
try? @debug.assert_eq({ "left": [1, 4], "right": [5, 6] }, {
"left": [1, 2, 3, 4],
"right": [5, 6],
}),
),
content=(
#|FAILED: `{ "left": [1, 4], "right": [5, 6] } != { "left": [1, 2, 3, 4], "right": [5, 6] }`
#|diff:
#|{ "left": [1, +2, +3, 4], "right": [5, 6] }
),
)
inspect(
output(
try? @debug.assert_eq([{ "k": 1, "v": 1 }, { "k": 2, "v": 2 }], [
{ "k": 1, "v": 10 },
{ "k": 2, "v": 2 },
{ "k": 3, "v": 3 },
]),
),
content=(
#|FAILED: `[{ "k": 1, "v": 1 }, { "k": 2, "v": 2 }] != [{ "k": 1, "v": 10 }, { "k": 2, "v": 2 }, { "k": 3, "v": 3 }]`
#|diff:
#|[{ "k": 1, "v": -1 +10 }, { "k": 2, "v": 2 }, +{ "k": 3, "v": 3 }]
),
)
inspect(
output(
try? @debug.assert_eq({ "outer": [[1, 2], [3, 4]] }, {
"outer": [[1, 2], [3, 4]],
}),
),
content="ok",
)
}

///|
test "assert_eq for float" {
// TODO: fix this
inspect(
output(try? @debug.assert_eq(1.0, 1.0 + 0.0000000000001)),
content=(
#|FAILED: `1 != 1.0000000000001`
#|diff:
#|1
),
)
}
Expand Down
Loading
Loading