rescript-zora
rescript-zora copied to clipboard
add assertions with no description
Thanks for creating the bindings for Zora, it's quite a nice testing suite for rescript!
Sometimes you don't want to write a test message for an assertion, would you be open to a PR that would change the current API to make the test message optional?
It would be a lightweight layer like this:
let equal = (~msg=?, t, act, exp) => equal(t, act, exp, msg)
You would use it like that:
t->equal("foo", "foo")
// or if you do want a description
t->equal("foo", "foo", ~msg="those two strings should be the same")
Sure it adds a some runtime, but it'd be likely unnoticeable, especially for testing and it would sometimes help to make sure you're not feeding the text message with the expected string value.
Yes, please! ❤️ I meant to add it, but never got around to it.
ok cool, I'll go for it then! 😀
https://github.com/lorenzofox3/zora/blob/master/assert/src/assert.js has the default descriptions from zora-assert. https://rescript-lang.org/docs/manual/latest/function#optional-with-default-value documents how to provide a default value for labelled arguments.
I think this would cause a major version bump since the API will shift as labelled arguments are an all-or-nothing thing for the argument, and so anyone who is using the library would have to update to use the label.
The only way it seems to work is to wrap the external functions:
@send external zoraEqual: (t, 't, 't, string) => unit = "equal"
let equal = (zora: t, a: 't, b: 't, ~msg="should be equivalent") => zoraEqual(zora, a, b, msg)
With uncurried mode we would not even need a wrapper, this would be enough:
@send external zoraEqual: (t, 't, 't, ~msg: string=?) => unit = "equal"
@tsnobip You're right. I was assuming we would set the default string when in fact Zora will take care of the lack of argument. And on top of the fact that the compiler errors weren't clear to me last night (they kept showing up in Zora.res for the external when I tried to use the default argument), and that's how I overlooked the easier solution. 😅
https://github.com/brettcannon/rescript-zora/tree/no-description-required shows it working with equal! Now to do the rest of the functions ...
A search and replace should do the rest :)
A search and replace should do the rest :)
I wish, but unfortunately the difference between ? for an external and a ReScript-native function is enough to have to tweak some code for the extras this library provides (i.e. optionNone and resultError). Plus I added explicit tests for both with and without ~msg provided.
But I managed to get it done, so there will be a PR shortly. 😀