Skip to content
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

Update package for use with spago #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
**DS_Store
output/
.psc-package/
.spago/
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,34 @@ instance decodeXmlUser :: DecodeXML User where
## Documentation

Documentation is published on [Pursuit](https://pursuit.purescript.org/packages/purescript-xml).


## Installation (Spago)

Add this to the additions section of your `packages.json` file:

```dhall
let additions =
{ xml =
{ dependencies =
[ "prelude"
, "unordered-collections"
, "lists"
, "parsing"
, "integers"
]
, repo =
"https://github.com/voteliquid/purescript-xml.git"
, version =
"master"
}
}
```

## Testing

purescript-xml's testsuite can be run using:

```bash
$ spago -x test.dhall test
```
128 changes: 128 additions & 0 deletions packages.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{-
Welcome to your new Dhall package-set!

Below are instructions for how to edit this file for most use
cases, so that you don't need to know Dhall to use it.

## Warning: Don't Move This Top-Level Comment!

Due to how `dhall format` currently works, this comment's
instructions cannot appear near corresponding sections below
because `dhall format` will delete the comment. However,
it will not delete a top-level comment like this one.

## Use Cases

Most will want to do one or both of these options:
1. Override/Patch a package's dependency
2. Add a package not already in the default package set

This file will continue to work whether you use one or both options.
Instructions for each option are explained below.

### Overriding/Patching a package

Purpose:
- Change a package's dependency to a newer/older release than the
default package set's release
- Use your own modified version of some dependency that may
include new API, changed API, removed API by
using your custom git repo of the library rather than
the package set's repo

Syntax:
Replace the overrides' "{=}" (an empty record) with the following idea
The "//" or "⫽" means "merge these two records and
when they have the same value, use the one on the right:"
-------------------------------
let overrides =
{ packageName =
upstream.packageName // { updateEntity1 = "new value", updateEntity2 = "new value" }
, packageName =
upstream.packageName // { version = "v4.0.0" }
, packageName =
upstream.packageName // { repo = "https://www.example.com/path/to/new/repo.git" }
}
-------------------------------

Example:
-------------------------------
let overrides =
{ halogen =
upstream.halogen // { version = "master" }
, halogen-vdom =
upstream.halogen-vdom // { version = "v4.0.0" }
}
-------------------------------

### Additions

Purpose:
- Add packages that aren't already included in the default package set

Syntax:
Replace the additions' "{=}" (an empty record) with the following idea:
-------------------------------
let additions =
{ package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, package-name =
{ dependencies =
[ "dependency1"
, "dependency2"
]
, repo =
"https://example.com/path/to/git/repo.git"
, version =
"tag ('v4.0.0') or branch ('master')"
}
, etc.
}
-------------------------------

Example:
-------------------------------
let additions =
{ benchotron =
{ dependencies =
[ "arrays"
, "exists"
, "profunctor"
, "strings"
, "quickcheck"
, "lcg"
, "transformers"
, "foldable-traversable"
, "exceptions"
, "node-fs"
, "node-buffer"
, "node-readline"
, "datetime"
, "now"
]
, repo =
"https://github.com/hdgarrood/purescript-benchotron.git"
, version =
"v7.0.0"
}
}
-------------------------------
-}


let upstream =
https://github.com/purescript/package-sets/releases/download/psc-0.13.8-20200724/packages.dhall sha256:bb941d30820a49345a0e88937094d2b9983d939c9fd3a46969b85ce44953d7d9

let overrides = {=}

let additions = {=}

in upstream // overrides // additions
12 changes: 0 additions & 12 deletions psc-package.json

This file was deleted.

19 changes: 19 additions & 0 deletions spago.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{-
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name = "purescript-xml"
, dependencies =
[ "console"
, "effect"
, "generics-rep"
, "integers"
, "lists"
, "parsing"
, "prelude"
, "psci-support"
, "unordered-collections"
]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs" ]
}
12 changes: 12 additions & 0 deletions src/Data/XML/Types.purs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
module Data.XML.Types where

import Prelude (class Show, class Eq)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.List (List)
import Data.Maybe (Maybe)
import Data.Tuple (Tuple)
Expand All @@ -13,6 +17,14 @@ data XML
= XMLNode XMLTagName (List XMLAttribute) (List XML)
| XMLContent String

derive instance genericXML :: Generic XML _

instance showXML :: Show XML where
show xml = genericShow xml

instance eqXML :: Eq XML where
eq xml = genericEq xml

data XPath = LocationPath (List LocationStep)

data LocationStep = LocationStep Axis NodeTest (Maybe XPath)
Expand Down
7 changes: 7 additions & 0 deletions test.dhall
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- https://github.com/purescript/spago#devdependencies-testdependencies-or-in-general-a-situation-with-many-configurations
let conf = ./spago.dhall

in conf // {
sources = conf.sources # [ "test/**/*.purs" ],
dependencies = conf.dependencies # [ "spec" ]
}
41 changes: 28 additions & 13 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,21 +1,36 @@
module Main where
module Test.Main where

import Prelude
import Effect (Effect)
import Effect.Class.Console (log)

import Data.Either (Either(..))
import Data.Identity (Identity(..))
import Data.Newtype (un)
import Data.XML (parseXML)
import Text.Parsing.Parser (parseErrorMessage, parseErrorPosition, runParserT)
import Data.XML (XML(..), parseXML)
import Effect (Effect)
import Effect.Aff (launchAff_)
import Test.Spec (describe, it)
import Test.Spec.Assertions (shouldEqual, fail)
import Test.Spec.Reporter (consoleReporter)
import Test.Spec.Runner (runSpec)
import Text.Parsing.Parser (parseErrorPosition)
import Text.Parsing.Parser.Pos (Position(..))

main :: Effect Unit
main =
case parseXML testXML of
Left err -> do
log (parseErrorMessage err)
log ("position: " <> show (parseErrorPosition err))
Right xml -> pure unit
main = launchAff_ $ runSpec [consoleReporter] do
describe "parseXML" do
it "should parse a full xml test file successfully" do
case parseXML testXML of
Left err -> fail "parsing failed"
Right xml -> pure unit

it "should parse a simple xml file" do
let example = parseXML """<?xml version="1.0" encoding="UTF-8"?><my-test>my-text</my-test>"""
let expected = XMLNode "my-test" mempty $ pure $ XMLContent "my-text"
example `shouldEqual` Right expected

it "should report an error for a malformed xml file" do
let example = parseXML """<?xml version="1.0" encoding="UTF-8"?><"""
case example of
Left err -> parseErrorPosition err `shouldEqual` (Position {line: 1, column: 40})
Right xml -> fail "expected xml to be invalid, but parseXML did not fail"

testXML :: String
testXML = """
Expand Down
1 change: 0 additions & 1 deletion test/index.js

This file was deleted.