-
Notifications
You must be signed in to change notification settings - Fork 4
/
TraversalTests.fs
66 lines (57 loc) · 2.09 KB
/
TraversalTests.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
/// <summary>
/// Tests for <c>Sub</c>.
/// </summary>
module Starling.Tests.Core.Traversal
open NUnit.Framework
open Starling.Utils.Testing
open Starling.Core.Expr
open Starling.Core.TypeSystem
open Starling.Core.Var
open Starling.Core.Traversal
open Starling.Core.Pretty
open Starling.Core.Traversal.Pretty
/// <summary>
/// Test cases for finding variables in expressions.
/// </summary>
module FindVars =
/// <summary>
/// Tests finding variables in expressions.
/// </summary>
let check (expected : TypedVar list) (expr : Expr<Var>) : unit =
let result = findVars (tliftOverExpr collectVars) expr
assertOkAndEqual (Set.ofList expected) result
(printTraversalError (fun () -> String "?") >> printUnstyled)
[<Test>]
let ``Finding vars in a Boolean primitive returns empty`` () =
check [] (normalBoolExpr BTrue)
[<Test>]
let ``Finding vars in an integer primitive returns empty`` () =
check [] (normalIntExpr (IInt 1L))
[<Test>]
let ``Finding vars in a Boolean var returns that var`` () =
check [ normalBoolVar "foo" ] (normalBoolExpr (BVar "foo"))
[<Test>]
let ``Finding vars in an integer var returns that var`` () =
check [ normalIntVar "bar" ] (normalIntExpr (IVar "bar"))
[<Test>]
let ``Finding vars in a Boolean expression works correctly`` () =
check
[ normalBoolVar "foo"
normalBoolVar "baz"
normalIntVar "foobar"
normalIntVar "barbaz" ]
(normalBoolExpr
(BAnd
[ BOr [ BVar "foo"; BVar "baz" ]
BGt ( normalInt (IVar "foobar"), normalInt (IVar "barbaz")) ] ))
[<Test>]
let ``Finding vars in an integer expression works correctly`` () =
check
[ normalIntVar "foo"
normalIntVar "bar"
normalIntVar "foobar"
normalIntVar "barbaz" ]
(normalIntExpr
(IAdd
[ ISub [ IVar "foo"; IVar "bar" ]
IMul [ IVar "foobar"; IVar "barbaz" ]] ))