1
1
mirror of https://github.com/github/semantic.git synced 2024-12-19 12:51:52 +03:00
semantic/test/Parsing/Spec.hs
Max Brunsfeld 3c0dd6cc45 Add unit test for parsing with a timeout
Co-Authored-By: Rick Winfrey <rewinfrey@github.com>
2019-03-19 11:56:07 -07:00

38 lines
1.2 KiB
Haskell

module Parsing.Spec (spec) where
import Control.Effect
import Data.AST
import Data.Blob
import Data.ByteString.Char8 (pack)
import Data.Duration
import Data.Language
import Data.Maybe
import Data.Source
import Language.JSON.Grammar (Grammar)
import Parsing.TreeSitter
import Semantic.Config
import SpecHelpers
import System.Timeout
import TreeSitter.JSON
spec :: Spec
spec = parallel $ do
describe "parseToAST" $ do
let source = toJSONSource $ take 10000 [1..]
let largeBlob = sourceBlob "large.json" JSON source
it "returns a result when the timeout does not expire" $ do
let timeout = fromMicroseconds 0 -- Zero microseconds indicates no timeout
let parseTask = parseToAST timeout tree_sitter_json largeBlob :: TaskEff (Maybe (AST [] Grammar))
result <- runTaskOrDie parseTask
(isJust result) `shouldBe` True
it "returns nothing when the timeout expires" $ do
let timeout = fromMicroseconds 1000
let parseTask = parseToAST timeout tree_sitter_json largeBlob :: TaskEff (Maybe (AST [] Grammar))
result <- runTaskOrDie parseTask
(isNothing result) `shouldBe` True
toJSONSource :: Show a => a -> Source
toJSONSource = fromUTF8 . pack . show