mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Enable multiple directives.
This commit is contained in:
parent
1472fc87e7
commit
31fbc386e9
@ -1,11 +1,12 @@
|
||||
module Directive ( Directive (..)
|
||||
, parseDirective
|
||||
, parseDirectives
|
||||
, toProcess
|
||||
) where
|
||||
|
||||
import Control.Applicative
|
||||
import Data.ByteString.Char8 (ByteString)
|
||||
import qualified Data.ByteString.Char8 as ByteString
|
||||
import Data.List.NonEmpty (NonEmpty)
|
||||
import Data.Coerce
|
||||
import System.Process
|
||||
import qualified Text.Trifecta as Trifecta
|
||||
@ -49,9 +50,12 @@ jq = do
|
||||
directive :: Trifecta.Parser Directive
|
||||
directive = fails <|> jq
|
||||
|
||||
parseDirective :: ByteString -> Either String Directive
|
||||
parseDirective = Trifecta.foldResult (Left . show) Right
|
||||
. Trifecta.parseByteString (directive <* Trifecta.eof) mempty
|
||||
toplevel :: Trifecta.Parser (NonEmpty Directive)
|
||||
toplevel = directive `Trifecta.sepEndByNonEmpty` Trifecta.char '\n'
|
||||
|
||||
parseDirectives :: ByteString -> Either String (NonEmpty Directive)
|
||||
parseDirectives = Trifecta.foldResult (Left . show) Right
|
||||
. Trifecta.parseByteString toplevel mempty
|
||||
|
||||
toProcess :: Directive -> CreateProcess
|
||||
toProcess (JQ d) = proc "jq" ["-e", ByteString.unpack d]
|
||||
|
@ -77,14 +77,13 @@ assertJQExpressionSucceeds directive core = do
|
||||
assertTranslationSucceeds :: HasCallStack => FilePath -> HUnit.Assertion
|
||||
assertTranslationSucceeds fp = withFrozenCallStack $ do
|
||||
fileContents <- ByteString.readFile ("semantic-python/test/fixtures" </> fp)
|
||||
let first = ByteString.takeWhile (/= '\n') fileContents
|
||||
directive <- case Directive.parseDirective first of
|
||||
directives <- case Directive.parseDirectives fileContents of
|
||||
Right dir -> pure dir
|
||||
Left err -> HUnit.assertFailure ("Directive parsing error: " <> err)
|
||||
|
||||
result <- TS.parseByteString TSP.tree_sitter_python fileContents
|
||||
let coreResult = fmap (Control.Effect.run . runFail . Py.compile @TSP.Module @_ @(Term (Ann :+: Core))) result
|
||||
case coreResult of
|
||||
for_ directives $ \directive -> case coreResult of
|
||||
Right (Left _) | directive == Directive.Fails -> pure ()
|
||||
Right (Right item) -> assertJQExpressionSucceeds directive item
|
||||
Right (Left err) -> HUnit.assertFailure ("Compilation failed: " <> err)
|
||||
@ -94,8 +93,8 @@ assertTranslationSucceeds fp = withFrozenCallStack $ do
|
||||
milestoneFixtures :: Tasty.TestTree
|
||||
milestoneFixtures = HUnit.testCaseSteps "Bootstrapping" $ \step -> do
|
||||
files <- liftIO (listDirectory "semantic-python/test/fixtures")
|
||||
let firstGroup = sort $ filter ((== '1') . head) files
|
||||
for_ firstGroup $ \file -> do
|
||||
let pyFiles = filter (isExtensionOf ".py") files
|
||||
for_ pyFiles $ \file -> do
|
||||
step file
|
||||
assertTranslationSucceeds file
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user