Skip to content

Commit eb2ed70

Browse files
Add tests; extended patterns.
1 parent 1cf1f9c commit eb2ed70

4 files changed

Lines changed: 37 additions & 5 deletions

File tree

Base.hs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import System.IO as X (Handle, hClose)
3030
import System.IO.Unsafe as X
3131
import Text.Printf as X
3232
import Text.Read as X (readMaybe)
33-
import Text.Regex.Posix (match, makeRegexOptsM, compIgnoreCase)
33+
import Text.Regex.Posix (match, makeRegexOptsM, compIgnoreCase, compExtended)
3434

3535
import System.Clock
3636

@@ -81,9 +81,8 @@ matches s =
8181
-}
8282

8383
-- regex-posix version (reputed to be slow and buggy)
84-
matches s = case makeRegexOptsM compIgnoreCase 0 s of
85-
Just p -> match p
86-
_ -> const False
84+
matches s = maybe (const False) match $
85+
makeRegexOptsM (compIgnoreCase + compExtended) 0 s
8786

8887
-- not yet tried:
8988
-- regex-tdfa (mass Text conversion, parsec dep) text import

hmp3-ng.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ test-suite test
9999
main-is: Main.hs
100100
hs-source-dirs: test
101101
other-modules:
102+
BaseSpec
102103
ConfigSpec
103104
CoreSpec
104105
DecoderSpec

test/BaseSpec.hs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
module BaseSpec (tests) where
2+
3+
import Data.ByteString.UTF8 qualified as UTF8
4+
5+
import Test.Tasty
6+
import Test.Tasty.HUnit
7+
8+
import Base (matches)
9+
10+
tests :: TestTree
11+
tests = testGroup "Base"
12+
[ testGroup "match"
13+
[ t True "exact" "foo" "fooBar"
14+
, t True "caseless" "FOO" "fooBar"
15+
, t False "invalid" "[" "any[thing"
16+
, t True "alt" "(foo|az)Q" "bazQux"
17+
, t True "dot" "o.a" "foobar"
18+
, t True "Unicode" "jör" "Björk"
19+
, t True "dot Unicode" "j.r" "Björk"
20+
, t True "Nordic case" "bør" "BØrnE"
21+
, t True "Greek case" "Λω" "ΦλΩα"
22+
, t True "dot CJK" "中.人" "中國人"
23+
]
24+
]
25+
26+
27+
t :: Bool -> String -> String -> String -> TestTree
28+
t b tag pat str =
29+
testCase tag $ matches (UTF8.fromString pat) (UTF8.fromString str) @?= b
30+

test/Main.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module Main (main) where
22

33
import Test.Tasty
44

5+
import BaseSpec qualified
56
import ConfigSpec qualified
67
import CoreSpec qualified
78
import DecoderSpec qualified
@@ -11,7 +12,8 @@ import WidthSpec qualified
1112

1213
main :: IO ()
1314
main = defaultMain $ testGroup "hmp3-ng"
14-
[ ConfigSpec.tests
15+
[ BaseSpec.tests
16+
, ConfigSpec.tests
1517
, CoreSpec.tests
1618
, DecoderSpec.tests
1719
, StyleSpec.tests

0 commit comments

Comments
 (0)