1
1
mirror of https://github.com/github/semantic.git synced 2024-12-27 17:05:33 +03:00
semantic/test/Reprinting/Spec.hs

57 lines
1.9 KiB
Haskell
Raw Normal View History

{-# LANGUAGE OverloadedLists, TypeOperators #-}
2018-07-31 03:05:44 +03:00
2018-07-31 17:43:46 +03:00
module Reprinting.Spec where
2018-07-30 23:00:09 +03:00
import SpecHelpers hiding (project, inject)
2018-07-30 23:00:09 +03:00
import Data.Functor.Foldable (embed, cata)
2018-07-30 23:00:09 +03:00
import qualified Data.Language as Language
import qualified Data.Syntax.Literal as Literal
import Data.Algebra
import Reprinting.Tokenize
2018-07-31 19:44:20 +03:00
import Reprinting.Pipeline
import Data.Sum
2018-08-16 00:01:58 +03:00
import Data.Foldable
2018-07-30 23:00:09 +03:00
import Semantic.IO
import Data.Blob
2018-08-20 19:03:03 +03:00
import Language.JSON.Translate
2018-07-30 23:00:09 +03:00
spec :: Spec
2018-07-31 21:07:16 +03:00
spec = describe "reprinting" $ do
let path = "test/fixtures/javascript/reprinting/map.json"
2018-07-31 21:07:16 +03:00
(src, tree) <- runIO $ do
src <- blobSource <$> readBlobFromPath (File path Language.JSON)
tree <- parseFile jsonParser "test/fixtures/javascript/reprinting/map.json"
pure (src, tree)
describe "tokenization" $ do
2018-07-31 19:44:20 +03:00
it "should pass over a pristine tree" $ do
2018-08-16 00:01:58 +03:00
let tagged = mark Unmodified tree
let toks = tokenizing src tagged
2018-07-31 19:44:20 +03:00
toks `shouldBe` [Chunk src]
2018-07-30 23:00:09 +03:00
2018-07-31 19:44:20 +03:00
it "should emit control tokens but only 1 chunk for a wholly-modified tree" $ do
2018-08-16 00:01:58 +03:00
let toks = tokenizing src (mark Refactored tree)
for_ @[] [List, Associative] $ \t -> do
toks `shouldSatisfy` elem (TControl (Enter t))
toks `shouldSatisfy` elem (TControl (Exit t))
2018-07-31 03:05:44 +03:00
2018-07-31 19:44:20 +03:00
describe "pipeline" $ do
it "should roundtrip exactly over a pristine tree" $ do
2018-08-16 00:01:58 +03:00
let tagged = mark Unmodified tree
2018-08-20 19:03:03 +03:00
let printed = runReprinter src defaultJSONPipeline tagged
2018-07-31 19:44:20 +03:00
printed `shouldBe` Right src
2018-07-31 21:07:16 +03:00
it "should roundtrip exactly over a wholly-modified tree" $ do
2018-08-16 00:01:58 +03:00
let tagged = mark Refactored tree
2018-08-20 19:03:03 +03:00
let printed = runReprinter src defaultJSONPipeline tagged
2018-07-31 21:07:16 +03:00
printed `shouldBe` Right src
it "should be able to parse the output of a refactor" $ do
2018-08-16 00:01:58 +03:00
let tagged = increaseNumbers (mark Refactored tree)
2018-08-20 19:03:03 +03:00
let (Right printed) = runReprinter src defaultJSONPipeline tagged
tree' <- runTask (parse jsonParser (Blob printed path Language.JSON))
2018-08-16 00:01:58 +03:00
length tree' `shouldSatisfy` (/= 0)