File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -70,11 +70,12 @@ instance nullarySumCodecCtor ∷ IsSymbol name ⇒ NullarySumCodec (Constructor
7070 tagRaw = reflectSymbol (Proxy ∷ Proxy name )
7171 tag = encoding.mapTag tagRaw
7272 in
73- J .fromString $ tag
73+ J .fromString tag
7474 nullarySumDecode encoding name j = do
75- tagRaw ← note (CA.Named name (CA.TypeMismatch " String" )) (J .toString j)
76- let tag = encoding.mapTag tagRaw
77- if tag /= reflectSymbol (Proxy ∷ Proxy name ) then
75+ actualTag ← note (CA.Named name (CA.TypeMismatch " String" )) (J .toString j)
76+ let expectedTagRaw = reflectSymbol (Proxy ∷ Proxy name )
77+ let expectedTag = encoding.mapTag expectedTagRaw
78+ if expectedTag /= actualTag then
7879 Left (CA.Named name (CA.UnexpectedValue j))
7980 else
8081 Right (Constructor NoArguments )
Original file line number Diff line number Diff line change @@ -2,14 +2,15 @@ module Test.Generic where
22
33import Prelude
44
5- import Data.Codec.Argonaut.Generic (nullarySum )
5+ import Data.Codec.Argonaut.Generic (nullarySum , nullarySumWith )
66import Data.Generic.Rep (class Generic )
77import Data.Show.Generic (genericShow )
88import Effect (Effect )
99import Effect.Console (log )
1010import Test.QuickCheck (quickCheck )
1111import Test.QuickCheck.Arbitrary (genericArbitrary )
1212import Test.QuickCheck.Gen (Gen )
13+ import Test.Sum (check )
1314import Test.Util (propCodec )
1415
1516data MySum = Ctor1 | Ctor2 | MoarCtors
@@ -27,3 +28,9 @@ main ∷ Effect Unit
2728main = do
2829 log " Check nullarySum"
2930 quickCheck (propCodec genMySum (nullarySum " MySum" ))
31+
32+ let opts = { mapTag: \tag → " My" <> tag }
33+
34+ check (nullarySumWith opts " MySum" ) Ctor1 " \" MyCtor1\" "
35+ check (nullarySumWith opts " MySum" ) MoarCtors " \" MyMoarCtors\" "
36+
You can’t perform that action at this time.
0 commit comments