Skip to content
This repository was archived by the owner on May 22, 2019. It is now read-only.

Commit 5261c7e

Browse files
committed
Add golden tests for layout
1 parent 5d5aa31 commit 5261c7e

22 files changed

+326
-5
lines changed

package.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,15 @@ executables:
9999

100100
tests:
101101
purescript-cst-test:
102-
main: Spec.hs
102+
main: Main.hs
103103
source-dirs: test
104104
ghc-options:
105105
- -threaded
106106
- -rtsopts
107107
- -with-rtsopts=-N
108108
dependencies:
109109
- purescript-cst
110+
- bytestring
111+
- filepath
112+
- tasty
113+
- tasty-golden

purescript-cst.cabal

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
--
33
-- see: https://github.com/sol/hpack
44
--
5-
-- hash: 1e42d1d28abc402cc9e87fa2aea472ed5adbe23f1624e524fd3945c2d3a034bf
5+
-- hash: 4628a2ef8808b8d6029e3a9c0b0a82502e9e834abfc57edc206691a00bac1d64
66

77
name: purescript-cst
88
version: 0.1.0.0
@@ -90,7 +90,7 @@ executable purescript-cst-exe
9090

9191
test-suite purescript-cst-test
9292
type: exitcode-stdio-1.0
93-
main-is: Spec.hs
93+
main-is: Main.hs
9494
other-modules:
9595
Paths_purescript_cst
9696
hs-source-dirs:
@@ -102,16 +102,20 @@ test-suite purescript-cst-test
102102
, array
103103
, async
104104
, base >=4.7 && <5
105+
, bytestring
105106
, containers
106107
, criterion
107108
, deepseq
108109
, dlist
110+
, filepath
109111
, megaparsec ==7.0.4
110112
, mtl
111113
, pretty-simple
112114
, prettyprinter ==1.2.1
113115
, purescript ==0.12.2
114116
, purescript-cst
115117
, scientific
118+
, tasty
119+
, tasty-golden
116120
, text
117121
default-language: Haskell2010

test/Main.hs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Prelude
2+
3+
import qualified Data.ByteString.Lazy as BS
4+
import qualified Data.Text as Text
5+
import qualified Data.Text.Encoding as Text
6+
import qualified Data.Text.IO as Text
7+
import Test.Tasty (defaultMain, TestTree, testGroup)
8+
import Test.Tasty.Golden (goldenVsString, findByExtension)
9+
import Language.PureScript.CST.Errors as CST
10+
import Language.PureScript.CST.Lexer as CST
11+
import Language.PureScript.CST.Print as CST
12+
import System.FilePath (takeBaseName, replaceExtension)
13+
14+
main :: IO ()
15+
main = defaultMain =<< layoutTests
16+
17+
layoutTests :: IO TestTree
18+
layoutTests = do
19+
pursFiles <- findByExtension [".purs"] "./test/layout"
20+
return $ testGroup "Layout golden tests" $ do
21+
file <- pursFiles
22+
pure $ goldenVsString
23+
(takeBaseName file)
24+
(replaceExtension file ".out")
25+
(BS.fromStrict . Text.encodeUtf8 <$> runLexer file)
26+
27+
where
28+
runLexer file = do
29+
src <- Text.readFile file
30+
case CST.lex src of
31+
Left errs ->
32+
pure $ Text.pack $ unlines $ CST.prettyPrintError <$> errs
33+
Right toks -> do
34+
pure $ CST.printTokens toks

test/Spec.hs

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/layout/AdoIn.out

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Test where{
2+
3+
test = ado{
4+
baz;
5+
let {foo = bar}}
6+
in bar;
7+
8+
test = ado {}in foo}

test/layout/AdoIn.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Test where
2+
3+
test = ado
4+
baz
5+
let foo = bar
6+
in bar
7+
8+
test = ado in foo

test/layout/CaseGuards.out

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module Test where{
2+
3+
-- Including data because of `|` masking
4+
data Foo
5+
= Foo
6+
| Bar
7+
| Baz;
8+
9+
test =
10+
case foo of{
11+
a | b, c ->
12+
d;
13+
a | b, c -> d};
14+
15+
test = case a, b of{
16+
c, d
17+
| e ->
18+
case e of{
19+
f | true -> bar
20+
| false -> baz}
21+
| f -> g};
22+
23+
test a
24+
| false =
25+
case false of{
26+
true | a > 12 -> true}
27+
| otherwise = true;
28+
29+
test = case a of {foo | foo \a -> a -> true};
30+
31+
test = a `case _ of {x | unit # \_ -> true, true -> const}` b;
32+
33+
test = case a of{
34+
12 | do {that;
35+
that }-> this
36+
| otherwise -> this};
37+
38+
test a b = [ case _ of{
39+
12 | case a, b of{
40+
_, 42 -> b;
41+
_, 12 -> false}, b -> true
42+
| case a, b of{
43+
_, 42 -> b;
44+
_, 12 -> false}, b -> true}, false ];
45+
46+
test a
47+
| case a, b of{
48+
_, 42 -> b;
49+
_, 12 -> false}, b = true
50+
| case a, b of{
51+
_, 42 -> b;
52+
_, 12 -> false}, b = true}

test/layout/CaseGuards.purs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
module Test where
2+
3+
-- Including data because of `|` masking
4+
data Foo
5+
= Foo
6+
| Bar
7+
| Baz
8+
9+
test =
10+
case foo of
11+
a | b, c ->
12+
d
13+
a | b, c -> d
14+
15+
test = case a, b of
16+
c, d
17+
| e ->
18+
case e of
19+
f | true -> bar
20+
| false -> baz
21+
| f -> g
22+
23+
test a
24+
| false =
25+
case false of
26+
true | a > 12 -> true
27+
| otherwise = true
28+
29+
test = case a of foo | foo \a -> a -> true
30+
31+
test = a `case _ of x | unit # \_ -> true, true -> const` b
32+
33+
test = case a of
34+
12 | do that
35+
that -> this
36+
| otherwise -> this
37+
38+
test a b = [ case _ of
39+
12 | case a, b of
40+
_, 42 -> b
41+
_, 12 -> false, b -> true
42+
| case a, b of
43+
_, 42 -> b
44+
_, 12 -> false, b -> true, false ]
45+
46+
test a
47+
| case a, b of
48+
_, 42 -> b
49+
_, 12 -> false, b = true
50+
| case a, b of
51+
_, 42 -> b
52+
_, 12 -> false, b = true
53+

test/layout/CaseWhere.out

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Test where{
2+
3+
test = case foo of{
4+
Nothing -> a
5+
where {a = 12};
6+
Just a -> do{
7+
what}}
8+
where{
9+
foo = bar};
10+
11+
test = case f of {Foo -> do {that}
12+
where {foo = 12}}}

test/layout/CaseWhere.purs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module Test where
2+
3+
test = case foo of
4+
Nothing -> a
5+
where a = 12
6+
Just a -> do
7+
what
8+
where
9+
foo = bar
10+
11+
test = case f of Foo -> do that
12+
where foo = 12

0 commit comments

Comments
 (0)