Skip to content

Commit 269943c

Browse files
authored
Replace logShow with assertEquals' (#135)
1 parent 9804125 commit 269943c

File tree

3 files changed

+51
-17
lines changed

3 files changed

+51
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ New features:
1111
Bugfixes:
1212

1313
Other improvements:
14+
- Replace manual tests with automated tests using `assert` (#135 by @neppord)
1415
- Improve documentation for `united` (#134 by @neppord)
1516

1617
## [v7.0.1](https://github.com/purescript-contrib/purescript-profunctor-lenses/releases/tag/v7.0.1) - 2021-05-06

spago.dhall

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{ name = "profunctor-lenses"
22
, dependencies =
33
[ "arrays"
4+
, "assert"
45
, "bifunctors"
56
, "console"
67
, "const"

test/Main.purs

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,24 @@ import Prelude
44

55
import Control.Monad.State (evalState, get)
66
import Data.Either (Either(..))
7-
import Data.Lens (Getter', Prism', _1, _2, _Just, _Left, collectOf, lens, lens', preview, prism', takeBoth, toArrayOf, traversed, view, lensStore)
7+
import Data.Lens (Getter', Prism', _1, _2, _Just, _Left, collectOf, lens, lens', lensStore, preview, prism', takeBoth, toArrayOf, traversed, view)
88
import Data.Lens.Fold ((^?))
99
import Data.Lens.Fold.Partial ((^?!), (^@?!))
1010
import Data.Lens.Grate (Grate, cloneGrate, grate, zipWithOf)
1111
import Data.Lens.Index (ix)
1212
import Data.Lens.Indexed (itraversed, reindexed)
13-
import Data.Lens.Lens (ilens, IndexedLens, cloneIndexedLens)
13+
import Data.Lens.Lens (IndexedLens, cloneIndexedLens, ilens)
1414
import Data.Lens.Record (prop)
1515
import Data.Lens.Setter (iover)
1616
import Data.Lens.Traversal (cloneTraversal)
17-
import Data.Lens.Zoom (ATraversal', IndexedTraversal', Traversal, Traversal', Lens, Lens', zoom)
17+
import Data.Lens.Zoom (ATraversal', IndexedTraversal', Lens, Lens', Traversal, Traversal', zoom)
1818
import Data.Maybe (Maybe(..))
1919
import Data.Tuple (Tuple(..), fst, snd)
2020
import Effect (Effect)
21-
import Effect.Console (logShow)
2221
import Partial.Unsafe (unsafePartial)
22+
import Test.Assert (assertEqual')
2323
import Type.Proxy (Proxy(..))
2424

25-
-- Traversing an array nested within a record
2625
foo :: forall a b r. Lens { foo :: a | r } { foo :: b | r } a b
2726
foo = prop (Proxy :: Proxy "foo")
2827

@@ -43,7 +42,7 @@ data ABC = A (Array XYZ) | B | C
4342
data XYZ = X Number | Y | Z
4443

4544
_A :: Prism' ABC (Array XYZ)
46-
_A = prism' A case _ of
45+
_A = prism' A case _ of
4746
(A array) -> Just array
4847
_ -> Nothing
4948

@@ -130,14 +129,47 @@ lensStoreExampleInt = lens' case _ of
130129

131130
main :: Effect Unit
132131
main = do
133-
logShow $ view bars doc
134-
logShow $ view barAndFoo { bar: "bar", foo: "foo" }
135-
logShow $ doc2 ^? _1bars
136-
logShow $ arrayOfNumbers $ A [(X 1.0), (X 2.0), (X 3.0)]
137-
logShow $ unsafePartial $ doc2 ^?! _1bars
138-
logShow $ unsafePartial $ Tuple 0 1 ^@?! i_2
139-
logShow stateTest
140-
logShow cloneTest
141-
logShow (summing (Tuple 1 2) (Tuple 3 4))
142-
logShow (collectOfTest (\a -> Tuple (a + a) (a * a)) [4, 5])
143-
logShow cloneTraversalTest
132+
assertEqual' """view bars doc"""
133+
{ expected: "Hello World"
134+
, actual: view bars doc
135+
}
136+
assertEqual' """view barAndFoo { bar: "bar", foo: "foo" }"""
137+
{ expected: Tuple "bar" "foo"
138+
, actual: view barAndFoo { bar: "bar", foo: "foo" }
139+
}
140+
assertEqual' """doc2 ^? _1bars"""
141+
{ expected: Just 2
142+
, actual: doc2 ^? _1bars
143+
}
144+
assertEqual' """arrayOfNumbers $ A [(X 1.0), (X 2.0), (X 3.0)]"""
145+
{ expected: [1.0,2.0,3.0]
146+
, actual: arrayOfNumbers $ A [(X 1.0), (X 2.0), (X 3.0)]
147+
}
148+
assertEqual' """unsafePartial $ doc2 ^?! _1bars"""
149+
{ expected: 2
150+
, actual: unsafePartial $ doc2 ^?! _1bars
151+
}
152+
assertEqual' """unsafePartial $ Tuple 0 1 ^@?! i_2"""
153+
{ expected: Tuple 0 1
154+
, actual: unsafePartial $ Tuple 0 1 ^@?! i_2
155+
}
156+
assertEqual' """stateTest"""
157+
{ expected: Tuple 4 "FooBar"
158+
, actual: stateTest
159+
}
160+
assertEqual' """cloneTest"""
161+
{ expected: Tuple 1 (Tuple 0 2)
162+
, actual: cloneTest
163+
}
164+
assertEqual' """summing (Tuple 1 2) (Tuple 3 4)"""
165+
{ expected: Tuple 4 6
166+
, actual: summing (Tuple 1 2) (Tuple 3 4)
167+
}
168+
assertEqual' """collectOfTest (\a -> Tuple (a + a) (a * a)) [4, 5]"""
169+
{ expected: Tuple [8,10] [16,25]
170+
, actual: collectOfTest (\a -> Tuple (a + a) (a * a)) [4, 5]
171+
}
172+
assertEqual' """cloneTraversalTest"""
173+
{ expected: Just 1
174+
, actual: cloneTraversalTest
175+
}

0 commit comments

Comments
 (0)