summaryrefslogtreecommitdiff
path: root/spec/inputs/test/format_spec.yue
blob: 6b94540451712a6146f5532faea5b8b0883b7d75 (plain)
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
files = [
	"spec/inputs/macro_export.yue"
	"spec/inputs/attrib.yue"
	"spec/inputs/macro.yue"
	"spec/inputs/using.yue"
	"spec/inputs/whitespace.yue"
	"spec/inputs/nil_coalescing.yue"
	"spec/inputs/stub.yue"
	"spec/inputs/pipe.yue"
	"spec/inputs/teal_lang.yue"
	"spec/inputs/string.yue"
	"spec/inputs/local.yue"
	"spec/inputs/tables.yue"
	"spec/inputs/operators.yue"
	"spec/inputs/lists.yue"
	"spec/inputs/compile_doc.yue"
	"spec/inputs/switch.yue"
	"spec/inputs/multiline_chain.yue"
	"spec/inputs/existential.yue"
	"spec/inputs/export_default.yue"
	"spec/inputs/assign.yue"
	"spec/inputs/literals.yue"
	"spec/inputs/luarocks_upload.yue"
	"spec/inputs/ambiguous.yue"
	"spec/inputs/bubbling.yue"
	"spec/inputs/try_catch.yue"
	"spec/inputs/funcs.yue"
	"spec/inputs/do.yue"
	"spec/inputs/with.yue"
	"spec/inputs/export.yue"
	"spec/inputs/macro_todo.yue"
	"spec/inputs/backcall.yue"
	"spec/inputs/cond.yue"
	"spec/inputs/in_expression.yue"
	"spec/inputs/comprehension.yue"
	"spec/inputs/macro_teal.yue"
	"spec/inputs/import.yue"
	"spec/inputs/unless_else.yue"
	"spec/inputs/destructure.yue"
	"spec/inputs/return.yue"
	"spec/inputs/loops.yue"
	"spec/inputs/class.yue"
	"spec/inputs/vararg.yue"
	"spec/inputs/goto.yue"
	"spec/inputs/metatable.yue"
	"spec/inputs/syntax.yue"
	"spec/inputs/global.yue"
	"spec/inputs/plus.yue"
	"spec/inputs/test/class_spec.yue"
	"spec/inputs/test/table_spreading_spec.yue"
	"spec/inputs/test/loops_spec.yue"
	"spec/inputs/test/format_spec.yue"
	"spec/inputs/upvalue_func.yue"
	"spec/inputs/import_global.yue"
	"spec/inputs/unicode/macro_export.yue"
	"spec/inputs/unicode/attrib.yue"
	"spec/inputs/unicode/macro.yue"
	"spec/inputs/unicode/using.yue"
	"spec/inputs/unicode/whitespace.yue"
	"spec/inputs/unicode/nil_coalescing.yue"
	"spec/inputs/unicode/stub.yue"
	"spec/inputs/unicode/pipe.yue"
	"spec/inputs/unicode/string.yue"
	"spec/inputs/unicode/local.yue"
	"spec/inputs/unicode/tables.yue"
	"spec/inputs/unicode/operators.yue"
	"spec/inputs/unicode/lists.yue"
	"spec/inputs/unicode/switch.yue"
	"spec/inputs/unicode/multiline_chain.yue"
	"spec/inputs/unicode/existential.yue"
	"spec/inputs/unicode/export_default.yue"
	"spec/inputs/unicode/assign.yue"
	"spec/inputs/unicode/literals.yue"
	"spec/inputs/unicode/ambiguous.yue"
	"spec/inputs/unicode/bubbling.yue"
	"spec/inputs/unicode/try_catch.yue"
	"spec/inputs/unicode/funcs.yue"
	"spec/inputs/unicode/do.yue"
	"spec/inputs/unicode/with.yue"
	"spec/inputs/unicode/export.yue"
	"spec/inputs/unicode/macro_todo.yue"
	"spec/inputs/unicode/backcall.yue"
	"spec/inputs/unicode/cond.yue"
	"spec/inputs/unicode/in_expression.yue"
	"spec/inputs/unicode/comprehension.yue"
	"spec/inputs/unicode/import.yue"
	"spec/inputs/unicode/unless_else.yue"
	"spec/inputs/unicode/destructure.yue"
	"spec/inputs/unicode/return.yue"
	"spec/inputs/unicode/loops.yue"
	"spec/inputs/unicode/class.yue"
	"spec/inputs/unicode/vararg.yue"
	"spec/inputs/unicode/goto.yue"
	"spec/inputs/unicode/metatable.yue"
	"spec/inputs/unicode/syntax.yue"
	"spec/inputs/unicode/global.yue"
	"spec/inputs/unicode/plus.yue"
	"spec/inputs/pipe_chain_combo.yue"
	"spec/inputs/destructure_defaults.yue"
	"spec/inputs/nil_coalesce_precedence.yue"
	"spec/inputs/comprehension_nested.yue"
	"spec/inputs/with_scope_shadow.yue"
	"spec/inputs/export_mixed.yue"
	"spec/inputs/unicode/pipe_chain_combo.yue"
	"spec/inputs/test/destructure_spec.yue"
	"spec/inputs/test/nil_coalescing_spec.yue"
	"spec/inputs/test/pipe_spec.yue"
	"spec/inputs/test/try_catch_spec.yue"
	"spec/inputs/test/comprehension_spec.yue"
]

import "yue"

rewriteLineCol = (item)->
	item[2] = 0
	item[3] = 0
	for i = 4, #item
		switch type item[i] when "table"
			if item[i][1] == "comment"
				table.remove item, i
				rewriteLineCol item
				return
			rewriteLineCol item[i]

<- describe "format"
for file in *files
	<- it file
	f = io.open file
	code = f\read "a*"
	f\close!

	original_ast = yue.to_ast code
	assert.is_not_nil original_ast
	rewriteLineCol original_ast
	formated = yue.format code, 0, false
	ast = yue.to_ast formated
	assert.is_not_nil ast
	rewriteLineCol ast
	assert.same original_ast, ast