diff --git a/.gitignore b/.gitignore index 96a5c10..4b556de 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ **DS_Store output/ .psc-package/ +.spago/ \ No newline at end of file diff --git a/README.md b/README.md index c55310a..2bfe6d1 100644 --- a/README.md +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/packages.dhall b/packages.dhall new file mode 100644 index 0000000..740e7c5 --- /dev/null +++ b/packages.dhall @@ -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 diff --git a/psc-package.json b/psc-package.json deleted file mode 100644 index 2846e3a..0000000 --- a/psc-package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "purescript-xml", - "set": "psc-0.12.0-20180819", - "source": "https://github.com/purescript/package-sets.git", - "depends": [ - "prelude", - "unordered-collections", - "lists", - "parsing", - "integers" - ] -} diff --git a/spago.dhall b/spago.dhall new file mode 100644 index 0000000..dfead68 --- /dev/null +++ b/spago.dhall @@ -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" ] +} diff --git a/src/Data/XML/Types.purs b/src/Data/XML/Types.purs index 3e844dc..74cfb2c 100644 --- a/src/Data/XML/Types.purs +++ b/src/Data/XML/Types.purs @@ -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) @@ -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) diff --git a/test.dhall b/test.dhall new file mode 100644 index 0000000..783c511 --- /dev/null +++ b/test.dhall @@ -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" ] +} \ No newline at end of file diff --git a/test/Main.purs b/test/Main.purs index 3431bf5..9767303 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -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 """my-text""" + 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 """<""" + 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 = """ diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 24e15c2..0000000 --- a/test/index.js +++ /dev/null @@ -1 +0,0 @@ -require('./output/Main').main();