Tests are syntactically checked code but indenting can mean the interesting stuff is displayed ‘off to the right’.
simple : Test
describe "leap year tests"
[ test "isn't a leap year" <|
isLeapYear 2001 |> Expect.equal False
, test "is a leap year" <|
isLeapYear 2000 |> Expect.equal True
Is anyone using a different format?
I’m using the same. Except that instead of
\_ -> I have
\() ->. I like to be explicit about parameters.
(Then if I turn the unit test into a fuzzer test then I get a compiler error to remind me to use the fuzz value)
I don’t think you’ll be able to reduce the indentation, but formatting-wise I do ↓
simple : Test
Test.describe "leap year"
[ test "no"
|> Expect.equal False
, test "yes"
|> Expect.equal True
() gives you the guarantee that no values will arrive there, which is helpful to remind you if you for example change to
Test.fuzz. (as jfmengels wrote)
<| → paren application,
op data |> expect →
data |> op |> expect for reasons of simplicity, consistency:
- Pipe data before the function:
food |> op ...
- Feed arguments after the function:
... |> opWith (a ...) (b ...)
Test.describe just to remove names exposed with implied context. Maybe describe is something a test tests or uses as a variable name in the future?
- no repeating in
tests what you already
I format my tests like this:
That looks rather excellent, Rupert
A tiny bit of repetition for a clean syntax and much code close to the left-margin
If indentation is of concern you would gain one more by piping the list into describe.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.