Quellcode durchsuchen

Add a simple test for artDecoCard parsing

jherve vor 1 Jahr
Ursprung
Commit
6decd89661
5 geänderte Dateien mit 96 neuen und 11 gelöschten Zeilen
  1. 3 0
      spago.dhall
  2. 6 8
      src/LinkedIn.purs
  3. 7 0
      src/LinkedIn/ArtDecoCard.purs
  4. 77 0
      test/ArtDecoCard.purs
  5. 3 3
      test/Main.purs

+ 3 - 0
spago.dhall

@@ -5,15 +5,18 @@ You can edit this file as you like.
 { name = "web-extension"
 , dependencies =
   [ "arrays"
+  , "assert"
   , "console"
   , "control"
   , "effect"
+  , "either"
   , "foldable-traversable"
   , "free"
   , "lists"
   , "maybe"
   , "node-buffer"
   , "node-fs"
+  , "nonempty"
   , "partial"
   , "prelude"
   , "strings"

+ 6 - 8
src/LinkedIn.purs

@@ -5,11 +5,13 @@ import Yoga.Tree
 
 import Control.Comonad.Cofree (head, tail)
 import Data.Array as A
+import Data.Generic.Rep (class Generic)
 import Data.List (List(..), (:))
 import Data.List as L
 import Data.List.NonEmpty as NEL
 import Data.List.Types (NonEmptyList)
 import Data.Maybe (Maybe(..), fromJust)
+import Data.Show.Generic (genericShow)
 import Data.String (Pattern(..), joinWith)
 import Data.String as S
 import Data.String.CodeUnits (fromCharArray, toCharArray)
@@ -77,15 +79,11 @@ data DetachedNode =
   | DetachedComment String
   | DetachedText String
 
+derive instance Generic DetachedNode _
+derive instance Eq DetachedNode
 instance Show DetachedNode where
-  show (DetachedElement n) = "DetachedElement(" <> n.tag <> id' <> classes' <> ")"
-    where
-      id' = case n.id of
-        Nothing -> ""
-        Just i -> "#" <> i
-      classes' = joinWith " " $ A.fromFoldable (map (\c -> "." <> c) n.classes)
-  show (DetachedComment c) = "DetachedComment(" <> c <> ")"
-  show (DetachedText t) = "DetachedText(" <> t <> ")"
+  show = genericShow
+
 
 asTree :: LinkedInUIElement -> Effect (Tree DetachedNode)
 asTree (LinkedInUIElement _ n) = asTree' n

+ 7 - 0
src/LinkedIn/ArtDecoCard.purs

@@ -22,6 +22,7 @@ data ParseError =
   | NodeListNotFoundError String
 
 derive instance Generic ParseError _
+derive instance Eq ParseError
 instance Show ParseError where
   show = genericShow
 
@@ -29,6 +30,7 @@ type Parser a = Node → Effect (Either ParseError a)
 
 data ArtDecoPvsEntitySubComponent = ArtDecoPvsEntitySubComponent DetachedNode
 derive instance Generic ArtDecoPvsEntitySubComponent _
+derive instance Eq ArtDecoPvsEntitySubComponent
 instance Show ArtDecoPvsEntitySubComponent where
   show = genericShow
 
@@ -41,6 +43,7 @@ parseArtDecoPvsEntitySubComponent n = do
 
 data ArtDecoCenterContent = ArtDecoCenterContent (NonEmptyList ArtDecoPvsEntitySubComponent)
 derive instance Generic ArtDecoCenterContent _
+derive instance Eq ArtDecoCenterContent
 instance Show ArtDecoCenterContent where
   show = genericShow
 
@@ -58,6 +61,7 @@ data ArtDecoCenterHeader = ArtDecoCenterHeader {
 }
 
 derive instance Generic ArtDecoCenterHeader _
+derive instance Eq ArtDecoCenterHeader
 instance Show ArtDecoCenterHeader where
   show = genericShow
 
@@ -77,6 +81,7 @@ data ArtDecoCenter = ArtDecoCenter {
 }
 
 derive instance Generic ArtDecoCenter _
+derive instance Eq ArtDecoCenter
 instance Show ArtDecoCenter where
   show = genericShow
 
@@ -96,6 +101,7 @@ data ArtDecoPvsEntity = ArtDecoPvsEntity {
 }
 
 derive instance Generic ArtDecoPvsEntity _
+derive instance Eq ArtDecoPvsEntity
 instance Show ArtDecoPvsEntity where
   show = genericShow
 
@@ -112,6 +118,7 @@ data ArtDecoCardElement = ArtDecoCardElement {
 }
 
 derive instance Generic ArtDecoCardElement _
+derive instance Eq ArtDecoCardElement
 instance Show ArtDecoCardElement where
   show = genericShow
 

Datei-Diff unterdrückt, da er zu groß ist
+ 77 - 0
test/ArtDecoCard.purs


+ 3 - 3
test/Main.purs

@@ -3,9 +3,9 @@ module Test.Main where
 import Prelude
 
 import Effect (Effect)
-import Effect.Class.Console (log)
+
+import Test.ArtDecoCard (testArtDecoCard)
 
 main :: Effect Unit
 main = do
-  log "🍝"
-  log "You should add some tests."
+  testArtDecoCard