1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 10:15:55 +03:00

Remove literal string from tests

This commit is contained in:
joshvera 2016-05-23 13:57:04 -04:00
parent ea87d385a5
commit 72dea795d2
2 changed files with 11 additions and 13 deletions

View File

@ -20,12 +20,11 @@ import Data.OrderedMap
import qualified Data.Foldable as F
import Data.Text as Text (unpack, Text)
data DiffInfo = DiffInfo { name :: String, term :: Maybe String } deriving (Eq, Show)
data DiffInfo = DiffInfo { categoryName :: String, value :: Maybe String } deriving (Eq, Show)
class ToTerm a where
toTerm :: a -> Maybe String
instance IsTerm leaf => ToTerm (Term leaf Info) where
toTerm term = case runCofree term of
(_ :< Leaf leaf) -> Just (termName leaf)
@ -33,12 +32,11 @@ instance IsTerm leaf => ToTerm (Term leaf Info) where
(_ :< Indexed children) -> Just (termName . toCategory . head $ extract <$> children)
(_ :< Fixed children) -> Just (termName . toCategory . head $ extract <$> children)
class IsTerm a where
termName :: a -> String
instance IsTerm DiffInfo where
termName = name
termName = categoryName
instance IsTerm String where
termName = id
@ -65,12 +63,12 @@ data DiffSummary a = DiffSummary {
instance Show a => Show (DiffSummary a) where
show DiffSummary{..} = case patch of
(Insert termInfo) -> "Added the " ++ "'" ++ fromJust (term termInfo) ++ "' " ++ termName termInfo
(Insert termInfo) -> "Added the " ++ "'" ++ fromJust (value termInfo) ++ "' " ++ termName termInfo
++ if null parentAnnotations then "" else " to the " ++ intercalate "/" (termName <$> parentAnnotations) ++ " context"
(Delete termInfo) -> "Deleted the " ++ "'" ++ fromJust (term termInfo) ++ "' " ++ termName termInfo
(Delete termInfo) -> "Deleted the " ++ "'" ++ fromJust (value termInfo) ++ "' " ++ termName termInfo
++ if null parentAnnotations then "" else " in the " ++ intercalate "/" (termName <$> parentAnnotations) ++ " context"
(Replace t1 t2) -> "Replaced the " ++ "'" ++ fromJust (term t1) ++ "' " ++ termName t1
++ " with the " ++ "'" ++ fromJust (term t2) ++ "' " ++ termName t2
(Replace t1 t2) -> "Replaced the " ++ "'" ++ fromJust (value t1) ++ "' " ++ termName t1
++ " with the " ++ "'" ++ fromJust (value t2) ++ "' " ++ termName t2
++ if null parentAnnotations then "" else " in the " ++ intercalate "/" (termName <$> parentAnnotations) ++ " context"
diffSummary :: IsTerm leaf => Diff leaf Info -> [DiffSummary DiffInfo]

View File

@ -22,18 +22,18 @@ testDiff :: Diff String Info
testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree $ literalInfo :< Leaf "a")) ])
testSummary :: DiffSummary Char
testSummary = DiffSummary { patch = Insert (DiffInfo "string literal" (Just "a")), parentAnnotations = [] }
testSummary = DiffSummary { patch = Insert (DiffInfo "string" (Just "a")), parentAnnotations = [] }
replacementSummary :: DiffSummary Char
replacementSummary = DiffSummary { patch = Replace (DiffInfo "string literal" (Just "a")) (DiffInfo "symbol literal" (Just "b")), parentAnnotations = [ (DiffInfo "array literal" Nothing)] }
replacementSummary = DiffSummary { patch = Replace (DiffInfo "string" (Just "a")) (DiffInfo "symbol" (Just "b")), parentAnnotations = [ (DiffInfo "array" (Just "switch {}")) ] }
spec :: Spec
spec = parallel $ do
describe "diffSummary" $ do
it "outputs a diff summary" $ do
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "string literal" (Just "a")), parentAnnotations = [ DiffInfo "array literal" Nothing ] } ]
diffSummary testDiff `shouldBe` [ DiffSummary { patch = Insert (DiffInfo "string" (Just "a")), parentAnnotations = [ DiffInfo "array" Nothing ] } ]
describe "show" $ do
it "should print adds" $
show testSummary `shouldBe` "Added the 'a' string literal"
show testSummary `shouldBe` "Added the 'a' string"
it "prints a replacement" $ do
show replacementSummary `shouldBe` "Replaced the 'a' string literal with the 'b' symbol literal in the array literal context"
show replacementSummary `shouldBe` "Replaced the 'a' string with the 'b' symbol in the array context"