Skip to content

Commit

Permalink
Merge pull request #9 from 8084/master
Browse files Browse the repository at this point in the history
added: assertEqual', assertFalse', assertTrue'
  • Loading branch information
garyb authored Feb 9, 2019
2 parents 76b5eb1 + 7283f24 commit 2044562
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions src/Test/Assert.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ module Test.Assert
( assert
, assert'
, assertEqual
, assertEqual'
, assertFalse
, assertFalse'
, assertThrows
, assertThrows'
, assertTrue
, assertTrue'
) where

import Prelude
Expand Down Expand Up @@ -65,11 +68,26 @@ assertEqual
=> Show a
=> { actual :: a, expected :: a }
-> Effect Unit
assertEqual {actual, expected} = do
assertEqual = assertEqual' ""

-- | Compares the `expected` and `actual` values for equality and throws a
-- | runtime exception with the specified message when the values are not equal.
-- |
-- | The message also indicates the expected value and the actual value.
assertEqual'
:: forall a
. Eq a
=> Show a
=> String
-> { actual :: a, expected :: a }
-> Effect Unit
assertEqual' userMessage {actual, expected} = do
unless result $ error message
assert' message result
where
message = "Expected: " <> show expected <> "\nActual: " <> show actual
message = (if userMessage == "" then "" else userMessage <> "\n")
<> "Expected: " <> show expected
<> "\nActual: " <> show actual
result = actual == expected

-- | Throws a runtime exception when the value is `false`.
Expand All @@ -81,6 +99,17 @@ assertTrue
-> Effect Unit
assertTrue actual = assertEqual { actual, expected: true }

-- | Throws a runtime exception with the specified message when the value is
-- | `false`.
-- |
-- | The message also indicates the expected value (`true`)
-- | and the actual value (`false`).
assertTrue'
:: String
-> Boolean
-> Effect Unit
assertTrue' message actual = assertEqual' message { actual, expected: true }

-- | Throws a runtime exception when the value is `true`.
-- |
-- | The message indicates the expected value (`false`)
Expand All @@ -89,3 +118,14 @@ assertFalse
:: Boolean
-> Effect Unit
assertFalse actual = assertEqual { actual, expected: false }

-- | Throws a runtime exception with the specified message when the value is
-- | `true`.
-- |
-- | The message also indicates the expected value (`false`)
-- | and the actual value (`true`).
assertFalse'
:: String
-> Boolean
-> Effect Unit
assertFalse' message actual = assertEqual' message { actual, expected: false }

0 comments on commit 2044562

Please sign in to comment.