@@ -13,10 +13,13 @@ import Data.List (List(..), singleton, (:))
13
13
import Data.Maybe (Maybe (Nothing, Just))
14
14
import Data.Monoid (mempty )
15
15
import Data.Path.Pathy (currentDir , parentDir' , file , dir , rootDir , (</>))
16
+ import Data.String.Regex (Regex , regex )
17
+ import Data.String.Regex.Flags (global , noFlags )
16
18
import Data.Tuple (Tuple (..))
17
19
import Data.URI (AbsoluteURI (..), Authority (..), Fragment (..), HierarchicalPart (..), Host (..), Port (..), Query (..), RelativePart (..), RelativeRef (..), Scheme (..), URI (..), UserInfo (..))
18
20
import Data.URI.AbsoluteURI as AbsoluteURI
19
21
import Data.URI.Authority as Authority
22
+ import Data.URI.Common as Common
20
23
import Data.URI.Host as Host
21
24
import Data.URI.Host.Gen as Host.Gen
22
25
import Data.URI.Port as Port
@@ -74,6 +77,22 @@ testParseQueryParses uri query =
74
77
(" parses: \" " <> uri <> " \" " )
75
78
(equal (Right query) (runParser Query .parser uri))
76
79
80
+ testMatch1FromMatches :: forall a . Either String Regex -> Int -> String -> Maybe String -> TestSuite a
81
+ testMatch1FromMatches rx' n str expected = case rx' of
82
+ Left error -> test " faulty regex given" (assert error false )
83
+ Right rx ->
84
+ test
85
+ (" matches: " <> show rx <> " at " <> show n <> " in " <> show str)
86
+ (equal expected $ Common .match1From rx n str)
87
+
88
+ testMatch1FromMisses :: forall a . Either String Regex -> Int -> String -> TestSuite a
89
+ testMatch1FromMisses rx' n str = case rx' of
90
+ Left error -> test " faulty regex given" (assert error false )
91
+ Right rx ->
92
+ test
93
+ (" does not match: " <> show rx <> " at " <> show n <> " in " <> show str)
94
+ (equal Nothing $ Common .match1From rx n str)
95
+
77
96
main :: forall eff . Eff (console :: CONSOLE , testOutput :: TESTOUTPUT , avar :: AVAR , exception :: EXCEPTION , random :: RANDOM | eff ) Unit
78
97
main = runTest $ suite " Data.URI" do
79
98
@@ -443,6 +462,17 @@ main = runTest $ suite "Data.URI" do
443
462
" key1=&key2="
444
463
(Query (Tuple " key1" (Just " " ) : Tuple " key2" (Just " " ) : Nil ))
445
464
465
+ suite " Common.match1From" do
466
+ testMatch1FromMisses (regex " key1" noFlags) 0 " "
467
+ testMatch1FromMisses (regex " key1" noFlags) 1 " key1"
468
+ testMatch1FromMisses (regex " key1" noFlags) 1 " key1=&key1="
469
+ testMatch1FromMisses (regex " key1" global) 1 " key1=&key1="
470
+ testMatch1FromMisses (regex " key1|key2" noFlags) 1 " key1=&key2="
471
+
472
+ testMatch1FromMatches (regex " key1" noFlags) 0 " key1" (Just " key1" )
473
+ testMatch1FromMatches (regex " key1" noFlags) 6 " key1=&key1=" (Just " key1" )
474
+ testMatch1FromMatches (regex " key1|key2" noFlags) 6 " key1=&key2=" (Just " key2" )
475
+
446
476
forAll :: forall eff prop . QC.Testable prop => QCG.Gen prop -> Test (console :: CONSOLE , random :: RANDOM , exception :: EXCEPTION | eff )
447
477
forAll = quickCheck
448
478
0 commit comments