Skip to content

Commit

Permalink
If the position of an erroneous character is detected, verify that it…
Browse files Browse the repository at this point in the history
… is detected at the correct location.
  • Loading branch information
jonathanknowles authored and KtorZ committed May 20, 2019
1 parent f4062a3 commit 72a0802
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/bech32/src/Codec/Binary/Bech32/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ module Codec.Binary.Bech32.Internal
, noPadding
, yesPadding

-- * Character Set Manipulation
-- * Character Manipulation
, CharPosition (..)
, charset
, word5ToChar
, charToWord5
, word5ToChar

) where

Expand Down
20 changes: 16 additions & 4 deletions lib/bech32/test/Codec/Binary/Bech32Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ module Codec.Binary.Bech32Spec
import Prelude

import Codec.Binary.Bech32.Internal
( HumanReadablePart, humanReadablePartToBytes, mkHumanReadablePart )
( CharPosition (..)
, DecodingError (..)
, HumanReadablePart
, humanReadablePartToBytes
, mkHumanReadablePart
)
import Control.Monad
( forM_ )
import Data.Bits
Expand Down Expand Up @@ -42,6 +47,7 @@ import Test.QuickCheck
, property
, vectorOf
, (.&&.)
, (.||.)
, (===)
, (==>)
)
Expand Down Expand Up @@ -154,9 +160,15 @@ spec = do
return $
index /= separatorIndex ==>
recombinedString /= validString ==>
(BS.length recombinedString === BS.length validString)
.&&.
(Bech32.decode recombinedString `shouldSatisfy` isLeft)
BS.length recombinedString == BS.length validString ==> (
-- error location detection is best effort:
(Bech32.decode recombinedString `shouldBe`
Left (StringToDecodeContainsInvalidChars
[CharPosition index]))
.||.
(Bech32.decode recombinedString `shouldBe`
Left (StringToDecodeContainsInvalidChars []))
)

it "Decoding fails for an upper-case string with a lower-case \
\character." $
Expand Down

0 comments on commit 72a0802

Please sign in to comment.