core
core copied to clipboard
add snapshot test capability without relying on string
fn expect[T:Show](
obj : T, ~value? : T ,
~loc : SourceLoc = _,
~args_loc : ArgsLoc = _
) -> Unit!InspectError {
...
}
-
[ ] modernize inspect protocl using JSON data?
```patch - ~content : String = "", + ~content? : String, ``` -
[ ] add expect API (using show first)
-
[ ] decide whether we need a new dedicated trait called Repr or reuse Show
Potential Issue
Assume we already have expect! working as expected:
struct P {
x: Int,
y: Int
} derive(Show)
test {
expect!({ x: 1, y: 2 })
}
After running the moon test -u, it becomes:
struct P {
x: Int,
y: Int
} derive(Show)
test {
expect!({ x: 1, y: 2 }, value={ x: 1, y: 2 })
}
Now, if the definition of P changes (maybe common in practice), for example by adding a new field z, the value={ x: 1, y: 2 } argument will cause syntax errors. Users have to manually update or remove the value argument.
Changing a single definition may lead to amount test cases failing with syntax errors. The user experience is terrible in this scenario.
struct P {
x: Int,
y: Int,
z: Int
} derive(Show)
test {
expect!({ x: 1, y: 2, z : 3 }, value={ x: 1, y: 2 })
}