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 1
1
module URI.Scheme
2
2
( Scheme
3
3
, fromString
4
+ , toString
4
5
, unsafeFromString
5
6
, parser
6
7
, print
@@ -42,6 +43,15 @@ instance showScheme ∷ Show Scheme where
42
43
fromString ∷ String → Maybe Scheme
43
44
fromString = map Scheme <<< hush <<< flip runParser (parseScheme <* eof)
44
45
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
+
45
55
-- | Constructs a `Scheme` part unsafely: if the value is not an acceptable
46
56
-- | scheme a runtime error will be thrown.
47
57
-- |
Original file line number Diff line number Diff line change @@ -2,12 +2,21 @@ module Test.URI.Scheme where
2
2
3
3
import Prelude
4
4
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 )
7
9
import URI.Scheme as Scheme
8
10
9
11
spec ∷ ∀ eff . Spec eff Unit
10
- spec =
12
+ spec = do
11
13
describe " Scheme parser/printer" do
12
14
testIso Scheme .parser Scheme .print " http:" (Scheme .unsafeFromString " http" )
13
15
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