Skip to content

Update to v0.14.0-rc3 #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:

- name: Set up a PureScript toolchain
uses: purescript-contrib/setup-purescript@main
with:
purescript: "0.14.0-rc3"

- name: Cache PureScript dependencies
uses: actions/cache@v2
Expand Down
26 changes: 13 additions & 13 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "purescript-uri",
"homepage": "https://github.com/slamdata/purescript-uri",
"description": "A type-safe parser, printer, and ADT for URLs and URIs. ",
"description": "A type-safe parser, printer, and ADT for URLs and URIs.",
"license": "Apache-2.0",
"repository": {
"type": "git",
"url": "git://github.com/slamdata/purescript-uri.git"
"url": "https://github.com/slamdata/purescript-uri.git"
},
"ignore": [
"**/.*",
Expand All @@ -17,18 +17,18 @@
"package.json"
],
"dependencies": {
"purescript-arrays": "^5.0.0",
"purescript-generics-rep": "^6.0.0",
"purescript-globals": "^4.0.0",
"purescript-integers": "^4.0.0",
"purescript-parsing": "^5.0.0",
"purescript-profunctor-lenses": "^6.0.0",
"purescript-unfoldable": "^4.0.0",
"purescript-these": "^4.0.0"
"purescript-arrays": "master",
"purescript-generics-rep": "master",
"purescript-js-uri": "https://github.com/purescript-contrib/purescript-js-uri.git#main",
"purescript-integers": "master",
"purescript-parsing": "main",
"purescript-profunctor-lenses": "main",
"purescript-unfoldable": "master",
"purescript-these": "main"
},
"devDependencies": {
"purescript-quickcheck": "^6.1.0",
"purescript-spec": "^4.0.1",
"purescript-aff": "^5.1.2"
"purescript-assert": "master",
"purescript-quickcheck": "master",
"purescript-aff": "main"
}
}
2 changes: 1 addition & 1 deletion packages.dhall
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200822/packages.dhall sha256:b4f151f1af4c5cb6bf5437489f4231fbdd92792deaf32971e6bcb0047b3dd1f8
https://raw.githubusercontent.com/purescript/package-sets/prepare-0.14/src/packages.dhall

