From 4139d3a81f90380553aaa246fbe4baa927306fcf Mon Sep 17 00:00:00 2001 From: Andrew Condon Date: Sun, 25 Jul 2021 09:13:46 +0200 Subject: [PATCH 1/3] update bower for halogen 6 --- bower.json | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/bower.json b/bower.json index 85d20eb..f1b2d6d 100644 --- a/bower.json +++ b/bower.json @@ -21,12 +21,53 @@ "yarn.lock" ], "dependencies": { - "purescript-string-parsers": "^5.0.0", - "purescript-halogen": "^5.0.0-rc.4" + "purescript-string-parsers": "^6.0.0", + "purescript-halogen": "^6.1.0" }, "devDependencies": { - "purescript-psci-support": "^4.0.0", + "purescript-psci-support": "^5.0.0", "purescript-jest": "^0.3.0", - "purescript-debug": "^4.0.0" + "purescript-debug": "^5.0.0" + }, + "resolutions": { + "purescript-prelude": "^v5.0.0", + "purescript-aff": "^v6.0.0", + "purescript-foreign": "^v6.0.0", + "purescript-transformers": "^v5.0.0", + "purescript-exceptions": "^v5.0.0", + "purescript-parallel": "^v5.0.0", + "purescript-datetime": "^5.0.0", + "purescript-functions": "^v5.0.0", + "purescript-unsafe-coerce": "^v5.0.0", + "purescript-either": "^v5.0.0", + "purescript-lists": "^v6.0.0", + "purescript-bifunctors": "^v5.0.0", + "purescript-foldable-traversable": "^v5.0.0", + "purescript-maybe": "^v5.0.0", + "purescript-tailrec": "^v5.0.0", + "purescript-strings": "^v5.0.0", + "purescript-arrays": "^v6.0.0", + "purescript-control": "^v5.0.0", + "purescript-integers": "^5.0.0", + "purescript-identity": "^5.0.0", + "purescript-lazy": "^v5.0.0", + "purescript-tuples": "^v6.0.0", + "purescript-newtype": "^v4.0.0", + "purescript-unfoldable": "^v5.0.0", + "purescript-functors": "^v4.0.0", + "purescript-refs": "^v5.0.0", + "purescript-gen": "^3.0.0", + "purescript-enums": "^5.0.0", + "purescript-ordered-collections": "^2.0.0", + "purescript-math": "^3.0.0", + "purescript-partial": "^3.0.0", + "purescript-distributive": "^5.0.0", + "purescript-invariant": "^5.0.0", + "purescript-nonempty": "^6.0.0", + "purescript-orders": "^5.0.0", + "purescript-st": "^5.0.0", + "purescript-const": "^5.0.0", + "purescript-contravariant": "^5.0.0", + "purescript-type-equality": "^4.0.0" } } From 79d5d588e733c340a4e30f6f645a83b48204bb39 Mon Sep 17 00:00:00 2001 From: Andrew Condon Date: Sun, 25 Jul 2021 09:58:52 +0200 Subject: [PATCH 2/3] build:ci and example working, test commented out test main needs to be rewritten with package-set compatible test library --- bower.json | 42 ---------- example/bower.json | 6 +- example/src/App.purs | 76 +++++++++--------- example/src/Main.purs | 4 +- test/Main.purs | 174 +++++++++++++++++++++--------------------- 5 files changed, 133 insertions(+), 169 deletions(-) diff --git a/bower.json b/bower.json index f1b2d6d..ff5c55e 100644 --- a/bower.json +++ b/bower.json @@ -26,48 +26,6 @@ }, "devDependencies": { "purescript-psci-support": "^5.0.0", - "purescript-jest": "^0.3.0", "purescript-debug": "^5.0.0" - }, - "resolutions": { - "purescript-prelude": "^v5.0.0", - "purescript-aff": "^v6.0.0", - "purescript-foreign": "^v6.0.0", - "purescript-transformers": "^v5.0.0", - "purescript-exceptions": "^v5.0.0", - "purescript-parallel": "^v5.0.0", - "purescript-datetime": "^5.0.0", - "purescript-functions": "^v5.0.0", - "purescript-unsafe-coerce": "^v5.0.0", - "purescript-either": "^v5.0.0", - "purescript-lists": "^v6.0.0", - "purescript-bifunctors": "^v5.0.0", - "purescript-foldable-traversable": "^v5.0.0", - "purescript-maybe": "^v5.0.0", - "purescript-tailrec": "^v5.0.0", - "purescript-strings": "^v5.0.0", - "purescript-arrays": "^v6.0.0", - "purescript-control": "^v5.0.0", - "purescript-integers": "^5.0.0", - "purescript-identity": "^5.0.0", - "purescript-lazy": "^v5.0.0", - "purescript-tuples": "^v6.0.0", - "purescript-newtype": "^v4.0.0", - "purescript-unfoldable": "^v5.0.0", - "purescript-functors": "^v4.0.0", - "purescript-refs": "^v5.0.0", - "purescript-gen": "^3.0.0", - "purescript-enums": "^5.0.0", - "purescript-ordered-collections": "^2.0.0", - "purescript-math": "^3.0.0", - "purescript-partial": "^3.0.0", - "purescript-distributive": "^5.0.0", - "purescript-invariant": "^5.0.0", - "purescript-nonempty": "^6.0.0", - "purescript-orders": "^5.0.0", - "purescript-st": "^5.0.0", - "purescript-const": "^5.0.0", - "purescript-contravariant": "^5.0.0", - "purescript-type-equality": "^4.0.0" } } diff --git a/example/bower.json b/example/bower.json index 1116c61..d678f8c 100644 --- a/example/bower.json +++ b/example/bower.json @@ -8,10 +8,10 @@ "output" ], "dependencies": { - "purescript-string-parsers": "^5.0.0", - "purescript-halogen": "^5.0.0-rc.4" + "purescript-string-parsers": "^6.0.0", + "purescript-halogen": "^6.1.0" }, "devDependencies": { - "purescript-psci-support": "^4.0.0" + "purescript-psci-support": "^5.0.0" } } diff --git a/example/src/App.purs b/example/src/App.purs index ee98a26..54a8656 100644 --- a/example/src/App.purs +++ b/example/src/App.purs @@ -2,14 +2,16 @@ module App where import Prelude +import Control.Monad.State (class MonadState) import Data.Const (Const) -import Data.Maybe (Maybe(..)) +import Effect.Aff.Class (class MonadAff) import Halogen as H import Halogen.HTML as HH import Halogen.HTML.Events as HE import Halogen.HTML.Properties as HP import Html.Renderer.Halogen as PH +type Query :: forall k. k -> Type type Query = Const Void data Action = OnValueChange String @@ -51,47 +53,49 @@ class_ = HP.class_ <<< HH.ClassName style :: forall r i. String -> HP.IProp ("style" :: String | r) i style = HP.attr (HH.AttrName "style") -render :: forall m. State -> H.ComponentHTML Action () m -render state = - HH.div [ class_ "grid" ] - [ HH.h2 [ class_ "header" ] - [ HH.text "purescript-html-parser-halogen example" ] - , HH.div [ class_ "col col-edit" ] - [ HH.h4_ [ HH.text "EDIT" ] - , HH.textarea - [ class_ "edit" - , HP.value state.value - , HE.onValueInput $ Just <<< OnValueChange - ] - ] - , HH.div [ class_ "col col-preview" ] - [ HH.h4_ [ HH.text "PREVIEW" ] - , HH.div [ class_ "preview" ] - [ PH.render_ state.value ] - ] - , HH.div [ class_ "footer" ] - [ HH.a - [ HP.href demoSourceUrl] [HH.text "source code"] - , HH.text " Powered by " - , HH.img - [ HP.src "https://upload.wikimedia.org/wikipedia/commons/6/64/PureScript_Logo.png" - , style "width: 1rem; height: 1rem" - ] - ] - ] - where - repoUrl = "https://github.com/rnons/purescript-html-parser-halogen" - demoSourceUrl = repoUrl <> "/tree/master/example" - -app :: forall m. H.Component HH.HTML Query Unit Void m -app = H.mkComponent +component :: forall query input output m. MonadAff m => H.Component query input output m +component = H.mkComponent { initialState: const initialState , render , eval: H.mkEval $ H.defaultEval { handleAction = handleAction } } + where + + render state = + HH.div [ class_ "grid" ] + [ HH.h2 [ class_ "header" ] + [ HH.text "purescript-html-parser-halogen example" ] + , HH.div [ class_ "col col-edit" ] + [ HH.h4_ [ HH.text "EDIT" ] + , HH.textarea + [ class_ "edit" + , HP.value state.value + , HE.onValueInput \s -> OnValueChange s + ] + ] + , HH.div [ class_ "col col-preview" ] + [ HH.h4_ [ HH.text "PREVIEW" ] + , HH.div [ class_ "preview" ] + [ PH.render_ state.value ] + ] + , HH.div [ class_ "footer" ] + [ HH.a + [ HP.href demoSourceUrl] [HH.text "source code"] + , HH.text " Powered by " + , HH.img + [ HP.src "https://upload.wikimedia.org/wikipedia/commons/6/64/PureScript_Logo.png" + , style "width: 1rem; height: 1rem" + ] + ] + ] + where + repoUrl = "https://github.com/rnons/purescript-html-parser-halogen" + demoSourceUrl = repoUrl <> "/tree/master/example" -handleAction :: forall m. Action -> H.HalogenM State Action () Void m Unit +handleAction :: forall m. + MonadState State m => + Action -> m Unit handleAction = case _ of OnValueChange value -> do H.modify_ $ _ { value = value } diff --git a/example/src/Main.purs b/example/src/Main.purs index 28f160d..d9bd97a 100644 --- a/example/src/Main.purs +++ b/example/src/Main.purs @@ -4,9 +4,9 @@ import Prelude import Effect (Effect) import Halogen.Aff as HA import Halogen.VDom.Driver (runUI) -import App (app) +import App (component) main :: Effect Unit main = HA.runHalogenAff do body <- HA.awaitBody - runUI app unit body + runUI component unit body diff --git a/test/Main.purs b/test/Main.purs index d76a310..07ca0c3 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -8,96 +8,98 @@ import Data.List (List) import Data.List as List import Effect (Effect) import Html.Parser (HtmlAttribute(..), HtmlNode(..), parse) -import Jest (expectToBeTrue, expectToEqual, test) +-- import Jest (expectToBeTrue, expectToEqual, test) -type Spec = - { name :: String - , raw :: String - , expected :: List HtmlNode - } +-- type Spec = +-- { name :: String +-- , raw :: String +-- , expected :: List HtmlNode +-- } -simpleATagLineBreak :: String -simpleATagLineBreak = """ -purescript -""" +-- simpleATagLineBreak :: String +-- simpleATagLineBreak = """ +-- purescript +-- """ -simpleATagExpected :: HtmlNode -simpleATagExpected = HtmlElement - { name: "a" - , attributes: List.fromFoldable - [ HtmlAttribute "href" "https://purescript.org" - , HtmlAttribute "target" "blank_" - ] - , children: List.singleton $ HtmlText "purescript" - } +-- simpleATagExpected :: HtmlNode +-- simpleATagExpected = HtmlElement +-- { name: "a" +-- , attributes: List.fromFoldable +-- [ HtmlAttribute "href" "https://purescript.org" +-- , HtmlAttribute "target" "blank_" +-- ] +-- , children: List.singleton $ HtmlText "purescript" +-- } -specs :: Array Spec -specs = - [ { name: "plain text" - , raw: "abc" - , expected: List.singleton $ HtmlText "abc" - } - , { name: "simple tag" - , raw: "purescript" - , expected: List.singleton $ simpleATagExpected - } - , { name: "simple tag with line break" - , raw: simpleATagLineBreak - , expected: List.fromFoldable $ - [ HtmlText "\n" - , simpleATagExpected - , HtmlText "\n" - ] - } - , { name: "html entities" - , raw: "
a&b
" - , expected: List.fromFoldable $ - [ HtmlElement - { name: "div" - , attributes: List.Nil - , children: List.singleton $ HtmlText "a&b" - } - ] - } - , { name: "tag inside text" - , raw: "a b c" - , expected: List.fromFoldable - [ HtmlText "a " - , HtmlElement - { name: "b" - , attributes: List.Nil - , children: List.singleton $ HtmlText "b" - } - , HtmlText " c" - ] - } - , { name: "non breaking space" - -- The first character is a non breaking space (code point 160). - , raw: "  1234" - , expected: List.singleton $ - HtmlText "  1234" - } - ] +-- specs :: Array Spec +-- specs = +-- [ { name: "plain text" +-- , raw: "abc" +-- , expected: List.singleton $ HtmlText "abc" +-- } +-- , { name: "simple
tag" +-- , raw: "purescript" +-- , expected: List.singleton $ simpleATagExpected +-- } +-- , { name: "simple tag with line break" +-- , raw: simpleATagLineBreak +-- , expected: List.fromFoldable $ +-- [ HtmlText "\n" +-- , simpleATagExpected +-- , HtmlText "\n" +-- ] +-- } +-- , { name: "html entities" +-- , raw: "
a&b
" +-- , expected: List.fromFoldable $ +-- [ HtmlElement +-- { name: "div" +-- , attributes: List.Nil +-- , children: List.singleton $ HtmlText "a&b" +-- } +-- ] +-- } +-- , { name: "tag inside text" +-- , raw: "a b c" +-- , expected: List.fromFoldable +-- [ HtmlText "a " +-- , HtmlElement +-- { name: "b" +-- , attributes: List.Nil +-- , children: List.singleton $ HtmlText "b" +-- } +-- , HtmlText " c" +-- ] +-- } +-- , { name: "non breaking space" +-- -- The first character is a non breaking space (code point 160). +-- , raw: "  1234" +-- , expected: List.singleton $ +-- HtmlText "  1234" +-- } +-- ] -rightHtml :: Array String -rightHtml = - [ "" - , "" - , "" - , """""" - , "" - , """""" - , "" - ] +-- rightHtml :: Array String +-- rightHtml = +-- [ "" +-- , "" +-- , "" +-- , """""" +-- , "" +-- , """""" +-- , "" +-- ] -main :: Effect Unit -main = do - sequence_ $ specs <#> \spec -> do - test spec.name $ expectToEqual (parse spec.raw) (Right spec.expected) +-- main :: Effect Unit +-- main = do +-- sequence_ $ specs <#> \spec -> do +-- test spec.name $ expectToEqual (parse spec.raw) (Right spec.expected) - sequence_ $ rightHtml <#> \html -> do - test ("should parse right: " <> html) $ - expectToBeTrue (isRight $ parse html) +-- sequence_ $ rightHtml <#> \html -> do +-- test ("should parse right: " <> html) $ +-- expectToBeTrue (isRight $ parse html) + +main = pure unit \ No newline at end of file From 40297350a88e7ff148d71140aee21289540067d6 Mon Sep 17 00:00:00 2001 From: Andrew Condon Date: Sun, 25 Jul 2021 11:43:13 +0200 Subject: [PATCH 3/3] bump bounds on jest so that test can work --- example/bower.json | 1 + test/Main.purs | 174 ++++++++++++++++++++++----------------------- 2 files changed, 87 insertions(+), 88 deletions(-) diff --git a/example/bower.json b/example/bower.json index d678f8c..ced36d6 100644 --- a/example/bower.json +++ b/example/bower.json @@ -9,6 +9,7 @@ ], "dependencies": { "purescript-string-parsers": "^6.0.0", + "purescript-jest": "^0.5.0", "purescript-halogen": "^6.1.0" }, "devDependencies": { diff --git a/test/Main.purs b/test/Main.purs index 07ca0c3..d76a310 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -8,98 +8,96 @@ import Data.List (List) import Data.List as List import Effect (Effect) import Html.Parser (HtmlAttribute(..), HtmlNode(..), parse) --- import Jest (expectToBeTrue, expectToEqual, test) +import Jest (expectToBeTrue, expectToEqual, test) --- type Spec = --- { name :: String --- , raw :: String --- , expected :: List HtmlNode --- } +type Spec = + { name :: String + , raw :: String + , expected :: List HtmlNode + } --- simpleATagLineBreak :: String --- simpleATagLineBreak = """ ---
purescript --- """ +simpleATagLineBreak :: String +simpleATagLineBreak = """ +purescript +""" --- simpleATagExpected :: HtmlNode --- simpleATagExpected = HtmlElement --- { name: "a" --- , attributes: List.fromFoldable --- [ HtmlAttribute "href" "https://purescript.org" --- , HtmlAttribute "target" "blank_" --- ] --- , children: List.singleton $ HtmlText "purescript" --- } +simpleATagExpected :: HtmlNode +simpleATagExpected = HtmlElement + { name: "a" + , attributes: List.fromFoldable + [ HtmlAttribute "href" "https://purescript.org" + , HtmlAttribute "target" "blank_" + ] + , children: List.singleton $ HtmlText "purescript" + } --- specs :: Array Spec --- specs = --- [ { name: "plain text" --- , raw: "abc" --- , expected: List.singleton $ HtmlText "abc" --- } --- , { name: "simple tag" --- , raw: "purescript" --- , expected: List.singleton $ simpleATagExpected --- } --- , { name: "simple tag with line break" --- , raw: simpleATagLineBreak --- , expected: List.fromFoldable $ --- [ HtmlText "\n" --- , simpleATagExpected --- , HtmlText "\n" --- ] --- } --- , { name: "html entities" --- , raw: "
a&b
" --- , expected: List.fromFoldable $ --- [ HtmlElement --- { name: "div" --- , attributes: List.Nil --- , children: List.singleton $ HtmlText "a&b" --- } --- ] --- } --- , { name: "tag inside text" --- , raw: "a b c" --- , expected: List.fromFoldable --- [ HtmlText "a " --- , HtmlElement --- { name: "b" --- , attributes: List.Nil --- , children: List.singleton $ HtmlText "b" --- } --- , HtmlText " c" --- ] --- } --- , { name: "non breaking space" --- -- The first character is a non breaking space (code point 160). --- , raw: "  1234" --- , expected: List.singleton $ --- HtmlText "  1234" --- } --- ] +specs :: Array Spec +specs = + [ { name: "plain text" + , raw: "abc" + , expected: List.singleton $ HtmlText "abc" + } + , { name: "simple
tag" + , raw: "purescript" + , expected: List.singleton $ simpleATagExpected + } + , { name: "simple tag with line break" + , raw: simpleATagLineBreak + , expected: List.fromFoldable $ + [ HtmlText "\n" + , simpleATagExpected + , HtmlText "\n" + ] + } + , { name: "html entities" + , raw: "
a&b
" + , expected: List.fromFoldable $ + [ HtmlElement + { name: "div" + , attributes: List.Nil + , children: List.singleton $ HtmlText "a&b" + } + ] + } + , { name: "tag inside text" + , raw: "a b c" + , expected: List.fromFoldable + [ HtmlText "a " + , HtmlElement + { name: "b" + , attributes: List.Nil + , children: List.singleton $ HtmlText "b" + } + , HtmlText " c" + ] + } + , { name: "non breaking space" + -- The first character is a non breaking space (code point 160). + , raw: "  1234" + , expected: List.singleton $ + HtmlText "  1234" + } + ] --- rightHtml :: Array String --- rightHtml = --- [ "" --- , "" --- , "" --- , """""" --- , "" --- , """""" --- , "" --- ] +rightHtml :: Array String +rightHtml = + [ "" + , "" + , "" + , """""" + , "" + , """""" + , "" + ] --- main :: Effect Unit --- main = do --- sequence_ $ specs <#> \spec -> do --- test spec.name $ expectToEqual (parse spec.raw) (Right spec.expected) +main :: Effect Unit +main = do + sequence_ $ specs <#> \spec -> do + test spec.name $ expectToEqual (parse spec.raw) (Right spec.expected) --- sequence_ $ rightHtml <#> \html -> do --- test ("should parse right: " <> html) $ --- expectToBeTrue (isRight $ parse html) - -main = pure unit \ No newline at end of file + sequence_ $ rightHtml <#> \html -> do + test ("should parse right: " <> html) $ + expectToBeTrue (isRight $ parse html)