File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 11module URI.Scheme
22 ( Scheme
33 , fromString
4+ , toString
45 , unsafeFromString
56 , parser
67 , print
@@ -42,6 +43,15 @@ instance showScheme ∷ Show Scheme where
4243fromString ∷ String → Maybe Scheme
4344fromString = map Scheme <<< hush <<< flip runParser (parseScheme <* eof)
4445
46+ -- | Returns the string value for a scheme.
47+ -- |
48+ -- | ``` purescript
49+ -- | toString (unsafeFromString "http") == "http"
50+ -- | toString (unsafeFromString "git+ssh") == "git+ssh"
51+ -- | ```
52+ toString ∷ Scheme → NonEmptyString
53+ toString (Scheme s) = s
54+
4555-- | Constructs a `Scheme` part unsafely: if the value is not an acceptable
4656-- | scheme a runtime error will be thrown.
4757-- |
Original file line number Diff line number Diff line change @@ -2,12 +2,21 @@ module Test.URI.Scheme where
22
33import Prelude
44
5- import Test.Spec (Spec , describe )
6- import Test.Util (testIso )
5+ import Data.Maybe (Maybe (..))
6+ import Data.String.NonEmpty as NES
7+ import Test.Spec (Spec , describe , it )
8+ import Test.Util (testIso , equal )
79import URI.Scheme as Scheme
810
911spec ∷ ∀ eff . Spec eff Unit
10- spec =
12+ spec = do
1113 describe " Scheme parser/printer" do
1214 testIso Scheme .parser Scheme .print " http:" (Scheme .unsafeFromString " http" )
1315 testIso Scheme .parser Scheme .print " git+ssh:" (Scheme .unsafeFromString " git+ssh" )
16+ describe " Scheme fromString/toString" do
17+ it " http"
18+ let http = Scheme .unsafeFromString " http"
19+ in equal (Just http) $ Scheme .fromString $ NES .toString $ Scheme .toString http
20+ it " git+ssh"
21+ let git = Scheme .unsafeFromString " git+ssh"
22+ in equal (Just git) $ Scheme .fromString $ NES .toString $ Scheme .toString git
You can’t perform that action at this time.
0 commit comments