1
1
mirror of https://github.com/github/semantic.git synced 2024-12-15 18:13:38 +03:00
semantic/test/Spec.hs

81 lines
3.5 KiB
Haskell
Raw Normal View History

2016-01-05 19:27:37 +03:00
module Main where
2018-03-13 21:14:55 +03:00
import qualified Analysis.Go.Spec
import qualified Analysis.PHP.Spec
import qualified Analysis.Python.Spec
2018-03-14 02:19:26 +03:00
import qualified Analysis.Ruby.Spec
2018-03-10 03:24:32 +03:00
import qualified Analysis.TypeScript.Spec
2017-11-27 21:47:04 +03:00
import qualified Assigning.Assignment.Spec
2018-05-07 21:21:05 +03:00
import qualified Control.Abstract.Evaluator.Spec
2018-09-14 20:08:08 +03:00
import qualified Control.Rewriting.Spec
2017-11-27 21:59:44 +03:00
import qualified Data.Diff.Spec
2018-10-31 20:19:43 +03:00
import qualified Data.Abstract.Name.Spec
import qualified Data.Abstract.Path.Spec
import qualified Data.Functor.Classes.Generic.Spec
2018-10-31 19:20:38 +03:00
import qualified Data.Graph.Spec
2018-10-31 19:46:52 +03:00
import qualified Data.Range.Spec
import qualified Data.Scientific.Spec
2018-10-31 22:47:30 +03:00
import qualified Data.Semigroup.App.Spec
2017-11-27 21:49:52 +03:00
import qualified Data.Source.Spec
2017-11-27 22:02:03 +03:00
import qualified Data.Term.Spec
2017-11-27 21:48:43 +03:00
import qualified Diffing.Algorithm.RWS.Spec
2017-11-27 21:51:05 +03:00
import qualified Diffing.Algorithm.SES.Spec
2017-11-27 22:03:45 +03:00
import qualified Diffing.Interpreter.Spec
2018-07-16 18:07:40 +03:00
import qualified Graphing.Calls.Spec
2017-11-27 22:06:12 +03:00
import qualified Integration.Spec
import qualified Matching.Go.Spec
Give Control.Matching API better ergonomics. Given that @tclem and I have found the matcher API frustrating, I've taken a stab at improving its ergonomics, and I've found some success in separating composition of matchers from predicate-based narrowing thereof. The biggest change here is the elimination of the old `match` combinator, which proved to be clumsy in that it complected narrowing and composition. Top-down matching combinators are now written with the `need` combinator and the `>>>` combinator, which is more readable and more versatile. Here's a matcher that accepts functions with Python docstrings: ```haskell docstringMatcher :: ( Decl.Function :< fs , [] :< fs , Lit.TextElement :< fs , term ~ Term (Sum fs) ann ) => Matcher term term docstringMatcher = target <* (need Decl.functionBody >>> narrow @[] >>> mhead >>> narrow @Lit.TextElement >>> ensure Lit.isTripleQuoted)) ``` Pretty readable, right? Each step of the tree regular expression - choosing function bodies, ensuring said bodies are lists, examining the first element, and choosing only TextElements containing triple-quoted strings - is made implicit. The old way would have looked something like this: ```haskell docstringMatcher = target <* match Decl.functionBody $ narrow $ matchM listToMaybe $ target <* ensure Lit.isTripleQuoted ``` which is a good deal more disorganized and less flexible in the quite-common case of applying functions during a matching pass. Separating the act of composition from function application is a big win here. Further comments are inline.
2018-11-03 02:25:29 +03:00
import qualified Matching.Python.Spec
import qualified Numeric.Spec
2017-11-27 22:04:58 +03:00
import qualified Rendering.TOC.Spec
2018-07-31 19:44:20 +03:00
import qualified Reprinting.Spec
2018-11-02 23:55:30 +03:00
import qualified Tags.Spec
2017-11-27 22:00:53 +03:00
import qualified Semantic.Spec
2017-11-27 21:57:25 +03:00
import qualified Semantic.CLI.Spec
2017-11-27 21:52:48 +03:00
import qualified Semantic.IO.Spec
2017-11-27 21:58:23 +03:00
import qualified Semantic.Stat.Spec
2018-07-10 21:17:56 +03:00
import Semantic.Config (defaultOptions)
import Semantic.Task (withOptions)
2018-07-10 21:09:02 +03:00
import Semantic.Util (TaskConfig(..))
2018-06-05 19:51:23 +03:00
import qualified Proto3.Roundtrip
2016-01-05 19:27:37 +03:00
import Test.Hspec
main :: IO ()
main = do
2018-07-10 21:16:51 +03:00
withOptions defaultOptions $ \ config logger statter -> hspec $ do
let args = TaskConfig config logger statter
describe "Semantic.Stat" Semantic.Stat.Spec.spec
parallel $ do
describe "Analysis.Go" (Analysis.Go.Spec.spec args)
describe "Analysis.PHP" (Analysis.PHP.Spec.spec args)
describe "Analysis.Python" (Analysis.Python.Spec.spec args)
describe "Analysis.Ruby" (Analysis.Ruby.Spec.spec args)
describe "Analysis.TypeScript" (Analysis.TypeScript.Spec.spec args)
describe "Assigning.Assignment" Assigning.Assignment.Spec.spec
describe "Control.Abstract.Evaluator" Control.Abstract.Evaluator.Spec.spec
2018-09-14 20:08:08 +03:00
describe "Control.Rewriting.Spec" Control.Rewriting.Spec.spec
describe "Data.Diff" Data.Diff.Spec.spec
2018-10-31 19:20:38 +03:00
describe "Data.Graph" Data.Graph.Spec.spec
describe "Data.Abstract.Path" Data.Abstract.Path.Spec.spec
2018-10-31 20:19:43 +03:00
describe "Data.Abstract.Name" Data.Abstract.Name.Spec.spec
describe "Data.Functor.Classes.Generic" Data.Functor.Classes.Generic.Spec.spec
2018-10-31 19:46:52 +03:00
describe "Data.Range" Data.Range.Spec.spec
describe "Data.Scientific" Data.Scientific.Spec.spec
2018-10-31 22:47:30 +03:00
describe "Data.Semigroup.App" Data.Semigroup.App.Spec.spec
describe "Data.Source" Data.Source.Spec.spec
describe "Data.Term" Data.Term.Spec.spec
describe "Diffing.Algorithm.RWS" Diffing.Algorithm.RWS.Spec.spec
describe "Diffing.Algorithm.SES" Diffing.Algorithm.SES.Spec.spec
describe "Diffing.Interpreter" Diffing.Interpreter.Spec.spec
2018-07-16 18:07:40 +03:00
describe "Graphing.Calls" Graphing.Calls.Spec.spec
Give Control.Matching API better ergonomics. Given that @tclem and I have found the matcher API frustrating, I've taken a stab at improving its ergonomics, and I've found some success in separating composition of matchers from predicate-based narrowing thereof. The biggest change here is the elimination of the old `match` combinator, which proved to be clumsy in that it complected narrowing and composition. Top-down matching combinators are now written with the `need` combinator and the `>>>` combinator, which is more readable and more versatile. Here's a matcher that accepts functions with Python docstrings: ```haskell docstringMatcher :: ( Decl.Function :< fs , [] :< fs , Lit.TextElement :< fs , term ~ Term (Sum fs) ann ) => Matcher term term docstringMatcher = target <* (need Decl.functionBody >>> narrow @[] >>> mhead >>> narrow @Lit.TextElement >>> ensure Lit.isTripleQuoted)) ``` Pretty readable, right? Each step of the tree regular expression - choosing function bodies, ensuring said bodies are lists, examining the first element, and choosing only TextElements containing triple-quoted strings - is made implicit. The old way would have looked something like this: ```haskell docstringMatcher = target <* match Decl.functionBody $ narrow $ matchM listToMaybe $ target <* ensure Lit.isTripleQuoted ``` which is a good deal more disorganized and less flexible in the quite-common case of applying functions during a matching pass. Separating the act of composition from function application is a big win here. Further comments are inline.
2018-11-03 02:25:29 +03:00
describe "Matching.Go" Matching.Go.Spec.spec
describe "Matching.Python" Matching.Python.Spec.spec
describe "Numeric" Numeric.Spec.spec
describe "Rendering.TOC" Rendering.TOC.Spec.spec
2018-07-31 19:44:20 +03:00
describe "Reprinting.Spec" Reprinting.Spec.spec
2018-11-02 23:55:30 +03:00
describe "Tags.Spec" Tags.Spec.spec
describe "Semantic" Semantic.Spec.spec
describe "Semantic.CLI" Semantic.CLI.Spec.spec
describe "Semantic.IO" Semantic.IO.Spec.spec
describe "Integration" (Integration.Spec.spec args)
describe "Protobuf roundtripping" Proto3.Roundtrip.spec