Expect
Testing
Assertions a Test case returns.
A test passes when its function returns a passing Expectation. equal is the one you will reach for first: expected value, then actual value. On failure, selm test prints both.
test "says hello"
<| (\_ctx -> Expect.equal "Hello, Ada" (hello "Ada"))true and false check a Bool. ok, onOk, and equalOk check a Result String. fail and pass build an expectation from a case when the other helpers do not fit the branch.
Types
Expectation
type Expectation = ExpectationThe result of one assertion: pass, or fail with a message.
Return it from the function you give to Test.test. The runner treats any other return value as a failure.
Examples
Expect.equal "Hello, Ada" (hello "Ada")Values
equal
equal : a -> a -> ExpectationPass when both values are the same. The expected value comes first.
Examples
Expect.equal "Hello, Ada" (hello "Ada")
Expect.equal 2 (1 + 1)A mismatch prints Expected and Actual.
notEqual
notEqual : a -> a -> ExpectationPass when the values differ.
Examples
Expect.notEqual "" nametrue
true : Bool -> ExpectationPass when the value is True.
Examples
Expect.true (String.contains "Ada" (hello "Ada"))Fold several checks into one expectation with &&.
false
false : Bool -> ExpectationPass when the value is False.
Examples
Expect.false (name == "")fail
fail : String -> ExpectationFail with a message.
Use this on a case branch that should not happen. ok is the shorter form when the failure string is already the Err.
Examples
case boot program of
Ok _ ->
Expect.equal 1 (currentCount ())
Err _ ->
Expect.fail "could not start"pass
pass : ExpectationAn expectation that always passes.
Return it when an earlier branch already checked the interesting part and this branch only needs to satisfy the Expectation type.
Examples
case parse name of
Ok _ ->
Expect.pass
Err err ->
Expect.fail errok
ok : Result String a -> ExpectationPass when the result is Ok. On Err, fail with that string.
The error type is String. Other error types need a case and fail.
Examples
Expect.ok (parseEmail "ada@example.com")onOk
onOk : Result String a -> (a -> Expectation) -> ExpectationWhen the result is Ok, run the next assertion on the value.
An Err fails with its string and skips the function.
Examples
parseEmail "ada@example.com"
|> Expect.onOk (\email -> Expect.equal "ada@example.com" email)equalOk
equalOk : a -> Result String a -> ExpectationPass when the result is Ok and the value matches.
The expected value comes first, same as equal. An Err fails with its string.
Examples
Expect.equalOk "ada@example.com" (parseEmail "ada@example.com")