-
Notifications
You must be signed in to change notification settings - Fork 4
/
PrettyTests.fs
75 lines (64 loc) · 2.05 KB
/
PrettyTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/// <summary>
/// Test module for the pretty printer module.
/// </summary>
module Starling.Tests.Pretty
open NUnit.Framework
open Starling
open Starling.Utils.Testing
open Starling.Core.Var
open Starling.Lang.AST
open Starling.Lang.AST.Pretty
/// <summary>
/// Tests for <see cref="printExpression"/>.
/// </summary>
module ExpressionTests =
let check expr str =
Core.Pretty.printUnstyled (printExpression (freshNode expr)) ?=? str
[<Test>]
let ``expression '5' is printed correctly`` () =
check (Num 5L) "5"
[<Test>]
let ``expression '(6 / bar)' is printed correctly`` () =
check
(BopExpr(Div, freshNode <| Num 6L, freshNode <| Identifier "bar"))
"(6 / bar)"
[<Test>]
let ``expression '((1 + 2) * 3)' is printed correctly`` () =
check
(BopExpr
(Mul,
freshNode <| BopExpr
(Add,
freshNode (Num 1L),
freshNode (Num 2L)),
freshNode (Num 3L)))
"((1 + 2) * 3)"
/// <summary>
/// Tests for <see cref="printSymbolic"/>.
/// </summary>
module SymbolicTests =
open Starling.Core.Symbolic
let check sym str =
Core.Pretty.printUnstyled (printSymbolic sym) ?=? str
[<Test>]
let ``the empty symbol %{} is printed correctly`` () =
check [] "%{}"
[<Test>]
let ``the symbol %{hello, world} is printed correctly`` () =
check [ SymString "hello, world" ] "%{hello, world}"
[<Test>]
let ``the split symbol %{hello, world} is printed correctly`` () =
check
[ SymString "hello,"
SymString " "
SymString "world" ]
"%{hello, world}"
[<Test>]
let ``the symbol %{[|2|] + [|2|] = [|5|]} is printed correctly`` () =
check
[ SymArg (freshNode (Num 2L))
SymString " + "
SymArg (freshNode (Num 2L))
SymString " = "
SymArg (freshNode (Num 5L)) ]
"%{[|2|] + [|2|] = [|5|]}"