in upstream
6 changes: 4 additions & 2 deletions spago.dhall
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
, dependencies =
[ "aff"
, "arrays"
, "assert"
, "generics-rep"
, "globals"
, "integers"
, "js-uri"
, "numbers"
, "parsing"
, "profunctor-lenses"
, "quickcheck"
, "these"
, "transformers"
, "unfoldable"
, "spec"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
Expand Down
9 changes: 5 additions & 4 deletions src/URI/Common.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ import Data.Array as Array
import Data.Either (Either(..), either)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (fromJust)
import Data.Newtype (class Newtype, un)
import Data.String (joinWith) as String
import Data.String.CodeUnits (singleton) as String
import Data.String.NonEmpty (NonEmptyString)
import Data.String.NonEmpty.CodeUnits (singleton) as NES
import Data.String.NonEmpty (unsafeFromString, toString) as NES
import Global.Unsafe (unsafeDecodeURIComponent, unsafeEncodeURIComponent)
import JSURI (decodeURIComponent, encodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Text.Parsing.Parser (ParseError(..), ParseState(..), Parser, ParserT(..), runParser)
import Text.Parsing.Parser.String (anyChar, char, eof, oneOf, satisfy)
Expand Down Expand Up @@ -96,16 +97,16 @@ printEncoded p s = either (const s) identity (runParser s parse)
simpleChar ∷ Parser String String
simpleChar = String.singleton <$> p
encodedChar ∷ Parser String String
encodedChar = unsafeEncodeURIComponent <<< String.singleton <$> anyChar
encodedChar = unsafePartial fromJust <<< encodeURIComponent <<< String.singleton <$> anyChar

-- | A version of [`printEncoded`](#v:printEncoded) that operates on non-empty
-- | strings.
printEncoded' ∷ Parser String Char → NonEmptyString → NonEmptyString
printEncoded' p =
unsafePartial NES.unsafeFromString <<< printEncoded p <<< NES.toString

-- | A version of [`decodeURIComponent`](https://pursuit.purescript.org/packages/purescript-globals/docs/Global#v:decodeURIComponent)
-- | A version of [`decodeURIComponent`](https://pursuit.purescript.org/packages/purescript-jsuri/docs/JSURI#v:decodeURIComponent)
-- | that operates on non-empty strings.
decodeURIComponent' ∷ NonEmptyString → NonEmptyString
decodeURIComponent' =
unsafePartial NES.unsafeFromString <<< unsafeDecodeURIComponent <<< NES.toString
unsafePartial NES.unsafeFromString <<< unsafePartial fromJust <<< decodeURIComponent <<< NES.toString
9 changes: 5 additions & 4 deletions src/URI/Extra/QueryPairs.purs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ import Data.Bifunctor (bimap)
import Data.Either (Either)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (Maybe(..))
import Data.Maybe (Maybe(..), fromJust)
import Data.String as String
import Data.String.NonEmpty.CodeUnits (singleton) as NES
import Data.String.NonEmpty (joinWith) as NES
import Data.Traversable (traverse)
import Data.Tuple (Tuple(..))
import Global.Unsafe (unsafeDecodeURIComponent)
import JSURI (decodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Text.Parsing.Parser (ParseError(..), Parser, runParser)
import Text.Parsing.Parser.Combinators (optionMaybe, sepBy)
import Text.Parsing.Parser.String (char, oneOf)
Expand Down Expand Up @@ -136,7 +137,7 @@ keyFromString = Key <<< printEncoded keyPartChar
-- | keyToString (unsafeKeyFromString "foo%23bar") = "foo#bar"
-- | ```
keyToString ∷ Key → String
keyToString (Key s) = unsafeDecodeURIComponent s
keyToString (Key s) = unsafePartial $ fromJust $ decodeURIComponent s

-- | Constructs a key value from a string directly - no percent-encoding
-- | will be applied. This is useful when using a custom encoding scheme for
Expand Down Expand Up @@ -188,7 +189,7 @@ valueFromString =
-- | valueToString (unsafeValueFromString "foo%23bar") = "foo#bar"
-- | ```
valueToString ∷ Value → String
valueToString (Value s) = unsafeDecodeURIComponent s
valueToString (Value s) = unsafePartial $ fromJust $ decodeURIComponent s

-- | Constructs a value from a string directly - no percent-encoding
-- | will be applied. This is useful when using a custom encoding scheme for
Expand Down
6 changes: 4 additions & 2 deletions src/URI/Fragment.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import Prelude

import Control.Alt ((<|>))
import Data.Array as Array
import Data.Maybe (fromJust)
import Data.String.NonEmpty.CodeUnits (singleton) as NES
import Data.String.NonEmpty (joinWith) as NES
import Global.Unsafe (unsafeDecodeURIComponent)
import JSURI (decodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Text.Parsing.Parser (Parser)
import Text.Parsing.Parser.String (char)
import URI.Common (subDelims, unreserved, pctEncoded, printEncoded)
Expand Down Expand Up @@ -52,7 +54,7 @@ fromString = Fragment <<< printEncoded fragmentChar
-- | toString (unsafeFromString "foo%23bar") = "foo#bar"
-- | ```
toString ∷ Fragment → String
toString (Fragment s) = unsafeDecodeURIComponent s
toString (Fragment s) = unsafePartial $ fromJust $ decodeURIComponent s

-- | Constructs a fragment value from a string directly - no percent-encoding
-- | will be applied. This is useful when using a custom encoding scheme for
Expand Down
6 changes: 4 additions & 2 deletions src/URI/Path/Segment.purs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ import Prelude
import Control.Alt ((<|>))
import Data.Array as Array
import Data.Array.NonEmpty as NEA
import Data.Maybe (fromJust)
import Data.String.NonEmpty (NonEmptyString)
import Data.String.NonEmpty.CodeUnits (singleton) as NES
import Data.String.NonEmpty (join1With, joinWith, toString) as NES
import Global.Unsafe (unsafeDecodeURIComponent)
import JSURI (decodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Text.Parsing.Parser (Parser)
import Text.Parsing.Parser.String (char)
import URI.Common (decodeURIComponent', pctEncoded, printEncoded, printEncoded', subDelims, unreserved)
Expand All @@ -59,7 +61,7 @@ segmentFromString = PathSegment <<< printEncoded segmentChar
-- | Returns the string value for a segment, percent-decoding any characters
-- | that require it.
segmentToString ∷ PathSegment → String
segmentToString (PathSegment s) = unsafeDecodeURIComponent s
segmentToString (PathSegment s) = unsafePartial $ fromJust $ decodeURIComponent s

-- | Constructs a segment value from a string directly - no percent-encoding
-- | will be applied. This is useful when using a custom encoding scheme for
Expand Down
5 changes: 2 additions & 3 deletions src/URI/Port.purs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ module URI.Port
import Prelude

import Data.Array as Array
import Data.Int (fromNumber)
import Data.Int (decimal, fromStringAs)
import Data.Maybe (Maybe(..))
import Data.String.CodeUnits as String
import Global (readInt)
import Partial.Unsafe (unsafeCrashWith)
import Text.Parsing.Parser (Parser, fail)
import Text.Parsing.Parser.String (char)
Expand Down Expand Up @@ -55,7 +54,7 @@ unsafeFromInt i =
parser ∷ Parser String Port
parser = do
s ← String.fromCharArray <$> (char ':' *> Array.some digit)
case fromNumber $ readInt 10 s of
case fromStringAs decimal s of
Just x → pure (Port x)
_ → fail "Expected a valid port number"

Expand Down
6 changes: 4 additions & 2 deletions src/URI/Query.purs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import Prelude

import Control.Alt ((<|>))
import Data.Array as Array
import Data.Maybe (fromJust)
import Data.String.NonEmpty.CodeUnits (singleton) as NES
import Data.String.NonEmpty (joinWith) as NES
import Global.Unsafe (unsafeDecodeURIComponent)
import JSURI (decodeURIComponent)
import Partial.Unsafe (unsafePartial)
import Text.Parsing.Parser (Parser)
import Text.Parsing.Parser.String (char)
import URI.Common (subDelims, unreserved, pctEncoded, printEncoded)
Expand Down Expand Up @@ -56,7 +58,7 @@ fromString = Query <<< printEncoded queryChar
-- | toString (unsafeFromString "foo%23bar") = "foo#bar"
-- | ```
toString ∷ Query → String
toString (Query s) = unsafeDecodeURIComponent s
toString (Query s) = unsafePartial $ fromJust $ decodeURIComponent s

-- | Constructs a query value from a string directly - no percent-encoding
-- | will be applied. This is useful when using a custom encoding scheme for
Expand Down
6 changes: 2 additions & 4 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import Prelude

import Effect (Effect)
import Effect.Aff (launchAff_)
import Test.Spec.Reporter (consoleReporter)
import Test.Spec.Runner (runSpec)
import Control.Monad.Reader (runReaderT)
import Test.URI.AbsoluteURI as AbsoluteURI
import Test.URI.Authority as Authority
import Test.URI.Extra.MultiHostPortPair as Extra.MultiHostPortPair
Expand All @@ -19,9 +18,8 @@ import Test.URI.Scheme as Scheme
import Test.URI.URIRef as URIRef
import Test.URI.UserInfo as UserInfo


main ∷ Effect Unit
main = launchAff_ $ runSpec [consoleReporter] do
main = launchAff_ $ flip runReaderT 0 do
Scheme.spec
UserInfo.spec
Host.spec
Expand Down
35 changes: 35 additions & 0 deletions test/Spec.purs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Test.Spec where

import Prelude

import Effect.Aff (Aff)
import Effect.Console (log)
import Effect.Class (class MonadEffect, liftEffect)
import Effect.Exception (Error, error)
import Data.Monoid (power, guard)
import Control.Monad.Reader (ReaderT)
import Control.Monad.Reader.Class (ask, local)
import Control.Monad.Error.Class (class MonadThrow, throwError)
import Test.Assert (assertEqual)

-----------------------------------------------------------------
-- Provides a similar API to purescript-spec, but without a dependency

type Spec a = ReaderT Int Aff a

describe :: String -> Spec Unit -> Spec Unit
describe msg runTest = do
indentation <- ask
let spacing = guard (indentation > 0) " "
liftEffect $ log $ (power ">>" indentation) <> spacing <> msg
local (_ + 1) runTest

it :: String -> Spec Unit -> Spec Unit
it = describe

shouldEqual :: forall m a. MonadEffect m => Eq a => Show a => a -> a -> m Unit
shouldEqual actual expected =
liftEffect $ assertEqual { actual, expected }

fail :: forall m. MonadThrow Error m => String -> m Unit
fail = throwError <<< error
10 changes: 5 additions & 5 deletions test/URI/AbsoluteURI.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Prelude
import Data.Either (Either(..))
import Data.Maybe (Maybe(..))
import Data.String.NonEmpty (nes)
import Data.Symbol (SProxy(..))
import Type.Proxy (Proxy(..))
import Data.These (These(..))
import Data.Tuple (Tuple(..))
import Test.Spec (Spec, describe)
Expand All @@ -32,7 +32,7 @@ spec =
(HierarchicalPartAuth
(Authority
Nothing
(Just (This (NameAddress (RegName.unsafeFromString $ nes (SProxy :: SProxy "localhost"))))))
(Just (This (NameAddress (RegName.unsafeFromString $ nes (Proxy :: Proxy "localhost"))))))
(path ["testBucket"]))
(Just (Query.unsafeFromString "password=&docTypeKey=")))
testIso
Expand All @@ -44,7 +44,7 @@ spec =
(HierarchicalPartAuth
(Authority
Nothing
(Just (Both (NameAddress (RegName.unsafeFromString $ nes (SProxy :: SProxy "localhost"))) (Port.unsafeFromInt 9999))))
(Just (Both (NameAddress (RegName.unsafeFromString $ nes (Proxy :: Proxy "localhost"))) (Port.unsafeFromInt 9999))))
(path ["testBucket"]))
(Just (Query.unsafeFromString "password=pass&docTypeKey=type&queryTimeoutSeconds=20")))
testIso
Expand All @@ -54,7 +54,7 @@ spec =
(AbsoluteURI
(Scheme.unsafeFromString "foo")
(HierarchicalPartNoAuth
(Just (Left (PathAbsolute (Just (Tuple (PathSegment.unsafeSegmentNZFromString $ nes (SProxy :: SProxy "abc")) [PathSegment.unsafeSegmentFromString "def"]))))))
(Just (Left (PathAbsolute (Just (Tuple (PathSegment.unsafeSegmentNZFromString $ nes (Proxy :: Proxy "abc")) [PathSegment.unsafeSegmentFromString "def"]))))))
Nothing)
testIso
(AbsoluteURI.parser options)
Expand All @@ -63,7 +63,7 @@ spec =
(AbsoluteURI
(Scheme.unsafeFromString "foo")
(HierarchicalPartNoAuth
(Just (Right (PathRootless (Tuple (PathSegment.unsafeSegmentNZFromString $ nes (SProxy :: SProxy "abc")) [PathSegment.unsafeSegmentFromString "def"])))))
(Just (Right (PathRootless (Tuple (PathSegment.unsafeSegmentNZFromString $ nes (Proxy :: Proxy "abc")) [PathSegment.unsafeSegmentFromString "def"])))))
Nothing)

path ∷ Array String → Path
Expand Down
10 changes: 5 additions & 5 deletions test/URI/Authority.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude

import Data.Maybe (Maybe(..))
import Data.String.NonEmpty (nes)
import Data.Symbol (SProxy(..))
import Type.Proxy (Proxy(..))
import Data.These (These(..))
import Test.Spec (Spec, describe)
import Test.Util (testIso)
Expand All @@ -25,21 +25,21 @@ spec =
"//localhost"
(Authority
Nothing
(Just (This (NameAddress (RegName.unsafeFromString (nes (SProxy :: SProxy "localhost")))))))
(Just (This (NameAddress (RegName.unsafeFromString (nes (Proxy :: Proxy "localhost")))))))
testIso
(Authority.parser options)
(Authority.print options)
"//localhost:3000"
(Authority
Nothing
(Just (Both (NameAddress (RegName.unsafeFromString (nes (SProxy :: SProxy "localhost")))) (Port.unsafeFromInt 3000))))
(Just (Both (NameAddress (RegName.unsafeFromString (nes (Proxy :: Proxy "localhost")))) (Port.unsafeFromInt 3000))))
testIso
(Authority.parser options)
(Authority.print options)
"//user@localhost:3000"
(Authority
(Just (UserInfo.unsafeFromString (nes (SProxy :: SProxy "user"))))
(Just (Both (NameAddress (RegName.unsafeFromString (nes (SProxy :: SProxy "localhost")))) (Port.unsafeFromInt 3000))))
(Just (UserInfo.unsafeFromString (nes (Proxy :: Proxy "user"))))
(Just (Both (NameAddress (RegName.unsafeFromString (nes (Proxy :: Proxy "localhost")))) (Port.unsafeFromInt 3000))))
testIso
(Authority.parser options)
(Authority.print options)
Expand Down
Loading