2019-10-01 00:59:23 +03:00
|
|
|
{-# LANGUAGE TypeApplications #-}
|
2019-03-19 20:13:03 +03:00
|
|
|
module Parsing.Spec (spec) where
|
|
|
|
|
|
|
|
import Data.Blob
|
|
|
|
import Data.ByteString.Char8 (pack)
|
|
|
|
import Data.Duration
|
2019-10-01 00:59:23 +03:00
|
|
|
import Data.Either
|
2019-03-19 20:13:03 +03:00
|
|
|
import Data.Language
|
|
|
|
import Parsing.TreeSitter
|
2019-09-20 22:51:49 +03:00
|
|
|
import Source.Source
|
2019-03-19 20:13:03 +03:00
|
|
|
import SpecHelpers
|
2019-09-20 22:51:49 +03:00
|
|
|
import TreeSitter.JSON (Grammar, tree_sitter_json)
|
2019-03-19 20:13:03 +03:00
|
|
|
|
|
|
|
spec :: Spec
|
2019-06-20 00:22:09 +03:00
|
|
|
spec = do
|
2019-03-19 20:13:03 +03:00
|
|
|
describe "parseToAST" $ do
|
2019-06-15 07:53:02 +03:00
|
|
|
let source = toJSONSource [1 :: Int .. 10000]
|
2019-03-19 20:13:03 +03:00
|
|
|
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
|
2019-10-01 00:59:23 +03:00
|
|
|
let parseTask = parseToAST @Grammar timeout tree_sitter_json largeBlob
|
2019-03-19 20:13:03 +03:00
|
|
|
result <- runTaskOrDie parseTask
|
2019-10-01 00:59:23 +03:00
|
|
|
isRight result `shouldBe` True
|
2019-03-19 20:13:03 +03:00
|
|
|
|
|
|
|
it "returns nothing when the timeout expires" $ do
|
|
|
|
let timeout = fromMicroseconds 1000
|
2019-10-01 00:59:23 +03:00
|
|
|
let parseTask = parseToAST @Grammar timeout tree_sitter_json largeBlob
|
2019-03-19 20:13:03 +03:00
|
|
|
result <- runTaskOrDie parseTask
|
2019-10-01 00:59:23 +03:00
|
|
|
isLeft result `shouldBe` True
|
2019-03-19 20:13:03 +03:00
|
|
|
|
|
|
|
toJSONSource :: Show a => a -> Source
|
|
|
|
toJSONSource = fromUTF8 . pack . show
|