-
Notifications
You must be signed in to change notification settings - Fork 0
/
preprocess_test.wax
81 lines (67 loc) · 3.43 KB
/
preprocess_test.wax
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
76
77
78
79
80
81
(@include "test.wax")
(@include "token.wax")
(@include "node.wax")
(@include "error.wax")
(@include "fileio.wax")
(@include "preprocess.wax")
(func preprocess_package_from_path_simple_test
; Given - simple include
(let test (struct test_test) (call test_init "preprocess_package_from_path_simple_test"))
(let node_include (struct node) (call node_new @NODE_EXPR "include"))
(let node_file (struct node) (call node_new @NODE_STR_QUOTE "\"wax/test.wax\""))
(insert (get node_include child) (# (get node_include child)) node_file)
; When
(let res (vec 3 str) (call preprocess_package_from_path "" node_include))
; Then
(call test_assert_equal test "test" (get res 0) "got expected package")
(call test_assert_equal test "wax/test.wax" (get res 1) "got expected filename")
(call test_assert_equal test "wax/" (get res 2) "got expected basepath")
)
(func preprocess_package_from_path_parentdir_test
; Given - parent directory include
(let test (struct test_test) (call test_init "preprocess_package_from_path_parentdir_test"))
(let node_include (struct node) (call node_new @NODE_EXPR "include"))
(let node_file (struct node) (call node_new @NODE_STR_QUOTE "\"wax/test.wax\""))
(insert (get node_include child) (# (get node_include child)) node_file)
; When
(let res (vec 3 str) (call preprocess_package_from_path "" node_include))
; Then
(call test_assert_equal test "test" (get res 0) "got expected package")
(call test_assert_equal test "wax/test.wax" (get res 1) "got expected filename")
(call test_assert_equal test "wax/" (get res 2) "got expected basepath")
)
(func preprocess_package_from_path_prefix_test
; Given - simple include, with basepath prefix
(let test (struct test_test) (call test_init "preprocess_package_from_path_prefix_test"))
(let node_include (struct node) (call node_new @NODE_EXPR "include"))
(let node_file (struct node) (call node_new @NODE_STR_QUOTE "\"../wax/test.wax\""))
(insert (get node_include child) (# (get node_include child)) node_file)
; When
(let res (vec 3 str) (call preprocess_package_from_path "" node_include))
; Then
(call test_assert_equal test "test" (get res 0) "got expected package")
(call test_assert_equal test "../wax/test.wax" (get res 1) "got expected filename")
(call test_assert_equal test "../wax/" (get res 2) "got expected basepath")
)
(func preprocess_package_from_path_alias_test
; Given - simple include
(let test (struct test_test) (call test_init "preprocess_package_from_path_alias_test"))
(let node_include (struct node) (call node_new @NODE_EXPR "import"))
(let node_package (struct node) (call node_new @NODE_STR_QUOTE "\"test\""))
(insert (get node_include child) (# (get node_include child)) node_package)
(let node_file (struct node) (call node_new @NODE_STR_QUOTE "\"wax/test123.wax\""))
(insert (get node_include child) (# (get node_include child)) node_file)
; When
(let res (vec 3 str) (call preprocess_package_from_path "" node_include))
; Then
(call test_assert_equal test "test" (get res 0) "got expected package")
(call test_assert_equal test "wax/test123.wax" (get res 1) "got expected filename")
(call test_assert_equal test "wax/" (get res 2) "got expected basepath")
)
(func main (result int)
(call preprocess_package_from_path_simple_test)
(call preprocess_package_from_path_parentdir_test)
(call preprocess_package_from_path_prefix_test)
(call preprocess_package_from_path_alias_test)
(return 0)
)