tests for comment parsing and parser benchmarks
This commit is contained in:
parent
3a08227c0c
commit
94b7e4b1d7
|
@ -0,0 +1,10 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import Criterion.Main
|
||||||
|
|
||||||
|
import qualified ParserBench
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = defaultMain
|
||||||
|
[ ParserBench.benchmarks
|
||||||
|
]
|
|
@ -0,0 +1,20 @@
|
||||||
|
module ParserBench (benchmarks) where
|
||||||
|
|
||||||
|
import Nix.Parser
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
|
import Criterion
|
||||||
|
|
||||||
|
benchFile :: FilePath -> Benchmark
|
||||||
|
benchFile = bench <*> whnfIO . parseNixFile . ("data/" ++)
|
||||||
|
|
||||||
|
benchmarks :: Benchmark
|
||||||
|
benchmarks = bgroup "Parser"
|
||||||
|
[ benchFile "nixpkgs-all-packages.nix"
|
||||||
|
, benchFile "nixpkgs-all-packages-pretty.nix"
|
||||||
|
, benchFile "let-comments.nix"
|
||||||
|
, benchFile "let-comments-multiline.nix"
|
||||||
|
, benchFile "let.nix"
|
||||||
|
, benchFile "simple.nix"
|
||||||
|
, benchFile "simple-pretty.nix"
|
||||||
|
]
|
|
@ -0,0 +1,13 @@
|
||||||
|
let
|
||||||
|
b.a = 3; /*
|
||||||
|
this is a multiline comment
|
||||||
|
/* we can also nest these comments
|
||||||
|
*/ /*
|
||||||
|
*/
|
||||||
|
*/
|
||||||
|
b.c = { e = {}; };
|
||||||
|
/* just some more comments
|
||||||
|
*/
|
||||||
|
b.c.e.f = 4;
|
||||||
|
/* this file is documented really well */
|
||||||
|
in b /* todo */
|
|
@ -0,0 +1,13 @@
|
||||||
|
let
|
||||||
|
b.a = 3;
|
||||||
|
# this is a oneline comment
|
||||||
|
# we can also nest these comments
|
||||||
|
# #
|
||||||
|
#
|
||||||
|
#
|
||||||
|
b.c = { e = {}; };
|
||||||
|
# just some more comments
|
||||||
|
#
|
||||||
|
b.c.e.f = 4;
|
||||||
|
# this file is documented really well
|
||||||
|
in b # todo
|
|
@ -0,0 +1,5 @@
|
||||||
|
let
|
||||||
|
b.a = 3;
|
||||||
|
b.c = { e = {}; };
|
||||||
|
b.c.e.f = 4;
|
||||||
|
in b
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
a = 3;
|
||||||
|
b = 4;
|
||||||
|
c = {
|
||||||
|
inherit ({ a = 3; }) a;
|
||||||
|
e = 4;
|
||||||
|
f = 5;
|
||||||
|
};
|
||||||
|
d = if true
|
||||||
|
then { a = 1; b = 2; c = 3; }
|
||||||
|
else if false
|
||||||
|
then null
|
||||||
|
else {
|
||||||
|
inherit ({
|
||||||
|
a = 3;
|
||||||
|
b = 4;
|
||||||
|
cdefgads = 5;
|
||||||
|
}) cdefgads;
|
||||||
|
};
|
||||||
|
f = x: x;
|
||||||
|
list = [
|
||||||
|
1
|
||||||
|
2
|
||||||
|
(f 3)
|
||||||
|
((x: x) 3)
|
||||||
|
[ 4 5 ]
|
||||||
|
];
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
{ a = 3; b = 4; c = { inherit ({a = 3; }) a; e = 4; f = 5; }; d = if true then { a = 1; b = 2; c = 3; } else if false then null else { inherit ({a = 3; b = 4; cdefgads = 5; }) cdefgads; }; f = x: x; list = [ 1 2 (f 3) ((x: x) 3) [ 4 5 ] ]; }
|
16
hnix.cabal
16
hnix.cabal
|
@ -87,6 +87,8 @@ Test-suite hnix-tests
|
||||||
Hs-source-dirs: tests
|
Hs-source-dirs: tests
|
||||||
Default-language: Haskell2010
|
Default-language: Haskell2010
|
||||||
Main-is: Main.hs
|
Main-is: Main.hs
|
||||||
|
Other-modules:
|
||||||
|
ParserTests
|
||||||
Build-depends:
|
Build-depends:
|
||||||
base >= 4.3 && < 5
|
base >= 4.3 && < 5
|
||||||
, containers
|
, containers
|
||||||
|
@ -96,6 +98,20 @@ Test-suite hnix-tests
|
||||||
, tasty-th
|
, tasty-th
|
||||||
, tasty-hunit
|
, tasty-hunit
|
||||||
|
|
||||||
|
Benchmark benchmarks
|
||||||
|
Type: exitcode-stdio-1.0
|
||||||
|
Hs-source-dirs: benchmarks
|
||||||
|
Default-language: Haskell2010
|
||||||
|
Main-is: Main.hs
|
||||||
|
Other-modules:
|
||||||
|
ParserBench
|
||||||
|
Build-depends:
|
||||||
|
base >= 4.3 && < 5
|
||||||
|
, containers
|
||||||
|
, text
|
||||||
|
, hnix
|
||||||
|
, criterion
|
||||||
|
|
||||||
source-repository head
|
source-repository head
|
||||||
type: git
|
type: git
|
||||||
location: git://github.com/jwiegley/hnix.git
|
location: git://github.com/jwiegley/hnix.git
|
||||||
|
|
|
@ -294,6 +294,12 @@ case_operators = do
|
||||||
(mkOper2 NMinus (mkSym "a") (mkSym "b")) $
|
(mkOper2 NMinus (mkSym "a") (mkSym "b")) $
|
||||||
mkSym "c"
|
mkSym "c"
|
||||||
|
|
||||||
|
case_comments :: Assertion
|
||||||
|
case_comments = do
|
||||||
|
Success expected <- parseNixFile "data/let.nix"
|
||||||
|
assertParseFile "let-comments-multiline.nix" expected
|
||||||
|
assertParseFile "let-comments.nix" expected
|
||||||
|
|
||||||
tests :: TestTree
|
tests :: TestTree
|
||||||
tests = $testGroupGenerator
|
tests = $testGroupGenerator
|
||||||
|
|
||||||
|
@ -303,6 +309,13 @@ assertParseString str expected = case parseNixString str of
|
||||||
Success actual -> assertEqual ("When parsing " ++ str) expected actual
|
Success actual -> assertEqual ("When parsing " ++ str) expected actual
|
||||||
Failure err -> assertFailure $ "Unexpected error parsing `" ++ str ++ "':\n" ++ show err
|
Failure err -> assertFailure $ "Unexpected error parsing `" ++ str ++ "':\n" ++ show err
|
||||||
|
|
||||||
|
assertParseFile :: FilePath -> NExpr -> Assertion
|
||||||
|
assertParseFile file expected = do
|
||||||
|
res <- parseNixFile $ "data/" ++ file
|
||||||
|
case res of
|
||||||
|
Success actual -> assertEqual ("Parsing data file " ++ file) expected actual
|
||||||
|
Failure err -> assertFailure $ "Unexpected error parsing data file `" ++ file ++ "':\n" ++ show err
|
||||||
|
|
||||||
assertParseFail :: String -> Assertion
|
assertParseFail :: String -> Assertion
|
||||||
assertParseFail str = case parseNixString str of
|
assertParseFail str = case parseNixString str of
|
||||||
Failure _ -> return ()
|
Failure _ -> return ()
|
||||||
|
|
Loading…
Reference in New Issue