Skip to content

Commit 09b1fcc

Browse files
committed
Setup boilerplate for parser tests
1 parent 31daac5 commit 09b1fcc

File tree

8 files changed

+67
-23
lines changed

8 files changed

+67
-23
lines changed

gren.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
"Compiler.Paths",
1818
"Compiler.License",
1919
"FileSystem.Lock",
20+
"Parse.Number",
2021
"SemanticVersion",
2122
"SemanticVersionRange",
2223
"String.EditDistance"
2324
],
2425
"gren-version": "0.6.0 <= v < 0.7.0",
2526
"dependencies": {
2627
"gren-lang/core": "7.1.0 <= v < 8.0.0",
27-
"gren-lang/node": "6.1.0 <= v < 7.0.0"
28+
"gren-lang/node": "6.1.0 <= v < 7.0.0",
29+
"gren-lang/parser": "6.1.0 <= v < 7.0.0"
2830
}
29-
}
31+
}
21.1 KB
Binary file not shown.

src/Parse/Number.gren

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Parse.Number exposing (Format (..), Outcome (..), parser)
2+
3+
4+
import Parser.Advanced as Parser exposing (Parser)
5+
6+
7+
type Format
8+
= Decimal
9+
| Hex
10+
11+
12+
type Outcome
13+
= Integer { format: Format, value : Int }
14+
15+
16+
parser : Parser c {} Outcome
17+
parser =
18+
Parser.succeed (Integer { format = Decimal, value = 0 })

tests/gren.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"gren-lang/node": "6.1.0",
1111
"gren-lang/core": "7.1.0",
1212
"gren-lang/test": "5.0.0",
13+
"gren-lang/parser": "6.1.0",
1314
"gren-lang/test-runner-node": "7.0.0",
1415
"gren-lang/compiler-node": "local:.."
1516
},
21.1 KB
Binary file not shown.

tests/src/Main.gren

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,30 @@ module Main exposing (main)
22

33
import Test
44
import Test.Runner.Node as TestRunner
5-
import Test.CLI.Parser as CLIParser
6-
import Test.CLI.PrettyPrinter as PrettyPrinter
7-
import Test.SemanticVersion as SemanticVersion
8-
import Test.SemanticVersionRange as SemanticVersionRange
9-
import Test.Compiler.Dependencies as Dependencies
10-
import Test.Compiler.PackageName as PackageName
11-
import Test.Compiler.ModuleName as ModuleName
12-
import Test.Compiler.Platform as Platform
13-
import Test.String.EditDistance as EditDistance
14-
import Node exposing (Program)
5+
import Test.CLI.Parser
6+
import Test.CLI.PrettyPrinter
7+
import Test.SemanticVersion
8+
import Test.SemanticVersionRange
9+
import Test.Compiler.Dependencies
10+
import Test.Compiler.PackageName
11+
import Test.Compiler.ModuleName
12+
import Test.Compiler.Platform
13+
import Test.String.EditDistance
14+
import Test.Parse.Number
1515

1616

1717
main : TestRunner.Program
1818
main =
1919
TestRunner.run <|
2020
Test.describe "Gren Compiler Node tests"
21-
[ CLIParser.tests
22-
, Dependencies.tests
23-
, PrettyPrinter.tests
24-
, SemanticVersion.tests
25-
, SemanticVersionRange.tests
26-
, PackageName.tests
27-
, ModuleName.tests
28-
, Platform.tests
29-
, EditDistance.tests
21+
[ Test.CLI.Parser.tests
22+
, Test.CLI.PrettyPrinter.tests
23+
, Test.SemanticVersion.tests
24+
, Test.SemanticVersionRange.tests
25+
, Test.Compiler.Dependencies.tests
26+
, Test.Compiler.PackageName.tests
27+
, Test.Compiler.ModuleName.tests
28+
, Test.Compiler.Platform.tests
29+
, Test.String.EditDistance.tests
30+
, Test.Parse.Number.tests
3031
]

tests/src/Test/Parse/Number.gren

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Test.Parse.Number exposing ( tests )
2+
3+
import Expect exposing (Expectation)
4+
import Test exposing (Test, describe, test, fuzz)
5+
import Fuzz exposing (Fuzzer)
6+
import Parser.Advanced as Parser
7+
import Parse.Number as PN
8+
9+
10+
tests : Test
11+
tests =
12+
describe "Parse.Number"
13+
[ describe "Integers"
14+
[ fuzz Fuzz.int "Can parse regular integers" <| \int ->
15+
run (String.fromInt int)
16+
|> Expect.equal (Ok (PN.Integer { format = PN.Decimal, value = int }))
17+
]
18+
]
19+
20+
21+
run : String -> Result (Array (Parser.DeadEnd c {})) PN.Outcome
22+
run str =
23+
Parser.run PN.parser str

tests/src/Test/String/EditDistance.gren

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
module Test.String.EditDistance exposing
2-
( tests )
1+
module Test.String.EditDistance exposing ( tests )
32

43
import Expect exposing (Expectation)
54
import Test exposing (Test, describe, test)

0 commit comments

Comments
 (0)