test.js
6.62 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function() {
var mode = CodeMirror.getMode({indentUnit: 4}, "verilog");
function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
MT("binary_literals",
"[number 1'b0]",
"[number 1'b1]",
"[number 1'bx]",
"[number 1'bz]",
"[number 1'bX]",
"[number 1'bZ]",
"[number 1'B0]",
"[number 1'B1]",
"[number 1'Bx]",
"[number 1'Bz]",
"[number 1'BX]",
"[number 1'BZ]",
"[number 1'b0]",
"[number 1'b1]",
"[number 2'b01]",
"[number 2'bxz]",
"[number 2'b11]",
"[number 2'b10]",
"[number 2'b1Z]",
"[number 12'b0101_0101_0101]",
"[number 1'b 0]",
"[number 'b0101]"
);
MT("octal_literals",
"[number 3'o7]",
"[number 3'O7]",
"[number 3'so7]",
"[number 3'SO7]"
);
MT("decimal_literals",
"[number 0]",
"[number 1]",
"[number 7]",
"[number 123_456]",
"[number 'd33]",
"[number 8'd255]",
"[number 8'D255]",
"[number 8'sd255]",
"[number 8'SD255]",
"[number 32'd123]",
"[number 32 'd123]",
"[number 32 'd 123]"
);
MT("hex_literals",
"[number 4'h0]",
"[number 4'ha]",
"[number 4'hF]",
"[number 4'hx]",
"[number 4'hz]",
"[number 4'hX]",
"[number 4'hZ]",
"[number 32'hdc78]",
"[number 32'hDC78]",
"[number 32 'hDC78]",
"[number 32'h DC78]",
"[number 32 'h DC78]",
"[number 32'h44x7]",
"[number 32'hFFF?]"
);
MT("real_number_literals",
"[number 1.2]",
"[number 0.1]",
"[number 2394.26331]",
"[number 1.2E12]",
"[number 1.2e12]",
"[number 1.30e-2]",
"[number 0.1e-0]",
"[number 23E10]",
"[number 29E-2]",
"[number 236.123_763_e-12]"
);
MT("operators",
"[meta ^]"
);
MT("keywords",
"[keyword logic]",
"[keyword logic] [variable foo]",
"[keyword reg] [variable abc]"
);
MT("variables",
"[variable _leading_underscore]",
"[variable _if]",
"[number 12] [variable foo]",
"[variable foo] [number 14]"
);
MT("tick_defines",
"[def `FOO]",
"[def `foo]",
"[def `FOO_bar]"
);
MT("system_calls",
"[meta $display]",
"[meta $vpi_printf]"
);
MT("line_comment", "[comment // Hello world]");
// Alignment tests
MT("align_port_map_style1",
/**
* mod mod(.a(a),
* .b(b)
* );
*/
"[variable mod] [variable mod][bracket (].[variable a][bracket (][variable a][bracket )],",
" .[variable b][bracket (][variable b][bracket )]",
" [bracket )];",
""
);
MT("align_port_map_style2",
/**
* mod mod(
* .a(a),
* .b(b)
* );
*/
"[variable mod] [variable mod][bracket (]",
" .[variable a][bracket (][variable a][bracket )],",
" .[variable b][bracket (][variable b][bracket )]",
"[bracket )];",
""
);
// Indentation tests
MT("indent_single_statement_if",
"[keyword if] [bracket (][variable foo][bracket )]",
" [keyword break];",
""
);
MT("no_indent_after_single_line_if",
"[keyword if] [bracket (][variable foo][bracket )] [keyword break];",
""
);
MT("indent_after_if_begin_same_line",
"[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
" [keyword break];",
" [keyword break];",
"[keyword end]",
""
);
MT("indent_after_if_begin_next_line",
"[keyword if] [bracket (][variable foo][bracket )]",
" [keyword begin]",
" [keyword break];",
" [keyword break];",
" [keyword end]",
""
);
MT("indent_single_statement_if_else",
"[keyword if] [bracket (][variable foo][bracket )]",
" [keyword break];",
"[keyword else]",
" [keyword break];",
""
);
MT("indent_if_else_begin_same_line",
"[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
" [keyword break];",
" [keyword break];",
"[keyword end] [keyword else] [keyword begin]",
" [keyword break];",
" [keyword break];",
"[keyword end]",
""
);
MT("indent_if_else_begin_next_line",
"[keyword if] [bracket (][variable foo][bracket )]",
" [keyword begin]",
" [keyword break];",
" [keyword break];",
" [keyword end]",
"[keyword else]",
" [keyword begin]",
" [keyword break];",
" [keyword break];",
" [keyword end]",
""
);
MT("indent_if_nested_without_begin",
"[keyword if] [bracket (][variable foo][bracket )]",
" [keyword if] [bracket (][variable foo][bracket )]",
" [keyword if] [bracket (][variable foo][bracket )]",
" [keyword break];",
""
);
MT("indent_case",
"[keyword case] [bracket (][variable state][bracket )]",
" [variable FOO]:",
" [keyword break];",
" [variable BAR]:",
" [keyword break];",
"[keyword endcase]",
""
);
MT("unindent_after_end_with_preceding_text",
"[keyword begin]",
" [keyword break]; [keyword end]",
""
);
MT("export_function_one_line_does_not_indent",
"[keyword export] [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
""
);
MT("export_task_one_line_does_not_indent",
"[keyword export] [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
""
);
MT("export_function_two_lines_indents_properly",
"[keyword export]",
" [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
""
);
MT("export_task_two_lines_indents_properly",
"[keyword export]",
" [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
""
);
MT("import_function_one_line_does_not_indent",
"[keyword import] [string \"DPI-C\"] [keyword function] [variable helloFromC];",
""
);
MT("import_task_one_line_does_not_indent",
"[keyword import] [string \"DPI-C\"] [keyword task] [variable helloFromC];",
""
);
MT("import_package_single_line_does_not_indent",
"[keyword import] [variable p]::[variable x];",
"[keyword import] [variable p]::[variable y];",
""
);
MT("covergoup_with_function_indents_properly",
"[keyword covergroup] [variable cg] [keyword with] [keyword function] [variable sample][bracket (][keyword bit] [variable b][bracket )];",
" [variable c] : [keyword coverpoint] [variable c];",
"[keyword endgroup]: [variable cg]",
""
);
})();