From 3ed561bfd863da9a35d0ed69d45f059a12001ba1 Mon Sep 17 00:00:00 2001 From: Irakli Safareli Date: Wed, 21 Mar 2018 00:32:08 +0100 Subject: [PATCH] add Scheme.toString --- src/URI/Scheme.purs | 10 ++++++++++ test/URI/Scheme.purs | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/URI/Scheme.purs b/src/URI/Scheme.purs index 9364371..d161528 100644 --- a/src/URI/Scheme.purs +++ b/src/URI/Scheme.purs @@ -1,6 +1,7 @@ module URI.Scheme ( Scheme , fromString + , toString , unsafeFromString , parser , print @@ -42,6 +43,15 @@ instance showScheme ∷ Show Scheme where fromString ∷ String → Maybe Scheme fromString = map Scheme <<< hush <<< flip runParser (parseScheme <* eof) +-- | Returns the string value for a scheme. +-- | +-- | ``` purescript +-- | toString (unsafeFromString "http") == "http" +-- | toString (unsafeFromString "git+ssh") == "git+ssh" +-- | ``` +toString ∷ Scheme → NonEmptyString +toString (Scheme s) = s + -- | Constructs a `Scheme` part unsafely: if the value is not an acceptable -- | scheme a runtime error will be thrown. -- | diff --git a/test/URI/Scheme.purs b/test/URI/Scheme.purs index d51c9c9..460e25a 100644 --- a/test/URI/Scheme.purs +++ b/test/URI/Scheme.purs @@ -2,12 +2,21 @@ module Test.URI.Scheme where import Prelude -import Test.Spec (Spec, describe) -import Test.Util (testIso) +import Data.Maybe (Maybe(..)) +import Data.String.NonEmpty as NES +import Test.Spec (Spec, describe, it) +import Test.Util (testIso, equal) import URI.Scheme as Scheme spec ∷ ∀ eff. Spec eff Unit -spec = +spec = do describe "Scheme parser/printer" do testIso Scheme.parser Scheme.print "http:" (Scheme.unsafeFromString "http") testIso Scheme.parser Scheme.print "git+ssh:" (Scheme.unsafeFromString "git+ssh") + describe "Scheme fromString/toString" do + it "http" + let http = Scheme.unsafeFromString "http" + in equal (Just http) $ Scheme.fromString $ NES.toString $ Scheme.toString http + it "git+ssh" + let git = Scheme.unsafeFromString "git+ssh" + in equal (Just git) $ Scheme.fromString $ NES.toString $ Scheme.toString git