Skip to content

Commit

Permalink
Upgrade dependencies for PureScript 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-si committed Sep 8, 2018
1 parent 52e69a7 commit de0d8c1
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 55 deletions.
17 changes: 9 additions & 8 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
],
"dependencies": {
"js-yaml": "^3.4.6",
"purescript-functions": "^3.0.0",
"purescript-foreign": "^4.0.0",
"purescript-foreign-generic": "^4.1.0",
"purescript-unsafe-coerce": "^3.0.0",
"purescript-argonaut-core": "^3.1.0"
"purescript-argonaut-core": "^4.0.1",
"purescript-foreign": "^5.0.0",
"purescript-foreign-generic": "^7.0.0",
"purescript-functions": "^4.0.0",
"purescript-ordered-collections": "^1.1.0",
"purescript-unsafe-coerce": "^4.0.0"
},
"devDependencies": {
"purescript-console": "^3.0.0",
"purescript-spec": "^1.0.0",
"purescript-argonaut-codecs": "^3.0.1"
"purescript-argonaut-codecs": "^4.0.2",
"purescript-console": "^4.1.0",
"purescript-spec": "^3.0.0"
}
}
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
"license": "SEE LICENSE FILE",
"repository": "",
"private": true,
"contributors": [ ],
"contributors": [],
"main": "main.js",
"scripts": {
"postinstall": "bower install",
"build": "pulp build"
},
"devDependencies": {
},
"devDependencies": {},
"dependencies": {
"js-yaml": "^3.4.6"
"js-yaml": "^3.12.0"
}
}
10 changes: 5 additions & 5 deletions src/Data/YAML/Foreign/Decode.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module Data.YAML.Foreign.Decode (
parseYAMLToJson
) where

import Data.Foreign (F, Foreign, ForeignError(..), fail)
import Data.Foreign.Generic (genericDecode)
import Data.Foreign.Generic.Class (class GenericDecode)
import Data.Foreign.Generic.Types (Options)
import Foreign (F, Foreign, ForeignError(..), fail)
import Foreign.Generic (genericDecode)
import Foreign.Generic.Class (class GenericDecode)
import Foreign.Generic.Types (Options)
import Data.Function.Uncurried (Fn3, runFn3)
import Data.Generic.Rep (class Generic)
import Prelude ((>=>), (<<<), pure, (>>=))
Expand All @@ -17,7 +17,7 @@ foreign import parseYAMLImpl :: forall r. Fn3 (String -> r) (Foreign -> r) Strin

-- | Attempt to parse a YAML string, returning the result as foreign data.
parseYAML :: String -> F Foreign
parseYAML yaml = runFn3 parseYAMLImpl (fail <<< JSONError) pure yaml
parseYAML yaml = runFn3 parseYAMLImpl (fail <<< ForeignError) pure yaml

-- | Attempt to parse a YAML string, returning the result as Json
parseYAMLToJson :: String -> F Json
Expand Down
7 changes: 1 addition & 6 deletions src/Data/YAML/Foreign/Encode.purs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ module Data.YAML.Foreign.Encode (

import Data.Map as M
import Data.Map (Map)
import Data.StrMap as StrMap
import Data.StrMap (StrMap)
import Data.Array (toUnfoldable)
import Data.Function.Uncurried (Fn4, runFn4)
import Data.List (List)
Expand Down Expand Up @@ -54,11 +52,8 @@ instance eqYValue :: Eq YValue where
class ToYAML a where
toYAML :: a -> YValue

instance strMapToYAML :: (ToYAML a) => ToYAML (StrMap a) where
toYAML strMap = YObject $ StrMap.fold (\acc key value -> M.insert key (toYAML value) acc) M.empty strMap

instance mapToYAML :: (ToYAML a) => ToYAML (Map String a) where
toYAML m = YObject $ M.mapWithKey (\key value -> toYAML value) m
toYAML m = YObject $ map (\value -> toYAML value) m

instance booleanToYAML :: ToYAML Boolean where
toYAML = YBoolean
Expand Down
22 changes: 12 additions & 10 deletions test/Instances.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import Data.Argonaut.Core (toObject, toString)
import Data.Argonaut.Decode (getField)
import Data.Argonaut.Decode.Class (class DecodeJson)
import Data.Either (Either(..))
import Data.Generic (class Generic, gShow, gEq)
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Eq (genericEq)
import Data.Generic.Rep.Show (genericShow)
import Data.Maybe (maybe)
import Prelude (class Eq, class Show, bind, pure, ($))

Expand All @@ -23,17 +25,17 @@ data GeoObject = GeoObject
, coverage :: Number
}

