aboutsummaryrefslogtreecommitdiff
path: root/spec/inputs/test/format_spec.yue
blob: 4da3f7e5fa866870b5836112416c6937cbec0691 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
files = [
	"spec/inputs/import_global.yue"
	"spec/inputs/nil_coalesce_precedence.yue"
	"spec/inputs/macro_export.yue"
	"spec/inputs/props.yue"
	"spec/inputs/attrib.yue"
	"spec/inputs/upvalue_func.yue"
	"spec/inputs/macro.yue"
	"spec/inputs/export_mixed.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/pipe_chain_combo.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/with_scope_shadow.yue"
	"spec/inputs/assign.yue"
	"spec/inputs/literals.yue"
	"spec/inputs/luarocks_upload.yue"
	"spec/inputs/comprehension_nested.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/destructure_defaults.yue"
	"spec/inputs/goto.yue"
	"spec/inputs/metatable.yue"
	"spec/inputs/syntax.yue"
	"spec/inputs/global.yue"
	"spec/inputs/plus.yue"
	"spec/inputs/test/with_spec.yue"
	"spec/inputs/test/try_catch_spec.yue"
	"spec/inputs/test/operator_advanced_spec.yue"
	"spec/inputs/test/with_statement_spec.yue"
	"spec/inputs/test/literals_spec.yue"
	"spec/inputs/test/varargs_assignment_spec.yue"
	"spec/inputs/test/advanced_macro_spec.yue"
	"spec/inputs/test/pipe_spec.yue"
	"spec/inputs/test/export_spec.yue"
	"spec/inputs/test/existential_spec.yue"
	"spec/inputs/test/metatable_spec.yue"
	"spec/inputs/test/multiline_args_spec.yue"
	"spec/inputs/test/format_spec.yue"
	"spec/inputs/test/do_statement_spec.yue"
	"spec/inputs/test/class_spec.yue"
	"spec/inputs/test/stub_spec.yue"
	"spec/inputs/test/whitespace_spec.yue"
	"spec/inputs/test/in_expression_spec.yue"
	"spec/inputs/test/param_destructure_spec.yue"
	"spec/inputs/test/operators_spec.yue"
	"spec/inputs/test/comprehension_spec.yue"
	"spec/inputs/test/attrib_spec.yue"
	"spec/inputs/test/nil_coalescing_spec.yue"
	"spec/inputs/test/table_comprehension_spec.yue"
	"spec/inputs/test/slicing_spec.yue"
	"spec/inputs/test/close_attribute_spec.yue"
	"spec/inputs/test/named_varargs_spec.yue"
	"spec/inputs/test/table_spreading_spec.yue"
	"spec/inputs/test/macro_spec.yue"
	"spec/inputs/test/chaining_comparison_spec.yue"
	"spec/inputs/test/table_append_spec.yue"
	"spec/inputs/test/destructure_spec.yue"
	"spec/inputs/test/vararg_spec.yue"
	"spec/inputs/test/string_spec.yue"
	"spec/inputs/test/implicit_object_spec.yue"
	"spec/inputs/test/backcall_spec.yue"
	"spec/inputs/test/while_assignment_spec.yue"
	"spec/inputs/test/switch_spec.yue"
	"spec/inputs/test/functions_advanced_spec.yue"
	"spec/inputs/test/config_spec.yue"
	"spec/inputs/test/yaml_string_spec.yue"
	"spec/inputs/test/const_attribute_spec.yue"
	"spec/inputs/test/cond_spec.yue"
	"spec/inputs/test/import_spec.yue"
	"spec/inputs/test/reverse_index_spec.yue"
	"spec/inputs/test/prefixed_return_spec.yue"
	"spec/inputs/test/goto_spec.yue"
	"spec/inputs/test/return_spec.yue"
	"spec/inputs/test/loops_spec.yue"
	"spec/inputs/test/if_assignment_spec.yue"
	"spec/inputs/test/tables_advanced_spec.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/pipe_chain_combo.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"
]

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