@@ -13,10 +13,13 @@ import Data.List (List(..), singleton, (:))
1313import Data.Maybe (Maybe (Nothing, Just))
1414import Data.Monoid (mempty )
1515import Data.Path.Pathy (currentDir , parentDir' , file , dir , rootDir , (</>))
16+ import Data.String.Regex (Regex , regex )
17+ import Data.String.Regex.Flags (global , noFlags )
1618import Data.Tuple (Tuple (..))
1719import Data.URI (AbsoluteURI (..), Authority (..), Fragment (..), HierarchicalPart (..), Host (..), Port (..), Query (..), RelativePart (..), RelativeRef (..), Scheme (..), URI (..), UserInfo (..))
1820import Data.URI.AbsoluteURI as AbsoluteURI
1921import Data.URI.Authority as Authority
22+ import Data.URI.Common as Common
2023import Data.URI.Host as Host
2124import Data.URI.Host.Gen as Host.Gen
2225import Data.URI.Port as Port
@@ -74,6 +77,22 @@ testParseQueryParses uri query =
7477 (" parses: \" " <> uri <> " \" " )
7578 (equal (Right query) (runParser Query .parser uri))
7679
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+
7796main :: forall eff . Eff (console :: CONSOLE , testOutput :: TESTOUTPUT , avar :: AVAR , exception :: EXCEPTION , random :: RANDOM | eff ) Unit
7897main = runTest $ suite " Data.URI" do
7998
@@ -443,6 +462,17 @@ main = runTest $ suite "Data.URI" do
443462 " key1=&key2="
444463 (Query (Tuple " key1" (Just " " ) : Tuple " key2" (Just " " ) : Nil ))
445464
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+
446476forAll :: forall eff prop . QC.Testable prop => QCG.Gen prop -> Test (console :: CONSOLE , random :: RANDOM , exception :: EXCEPTION | eff )
447477forAll = quickCheck
448478
0 commit comments