derive instance genericGeoObject :: Generic GeoObject
instance showGeoObject :: Show GeoObject where show = gShow
instance eqGeoObject :: Eq GeoObject where eq = gEq
derive instance genericGeoObject :: Generic GeoObject _
instance showGeoObject :: Show GeoObject where show = genericShow
instance eqGeoObject :: Eq GeoObject where eq = genericEq

derive instance genericPoint :: Generic Point
instance showPoint :: Show Point where show = gShow
instance eqPoint :: Eq Point where eq = gEq
derive instance genericPoint :: Generic Point _
instance showPoint :: Show Point where show = genericShow
instance eqPoint :: Eq Point where eq = genericEq

derive instance genericMobility :: Generic Mobility
instance showMobility :: Show Mobility where show = gShow
instance eqMobility :: Eq Mobility where eq = gEq
derive instance genericMobility :: Generic Mobility _
instance showMobility :: Show Mobility where show = genericShow
instance eqMobility :: Eq Mobility where eq = genericEq

instance geoJson :: DecodeJson GeoObject where
decodeJson s = do
Expand Down
37 changes: 15 additions & 22 deletions test/Main.purs
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
module Test.Main where

import Data.Map as Map
import Data.StrMap as StrMap
import Control.Monad.Eff (Eff)
import Control.Monad.Except (runExcept)
import Data.Argonaut.Decode (class DecodeJson, decodeJson)
import Data.Either (Either(..))
import Data.Map (Map)
import Data.StrMap (StrMap)
import Data.YAML.Foreign.Decode (parseYAMLToJson)
import Data.YAML.Foreign.Encode (printYAML)
import Effect
import Prelude (Unit, discard, pure, ($), (<<<), (>>=))
import Test.Instances (GeoObject(..), Mobility(..), Point(..))
import Test.Spec (describe, it)
import Test.Spec.Assertions (shouldEqual)
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (RunnerEffects, run)
import Test.Spec.Runner (run)

yamlInput :: String
yamlInput = """
Expand Down Expand Up @@ -45,54 +43,54 @@ yamlInput = """
"""

yamlOutput :: String
yamlOutput = """- Mobility: Fix
yamlOutput = """- Coverage: 10
Mobility: Fix
Name: House
Points:
- X: 10
Y: 10
- X: 20
Y: 10
- X: 5
Y: 5
Coverage: 10
Name: House
Scale: 9.5
- Mobility: Fix
- Coverage: 10
Mobility: Fix
Name: Tree
Points:
- X: 1
Y: 1
- X: 2
Y: 2
- X: 0
Y: 0
Coverage: 10
Name: Tree
Scale: 1
"""


yamlMapOutput :: String
yamlMapOutput = """key:
- Mobility: Fix
- Coverage: 10
Mobility: Fix
Name: House
Points:
- X: 10
Y: 10
- X: 20
Y: 10
- X: 5
Y: 5
Coverage: 10
Name: House
Scale: 9.5
- Mobility: Fix
- Coverage: 10
Mobility: Fix
Name: Tree
Points:
- X: 1
Y: 1
- X: 2
Y: 2
- X: 0
Y: 0
Coverage: 10
Name: Tree
Scale: 1
"""

Expand All @@ -106,8 +104,6 @@ yamlToData s = case runExcept $ parseYAMLToJson s of
Left err -> Left "Could not parse yaml"
Right json -> decodeJson json

testStrMap :: StrMap (Array GeoObject)
testStrMap = StrMap.singleton "key" parsedData

testMap :: Map String (Array GeoObject)
testMap = Map.singleton "key" parsedData
Expand Down Expand Up @@ -137,7 +133,7 @@ readPoint = yamlToData
fullCircle :: String -> Either String String
fullCircle yamlString = (readPoint yamlString) >>= pure <<< printYAML

main :: Eff (RunnerEffects ()) Unit
main :: Effect Unit
main = run [consoleReporter] do
describe "purescript-yaml" do
describe "decode" do
Expand All @@ -149,9 +145,6 @@ main = run [consoleReporter] do
let encoded = printYAML parsedData
encoded `shouldEqual` yamlOutput

let encodedStrMap = printYAML testStrMap
encodedStrMap `shouldEqual` yamlMapOutput

let encodedMap = printYAML testMap
encodedMap `shouldEqual` yamlMapOutput

Expand Down

0 comments on commit de0d8c1

Please sign in to comment.