mirror of
https://github.com/github/semantic.git
synced 2024-11-23 08:27:56 +03:00
Bring back tree-sitter corpus tests for go
This commit is contained in:
parent
4566a59f42
commit
68bc0f68d5
1
.github/workflows/haskell.yml
vendored
1
.github/workflows/haskell.yml
vendored
@ -61,6 +61,7 @@ jobs:
|
||||
cabal v2-build --project-file=cabal.project.ci
|
||||
cabal v2-run --project-file=cabal.project.ci semantic:test
|
||||
cabal v2-run --project-file=cabal.project.ci semantic-core:test
|
||||
cabal v2-run --project-file=cabal.project.ci semantic-go:test
|
||||
cabal v2-run --project-file=cabal.project.ci semantic-python:test:compiling
|
||||
cabal v2-run --project-file=cabal.project.ci semantic-python:test:graphing
|
||||
cd semantic-source; cabal v2-run --project-file=cabal.project.ci semantic-source:test; cd ..
|
||||
|
@ -2,6 +2,7 @@
|
||||
module AST.Test
|
||||
( CorpusExample(..)
|
||||
, readCorpusFiles
|
||||
, readCorpusFiles'
|
||||
, parseCorpusFile
|
||||
, testCorpus
|
||||
) where
|
||||
@ -22,7 +23,7 @@ import System.FilePath.Glob
|
||||
import Test.Tasty
|
||||
import Test.Tasty.HUnit
|
||||
|
||||
testCorpus :: (ByteString -> IO (Either String (t a))) -> Path.RelFile -> IO TestTree
|
||||
testCorpus :: (ByteString -> IO (Either String (t a))) -> Path.AbsRelFile -> IO TestTree
|
||||
testCorpus parse path = do
|
||||
xs <- parseCorpusFile path
|
||||
case xs of
|
||||
@ -50,10 +51,15 @@ readCorpusFiles parent = do
|
||||
files <- globDir1 (compile "**/*.txt") (Path.toString dir)
|
||||
pure (Path.relPath <$> files)
|
||||
|
||||
readCorpusFiles' :: Path.AbsDir -> IO [Path.AbsRelFile]
|
||||
readCorpusFiles' dir = do
|
||||
files <- globDir1 (compile "**/*.txt") (Path.toString dir)
|
||||
pure (Path.file <$> files)
|
||||
|
||||
data CorpusExample = CorpusExample { name :: String, code :: ByteString }
|
||||
deriving (Eq, Show)
|
||||
|
||||
parseCorpusFile :: Path.RelFile -> IO (Either String [CorpusExample])
|
||||
parseCorpusFile :: Path.AbsRelFile -> IO (Either String [CorpusExample])
|
||||
parseCorpusFile path = do
|
||||
c <- Data.ByteString.readFile (Path.toString path)
|
||||
pure $ parseOnly corpusParser c
|
||||
|
@ -31,7 +31,7 @@ common haskell
|
||||
, template-haskell ^>= 2.15
|
||||
, text ^>= 1.2.3
|
||||
, tree-sitter ^>= 0.9
|
||||
, tree-sitter-go ^>= 0.5.0.0
|
||||
, tree-sitter-go ^>= 0.5.0.1
|
||||
|
||||
ghc-options:
|
||||
-Weverything
|
||||
|
@ -12,11 +12,12 @@
|
||||
|
||||
module Language.Go.AST
|
||||
( module Language.Go.AST
|
||||
, Go.getTestCorpusDir
|
||||
) where
|
||||
|
||||
import Prelude hiding (False, Float, Integer, Rational, String, True)
|
||||
import AST.GenerateSyntax
|
||||
import Language.Haskell.TH.Syntax (runIO)
|
||||
import qualified TreeSitter.Go as Go (getNodeTypesPath, tree_sitter_go)
|
||||
import qualified TreeSitter.Go as Go (getNodeTypesPath, getTestCorpusDir, tree_sitter_go)
|
||||
|
||||
runIO Go.getNodeTypesPath >>= astDeclarationsForLanguage Go.tree_sitter_go
|
||||
|
@ -10,7 +10,8 @@ import Test.Tasty
|
||||
|
||||
main :: IO ()
|
||||
main
|
||||
= readCorpusFiles (Path.relDir "tree-sitter-go/vendor/tree-sitter-go/corpus")
|
||||
= Path.absDir <$> Go.getTestCorpusDir
|
||||
>>= readCorpusFiles'
|
||||
>>= traverse (testCorpus parse)
|
||||
>>= defaultMain . tests
|
||||
where parse = parseByteString @Go.SourceFile @() tree_sitter_go
|
||||
|
Loading…
Reference in New Issue
Block a user