mirror of
https://github.com/github/semantic.git
synced 2024-12-29 01:42:43 +03:00
Fix up tests
This commit is contained in:
parent
0244e9a929
commit
cf21fddc08
@ -22,6 +22,7 @@ import Range
|
||||
import qualified Source
|
||||
import SplitDiff
|
||||
import Syntax
|
||||
import Category
|
||||
import Term
|
||||
import Test.Hspec
|
||||
import Test.Hspec.QuickCheck
|
||||
@ -257,7 +258,7 @@ align :: Both (Source.Source Char) -> ConstructibleFree (Patch (Term String Info
|
||||
align sources = PrettyDiff sources . fmap (fmap (getRange &&& identity)) . alignDiff sources . deconstruct
|
||||
|
||||
info :: Int -> Int -> Info
|
||||
info = ((\ r -> Info r mempty 0) .) . Range
|
||||
info = ((\ r -> Info r StringLiteral 0) .) . Range
|
||||
|
||||
prettyDiff :: Both (Source.Source Char) -> [Join These (ConstructibleFree (SplitPatch (Term String Info)) Info)] -> PrettyDiff (SplitDiff String Info)
|
||||
prettyDiff sources = PrettyDiff sources . fmap (fmap ((getRange &&& identity) . deconstruct))
|
||||
|
@ -47,10 +47,11 @@ instance (Eq a, Eq annotation, Arbitrary a, Arbitrary annotation) => Arbitrary (
|
||||
data CategorySet = A | B | C | D deriving (Eq, Show)
|
||||
|
||||
instance Categorizable CategorySet where
|
||||
categories A = Set.fromList [ Other "a" ]
|
||||
categories B = Set.fromList [ Other "b" ]
|
||||
categories C = Set.fromList [ Other "c" ]
|
||||
categories D = Set.fromList [ Other "d" ]
|
||||
category s = case s of
|
||||
A -> Other "a"
|
||||
B -> Other "b"
|
||||
C -> Other "c"
|
||||
D -> Other "d"
|
||||
|
||||
instance Arbitrary CategorySet where
|
||||
arbitrary = elements [ A, B, C, D ]
|
||||
@ -80,4 +81,4 @@ instance Arbitrary a => Arbitrary (Source a) where
|
||||
|
||||
arbitraryLeaf :: Gen (Source Char, Info, Syntax (Source Char) f)
|
||||
arbitraryLeaf = toTuple <$> arbitrary
|
||||
where toTuple string = (string, Info (Range 0 $ length string) mempty 1, Leaf string)
|
||||
where toTuple string = (string, Info (Range 0 $ length string) StringLiteral 1, Leaf string)
|
||||
|
@ -13,10 +13,10 @@ import Data.Set
|
||||
import DiffSummary
|
||||
|
||||
arrayInfo :: Info
|
||||
arrayInfo = Info (rangeAt 0) (singleton ArrayLiteral) 2
|
||||
arrayInfo = Info (rangeAt 0) ArrayLiteral 2
|
||||
|
||||
literalInfo :: Info
|
||||
literalInfo = Info (rangeAt 1) (singleton StringLiteral) 1
|
||||
literalInfo = Info (rangeAt 1) StringLiteral 1
|
||||
|
||||
testDiff :: Diff String Info
|
||||
testDiff = free $ Free (pure arrayInfo :< Indexed [ free $ Pure (Insert (cofree $ literalInfo :< Leaf "a")) ])
|
||||
|
@ -14,8 +14,8 @@ spec :: Spec
|
||||
spec = parallel $
|
||||
describe "interpret" $
|
||||
it "returns a replacement when comparing two unicode equivalent terms" $
|
||||
I.interpret comparable diffCost (cofree (Info range mempty 0 :< Leaf "t\776")) (cofree (Info range2 mempty 0 :< Leaf "\7831")) `shouldBe`
|
||||
free (Pure (Replace (cofree (Info range mempty 0 :< Leaf "t\776")) (cofree (Info range2 mempty 0 :< Leaf "\7831"))))
|
||||
I.interpret comparable diffCost (cofree (Info range StringLiteral 0 :< Leaf "t\776")) (cofree (Info range2 StringLiteral 0 :< Leaf "\7831")) `shouldBe`
|
||||
free (Pure (Replace (cofree (Info range StringLiteral 0 :< Leaf "t\776")) (cofree (Info range2 StringLiteral 0 :< Leaf "\7831"))))
|
||||
|
||||
where
|
||||
range = Range 0 2
|
||||
|
@ -2,17 +2,16 @@ module PatchOutputSpec where
|
||||
|
||||
import Prologue
|
||||
import Data.Functor.Both
|
||||
import Data.String
|
||||
import Diff
|
||||
import Info
|
||||
import Range
|
||||
import Renderer.Patch
|
||||
import Source
|
||||
import Syntax
|
||||
import Category
|
||||
import Test.Hspec
|
||||
|
||||
spec :: Spec
|
||||
spec = parallel $
|
||||
describe "hunks" $
|
||||
it "empty diffs have empty hunks" $
|
||||
hunks (free . Free $ pure (Info (Range 0 0) mempty 1) :< Leaf "") (both (SourceBlob (fromList "") "abcde" "path2.txt" (Just defaultPlainBlob)) (SourceBlob (fromList "") "xyz" "path2.txt" (Just defaultPlainBlob))) `shouldBe` [Hunk {offset = pure 0, changes = [], trailingContext = []}]
|
||||
hunks (free . Free $ pure (Info (Range 0 0) StringLiteral 1) :< Leaf "") (both (SourceBlob (fromList "") "abcde" "path2.txt" (Just defaultPlainBlob)) (SourceBlob (fromList "") "xyz" "path2.txt" (Just defaultPlainBlob))) `shouldBe` [Hunk {offset = pure 0, changes = [], trailingContext = []}]
|
||||
|
@ -1 +1 @@
|
||||
{"rows":[[{"number":1,"terms":[{"range":[0,2],"categories":["program"],"children":[{"range":[0,2],"categories":["expression_statement"],"children":[{"range":[0,2],"categories":["DictionaryLiteral"],"children":{}}]}]}],"range":[0,2],"hasChanges":false},{"number":1,"terms":[{"range":[0,2],"categories":["program"],"children":[{"range":[0,2],"categories":["expression_statement"],"children":[{"range":[0,2],"categories":["DictionaryLiteral"],"children":{}}]}]}],"range":[0,2],"hasChanges":false}],[{"number":2,"terms":[{"range":[2,12],"categories":["program"],"children":[{"range":[2,12],"categories":["expression_statement"],"children":[{"range":[2,12],"categories":["DictionaryLiteral"],"children":{"\"b\"":{"range":[4,10],"categories":["Pair"],"children":[{"range":[4,7],"categories":["StringLiteral"],"children":[{"range":[4,5],"categories":["StringLiteral"]},{"range":[5,6],"categories":["StringLiteral"]},{"range":[6,7],"categories":["StringLiteral"]}]},{"patch":"replace","range":[9,10],"categories":["number"]}]}}}]}]}],"range":[2,12],"hasChanges":true},{"number":2,"terms":[{"range":[2,12],"categories":["program"],"children":[{"range":[2,12],"categories":["expression_statement"],"children":[{"range":[2,12],"categories":["DictionaryLiteral"],"children":{"\"b\"":{"range":[4,10],"categories":["Pair"],"children":[{"range":[4,7],"categories":["StringLiteral"],"children":[{"range":[4,5],"categories":["StringLiteral"]},{"range":[5,6],"categories":["StringLiteral"]},{"range":[6,7],"categories":["StringLiteral"]}]},{"patch":"replace","range":[9,10],"categories":["number"]}]}}}]}]}],"range":[2,12],"hasChanges":true}],[{"number":3,"terms":[{"range":[12,21],"categories":["program"],"children":[{"range":[12,21],"categories":["expression_statement"],"children":[{"range":[12,21],"categories":["DictionaryLiteral"],"children":{"\"a\"":{"range":[14,20],"categories":["Pair"],"children":[{"range":[14,17],"categories":["StringLiteral"],"children":[{"range":[14,15],"categories":["StringLiteral"]},{"range":[15,16],"categories":["StringLiteral"]},{"range":[16,17],"categories":["StringLiteral"]}]},{"range":[19,20],"categories":["number"]}]}}}]}]}],"range":[12,21],"hasChanges":false},{"number":3,"terms":[{"range":[12,21],"categories":["program"],"children":[{"range":[12,21],"categories":["expression_statement"],"children":[{"range":[12,21],"categories":["DictionaryLiteral"],"children":{"\"a\"":{"range":[14,20],"categories":["Pair"],"children":[{"range":[14,17],"categories":["StringLiteral"],"children":[{"range":[14,15],"categories":["StringLiteral"]},{"range":[15,16],"categories":["StringLiteral"]},{"range":[16,17],"categories":["StringLiteral"]}]},{"range":[19,20],"categories":["number"]}]}}}]}]}],"range":[12,21],"hasChanges":false}],[{"number":4,"terms":[{"range":[21,23],"categories":["program"],"children":[{"range":[21,23],"categories":["expression_statement"],"children":[{"range":[21,22],"categories":["DictionaryLiteral"],"children":{}}]}]}],"range":[21,23],"hasChanges":false},{"number":4,"terms":[{"range":[21,23],"categories":["program"],"children":[{"range":[21,23],"categories":["expression_statement"],"children":[{"range":[21,22],"categories":["DictionaryLiteral"],"children":{}}]}]}],"range":[21,23],"hasChanges":false}],[{"number":5,"terms":[{"range":[23,23],"categories":["program"],"children":[]}],"range":[23,23],"hasChanges":false},{"number":5,"terms":[{"range":[23,23],"categories":["program"],"children":[]}],"range":[23,23],"hasChanges":false}]],"oids":["",""],"paths":["test/diffs/dictionary.A.js","test/diffs/dictionary.B.js"]}
|
||||
{"rows":[[{"number":1,"terms":[{"range":[0,2],"categories":"program","children":[{"range":[0,2],"categories":"expression_statement","children":[{"range":[0,2],"categories":"DictionaryLiteral","children":{}}]}]}],"range":[0,2],"hasChanges":false},{"number":1,"terms":[{"range":[0,2],"categories":"program","children":[{"range":[0,2],"categories":"expression_statement","children":[{"range":[0,2],"categories":"DictionaryLiteral","children":{}}]}]}],"range":[0,2],"hasChanges":false}],[{"number":2,"terms":[{"range":[2,12],"categories":"program","children":[{"range":[2,12],"categories":"expression_statement","children":[{"range":[2,12],"categories":"DictionaryLiteral","children":{"\"b\"":{"range":[4,10],"categories":"Pair","children":[{"range":[4,7],"categories":"StringLiteral","children":[{"range":[4,5],"categories":"StringLiteral"},{"range":[5,6],"categories":"StringLiteral"},{"range":[6,7],"categories":"StringLiteral"}]},{"patch":"replace","range":[9,10],"categories":"number"}]}}}]}]}],"range":[2,12],"hasChanges":true},{"number":2,"terms":[{"range":[2,12],"categories":"program","children":[{"range":[2,12],"categories":"expression_statement","children":[{"range":[2,12],"categories":"DictionaryLiteral","children":{"\"b\"":{"range":[4,10],"categories":"Pair","children":[{"range":[4,7],"categories":"StringLiteral","children":[{"range":[4,5],"categories":"StringLiteral"},{"range":[5,6],"categories":"StringLiteral"},{"range":[6,7],"categories":"StringLiteral"}]},{"patch":"replace","range":[9,10],"categories":"number"}]}}}]}]}],"range":[2,12],"hasChanges":true}],[{"number":3,"terms":[{"range":[12,21],"categories":"program","children":[{"range":[12,21],"categories":"expression_statement","children":[{"range":[12,21],"categories":"DictionaryLiteral","children":{"\"a\"":{"range":[14,20],"categories":"Pair","children":[{"range":[14,17],"categories":"StringLiteral","children":[{"range":[14,15],"categories":"StringLiteral"},{"range":[15,16],"categories":"StringLiteral"},{"range":[16,17],"categories":"StringLiteral"}]},{"range":[19,20],"categories":"number"}]}}}]}]}],"range":[12,21],"hasChanges":false},{"number":3,"terms":[{"range":[12,21],"categories":"program","children":[{"range":[12,21],"categories":"expression_statement","children":[{"range":[12,21],"categories":"DictionaryLiteral","children":{"\"a\"":{"range":[14,20],"categories":"Pair","children":[{"range":[14,17],"categories":"StringLiteral","children":[{"range":[14,15],"categories":"StringLiteral"},{"range":[15,16],"categories":"StringLiteral"},{"range":[16,17],"categories":"StringLiteral"}]},{"range":[19,20],"categories":"number"}]}}}]}]}],"range":[12,21],"hasChanges":false}],[{"number":4,"terms":[{"range":[21,23],"categories":"program","children":[{"range":[21,23],"categories":"expression_statement","children":[{"range":[21,22],"categories":"DictionaryLiteral","children":{}}]}]}],"range":[21,23],"hasChanges":false},{"number":4,"terms":[{"range":[21,23],"categories":"program","children":[{"range":[21,23],"categories":"expression_statement","children":[{"range":[21,22],"categories":"DictionaryLiteral","children":{}}]}]}],"range":[21,23],"hasChanges":false}],[{"number":5,"terms":[{"range":[23,23],"categories":"program","children":[]}],"range":[23,23],"hasChanges":false},{"number":5,"terms":[{"range":[23,23],"categories":"program","children":[]}],"range":[23,23],"hasChanges":false}]],"oids":["",""],"paths":["test/diffs/dictionary.A.js","test/diffs/dictionary.B.js"]}
|
@ -1 +1 @@
|
||||
{"rows":[[{"number":1,"terms":[{"range":[0,29],"categories":["program"],"children":[{"range":[0,28],"categories":["expression_statement"],"children":[{"range":[0,27],"categories":["FunctionCall"],"children":[{"range":[0,11],"categories":["member_access"],"children":[{"range":[0,7],"categories":["identifier"]},{"range":[8,11],"categories":["identifier"]}]},{"range":[12,26],"categories":["arguments"],"children":[{"range":[12,26],"categories":["StringLiteral"],"children":[{"range":[12,13],"categories":["StringLiteral"]},{"range":[13,18],"categories":["StringLiteral"]},{"range":[18,19],"categories":["StringLiteral"]},{"range":[20,25],"categories":["StringLiteral"]},{"range":[25,26],"categories":["StringLiteral"]}]}]}]}]}]}],"range":[0,29],"hasChanges":false},{"number":1,"terms":[{"range":[0,29],"categories":["program"],"children":[{"range":[0,28],"categories":["expression_statement"],"children":[{"range":[0,27],"categories":["FunctionCall"],"children":[{"range":[0,11],"categories":["member_access"],"children":[{"range":[0,7],"categories":["identifier"]},{"range":[8,11],"categories":["identifier"]}]},{"range":[12,26],"categories":["arguments"],"children":[{"range":[12,26],"categories":["StringLiteral"],"children":[{"range":[12,13],"categories":["StringLiteral"]},{"range":[13,18],"categories":["StringLiteral"]},{"range":[18,19],"categories":["StringLiteral"]},{"range":[20,25],"categories":["StringLiteral"]},{"range":[25,26],"categories":["StringLiteral"]}]}]}]}]}]}],"range":[0,29],"hasChanges":false}],[{"number":2,"terms":[{"range":[29,29],"categories":["program"],"children":[]}],"range":[29,29],"hasChanges":false},{"number":2,"terms":[{"range":[29,30],"categories":["program"],"children":[]}],"range":[29,30],"hasChanges":false}],[{"number":3,"terms":[{"range":[30,56],"categories":["program"],"children":[{"patch":"insert","range":[30,55],"categories":["expression_statement"],"children":[{"range":[30,54],"categories":["FunctionCall"],"children":[{"range":[30,41],"categories":["member_access"],"children":[{"range":[30,37],"categories":["identifier"]},{"range":[38,41],"categories":["identifier"]}]},{"range":[42,53],"categories":["arguments"],"children":[{"range":[42,53],"categories":["StringLiteral"],"children":[{"range":[42,43],"categories":["StringLiteral"]},{"range":[43,52],"categories":["StringLiteral"]},{"range":[52,53],"categories":["StringLiteral"]}]}]}]}]}]}],"range":[30,56],"hasChanges":true}],[{"number":4,"terms":[{"range":[56,56],"categories":["program"],"children":[]}],"range":[56,56],"hasChanges":false}]],"oids":["",""],"paths":["test/diffs/newline-at-eof.A.js","test/diffs/newline-at-eof.B.js"]}
|
||||
{"rows":[[{"number":1,"terms":[{"range":[0,29],"categories":"program","children":[{"range":[0,28],"categories":"expression_statement","children":[{"range":[0,27],"categories":"FunctionCall","children":[{"range":[0,11],"categories":"member_access","children":[{"range":[0,7],"categories":"identifier"},{"range":[8,11],"categories":"identifier"}]},{"range":[12,26],"categories":"arguments","children":[{"range":[12,26],"categories":"StringLiteral","children":[{"range":[12,13],"categories":"StringLiteral"},{"range":[13,18],"categories":"StringLiteral"},{"range":[18,19],"categories":"StringLiteral"},{"range":[20,25],"categories":"StringLiteral"},{"range":[25,26],"categories":"StringLiteral"}]}]}]}]}]}],"range":[0,29],"hasChanges":false},{"number":1,"terms":[{"range":[0,29],"categories":"program","children":[{"range":[0,28],"categories":"expression_statement","children":[{"range":[0,27],"categories":"FunctionCall","children":[{"range":[0,11],"categories":"member_access","children":[{"range":[0,7],"categories":"identifier"},{"range":[8,11],"categories":"identifier"}]},{"range":[12,26],"categories":"arguments","children":[{"range":[12,26],"categories":"StringLiteral","children":[{"range":[12,13],"categories":"StringLiteral"},{"range":[13,18],"categories":"StringLiteral"},{"range":[18,19],"categories":"StringLiteral"},{"range":[20,25],"categories":"StringLiteral"},{"range":[25,26],"categories":"StringLiteral"}]}]}]}]}]}],"range":[0,29],"hasChanges":false}],[{"number":2,"terms":[{"range":[29,29],"categories":"program","children":[]}],"range":[29,29],"hasChanges":false},{"number":2,"terms":[{"range":[29,30],"categories":"program","children":[]}],"range":[29,30],"hasChanges":false}],[{"number":3,"terms":[{"range":[30,56],"categories":"program","children":[{"patch":"insert","range":[30,55],"categories":"expression_statement","children":[{"range":[30,54],"categories":"FunctionCall","children":[{"range":[30,41],"categories":"member_access","children":[{"range":[30,37],"categories":"identifier"},{"range":[38,41],"categories":"identifier"}]},{"range":[42,53],"categories":"arguments","children":[{"range":[42,53],"categories":"StringLiteral","children":[{"range":[42,43],"categories":"StringLiteral"},{"range":[43,52],"categories":"StringLiteral"},{"range":[52,53],"categories":"StringLiteral"}]}]}]}]}]}],"range":[30,56],"hasChanges":true}],[{"number":4,"terms":[{"range":[56,56],"categories":"program","children":[]}],"range":[56,56],"hasChanges":false}]],"oids":["",""],"paths":["test/diffs/newline-at-eof.A.js","test/diffs/newline-at-eof.B.js"]}
|
@ -1 +1 @@
|
||||
{"rows":[[{"number":1,"terms":[{"range":[0,28],"categories":["program"],"children":[{"range":[0,28],"categories":["expression_statement"],"children":[{"range":[0,27],"categories":["FunctionCall"],"children":[{"range":[0,11],"categories":["member_access"],"children":[{"range":[0,7],"categories":["identifier"]},{"range":[8,11],"categories":["identifier"]}]},{"range":[12,26],"categories":["arguments"],"children":[{"range":[12,26],"categories":["StringLiteral"],"children":[{"range":[12,13],"categories":["StringLiteral"]},{"range":[13,18],"categories":["StringLiteral"]},{"range":[18,19],"categories":["StringLiteral"]},{"range":[20,25],"categories":["StringLiteral"]},{"range":[25,26],"categories":["StringLiteral"]}]}]}]}]}]}],"range":[0,28],"hasChanges":false},{"number":1,"terms":[{"range":[0,29],"categories":["program"],"children":[{"range":[0,28],"categories":["expression_statement"],"children":[{"range":[0,27],"categories":["FunctionCall"],"children":[{"range":[0,11],"categories":["member_access"],"children":[{"range":[0,7],"categories":["identifier"]},{"range":[8,11],"categories":["identifier"]}]},{"range":[12,26],"categories":["arguments"],"children":[{"range":[12,26],"categories":["StringLiteral"],"children":[{"range":[12,13],"categories":["StringLiteral"]},{"range":[13,18],"categories":["StringLiteral"]},{"range":[18,19],"categories":["StringLiteral"]},{"range":[20,25],"categories":["StringLiteral"]},{"range":[25,26],"categories":["StringLiteral"]}]}]}]}]}]}],"range":[0,29],"hasChanges":false}],[{"number":2,"terms":[{"range":[29,30],"categories":["program"],"children":[]}],"range":[29,30],"hasChanges":false}],[{"number":3,"terms":[{"range":[30,55],"categories":["program"],"children":[{"patch":"insert","range":[30,55],"categories":["expression_statement"],"children":[{"range":[30,54],"categories":["FunctionCall"],"children":[{"range":[30,41],"categories":["member_access"],"children":[{"range":[30,37],"categories":["identifier"]},{"range":[38,41],"categories":["identifier"]}]},{"range":[42,53],"categories":["arguments"],"children":[{"range":[42,53],"categories":["StringLiteral"],"children":[{"range":[42,43],"categories":["StringLiteral"]},{"range":[43,52],"categories":["StringLiteral"]},{"range":[52,53],"categories":["StringLiteral"]}]}]}]}]}]}],"range":[30,55],"hasChanges":true}]],"oids":["",""],"paths":["test/diffs/no-newline-at-eof.A.js","test/diffs/no-newline-at-eof.B.js"]}
|
||||
{"rows":[[{"number":1,"terms":[{"range":[0,28],"categories":"program","children":[{"range":[0,28],"categories":"expression_statement","children":[{"range":[0,27],"categories":"FunctionCall","children":[{"range":[0,11],"categories":"member_access","children":[{"range":[0,7],"categories":"identifier"},{"range":[8,11],"categories":"identifier"}]},{"range":[12,26],"categories":"arguments","children":[{"range":[12,26],"categories":"StringLiteral","children":[{"range":[12,13],"categories":"StringLiteral"},{"range":[13,18],"categories":"StringLiteral"},{"range":[18,19],"categories":"StringLiteral"},{"range":[20,25],"categories":"StringLiteral"},{"range":[25,26],"categories":"StringLiteral"}]}]}]}]}]}],"range":[0,28],"hasChanges":false},{"number":1,"terms":[{"range":[0,29],"categories":"program","children":[{"range":[0,28],"categories":"expression_statement","children":[{"range":[0,27],"categories":"FunctionCall","children":[{"range":[0,11],"categories":"member_access","children":[{"range":[0,7],"categories":"identifier"},{"range":[8,11],"categories":"identifier"}]},{"range":[12,26],"categories":"arguments","children":[{"range":[12,26],"categories":"StringLiteral","children":[{"range":[12,13],"categories":"StringLiteral"},{"range":[13,18],"categories":"StringLiteral"},{"range":[18,19],"categories":"StringLiteral"},{"range":[20,25],"categories":"StringLiteral"},{"range":[25,26],"categories":"StringLiteral"}]}]}]}]}]}],"range":[0,29],"hasChanges":false}],[{"number":2,"terms":[{"range":[29,30],"categories":"program","children":[]}],"range":[29,30],"hasChanges":false}],[{"number":3,"terms":[{"range":[30,55],"categories":"program","children":[{"patch":"insert","range":[30,55],"categories":"expression_statement","children":[{"range":[30,54],"categories":"FunctionCall","children":[{"range":[30,41],"categories":"member_access","children":[{"range":[30,37],"categories":"identifier"},{"range":[38,41],"categories":"identifier"}]},{"range":[42,53],"categories":"arguments","children":[{"range":[42,53],"categories":"StringLiteral","children":[{"range":[42,43],"categories":"StringLiteral"},{"range":[43,52],"categories":"StringLiteral"},{"range":[52,53],"categories":"StringLiteral"}]}]}]}]}]}],"range":[30,55],"hasChanges":true}]],"oids":["",""],"paths":["test/diffs/no-newline-at-eof.A.js","test/diffs/no-newline-at-eof.B.js"]}
|
Loading…
Reference in New Issue
Block a user