all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/verilog/test.js (view raw)

  1// CodeMirror, copyright (c) by Marijn Haverbeke and others
  2// Distributed under an MIT license: https://codemirror.net/LICENSE
  3
  4(function() {
  5  var mode = CodeMirror.getMode({indentUnit: 4}, "verilog");
  6  function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  7
  8  MT("binary_literals",
  9     "[number 1'b0]",
 10     "[number 1'b1]",
 11     "[number 1'bx]",
 12     "[number 1'bz]",
 13     "[number 1'bX]",
 14     "[number 1'bZ]",
 15     "[number 1'B0]",
 16     "[number 1'B1]",
 17     "[number 1'Bx]",
 18     "[number 1'Bz]",
 19     "[number 1'BX]",
 20     "[number 1'BZ]",
 21     "[number 1'b0]",
 22     "[number 1'b1]",
 23     "[number 2'b01]",
 24     "[number 2'bxz]",
 25     "[number 2'b11]",
 26     "[number 2'b10]",
 27     "[number 2'b1Z]",
 28     "[number 12'b0101_0101_0101]",
 29     "[number 1'b 0]",
 30     "[number 'b0101]"
 31  );
 32
 33  MT("octal_literals",
 34     "[number 3'o7]",
 35     "[number 3'O7]",
 36     "[number 3'so7]",
 37     "[number 3'SO7]"
 38  );
 39
 40  MT("decimal_literals",
 41     "[number 0]",
 42     "[number 1]",
 43     "[number 7]",
 44     "[number 123_456]",
 45     "[number 'd33]",
 46     "[number 8'd255]",
 47     "[number 8'D255]",
 48     "[number 8'sd255]",
 49     "[number 8'SD255]",
 50     "[number 32'd123]",
 51     "[number 32 'd123]",
 52     "[number 32 'd 123]"
 53  );
 54
 55  MT("hex_literals",
 56     "[number 4'h0]",
 57     "[number 4'ha]",
 58     "[number 4'hF]",
 59     "[number 4'hx]",
 60     "[number 4'hz]",
 61     "[number 4'hX]",
 62     "[number 4'hZ]",
 63     "[number 32'hdc78]",
 64     "[number 32'hDC78]",
 65     "[number 32 'hDC78]",
 66     "[number 32'h DC78]",
 67     "[number 32 'h DC78]",
 68     "[number 32'h44x7]",
 69     "[number 32'hFFF?]"
 70  );
 71
 72  MT("real_number_literals",
 73     "[number 1.2]",
 74     "[number 0.1]",
 75     "[number 2394.26331]",
 76     "[number 1.2E12]",
 77     "[number 1.2e12]",
 78     "[number 1.30e-2]",
 79     "[number 0.1e-0]",
 80     "[number 23E10]",
 81     "[number 29E-2]",
 82     "[number 236.123_763_e-12]"
 83  );
 84
 85  MT("operators",
 86     "[meta ^]"
 87  );
 88
 89  MT("keywords",
 90     "[keyword logic]",
 91     "[keyword logic] [variable foo]",
 92     "[keyword reg] [variable abc]"
 93  );
 94
 95  MT("variables",
 96     "[variable _leading_underscore]",
 97     "[variable _if]",
 98     "[number 12] [variable foo]",
 99     "[variable foo] [number 14]"
100  );
101
102  MT("tick_defines",
103     "[def `FOO]",
104     "[def `foo]",
105     "[def `FOO_bar]"
106  );
107
108  MT("system_calls",
109     "[meta $display]",
110     "[meta $vpi_printf]"
111  );
112
113  MT("line_comment", "[comment // Hello world]");
114
115  // Alignment tests
116  MT("align_port_map_style1",
117     /**
118      * mod mod(.a(a),
119      *         .b(b)
120      *        );
121      */
122     "[variable mod] [variable mod][bracket (].[variable a][bracket (][variable a][bracket )],",
123     "        .[variable b][bracket (][variable b][bracket )]",
124     "       [bracket )];",
125     ""
126  );
127
128  MT("align_port_map_style2",
129     /**
130      * mod mod(
131      *     .a(a),
132      *     .b(b)
133      * );
134      */
135     "[variable mod] [variable mod][bracket (]",
136     "    .[variable a][bracket (][variable a][bracket )],",
137     "    .[variable b][bracket (][variable b][bracket )]",
138     "[bracket )];",
139     ""
140  );
141
142  // Indentation tests
143  MT("indent_single_statement_if",
144      "[keyword if] [bracket (][variable foo][bracket )]",
145      "    [keyword break];",
146      ""
147  );
148
149  MT("no_indent_after_single_line_if",
150      "[keyword if] [bracket (][variable foo][bracket )] [keyword break];",
151      ""
152  );
153
154  MT("indent_after_if_begin_same_line",
155      "[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
156      "    [keyword break];",
157      "    [keyword break];",
158      "[keyword end]",
159      ""
160  );
161
162  MT("indent_after_if_begin_next_line",
163      "[keyword if] [bracket (][variable foo][bracket )]",
164      "    [keyword begin]",
165      "        [keyword break];",
166      "        [keyword break];",
167      "    [keyword end]",
168      ""
169  );
170
171  MT("indent_single_statement_if_else",
172      "[keyword if] [bracket (][variable foo][bracket )]",
173      "    [keyword break];",
174      "[keyword else]",
175      "    [keyword break];",
176      ""
177  );
178
179  MT("indent_if_else_begin_same_line",
180      "[keyword if] [bracket (][variable foo][bracket )] [keyword begin]",
181      "    [keyword break];",
182      "    [keyword break];",
183      "[keyword end] [keyword else] [keyword begin]",
184      "    [keyword break];",
185      "    [keyword break];",
186      "[keyword end]",
187      ""
188  );
189
190  MT("indent_if_else_begin_next_line",
191      "[keyword if] [bracket (][variable foo][bracket )]",
192      "    [keyword begin]",
193      "        [keyword break];",
194      "        [keyword break];",
195      "    [keyword end]",
196      "[keyword else]",
197      "    [keyword begin]",
198      "        [keyword break];",
199      "        [keyword break];",
200      "    [keyword end]",
201      ""
202  );
203
204  MT("indent_if_nested_without_begin",
205      "[keyword if] [bracket (][variable foo][bracket )]",
206      "    [keyword if] [bracket (][variable foo][bracket )]",
207      "        [keyword if] [bracket (][variable foo][bracket )]",
208      "            [keyword break];",
209      ""
210  );
211
212  MT("indent_case",
213      "[keyword case] [bracket (][variable state][bracket )]",
214      "    [variable FOO]:",
215      "        [keyword break];",
216      "    [variable BAR]:",
217      "        [keyword break];",
218      "[keyword endcase]",
219      ""
220  );
221
222  MT("unindent_after_end_with_preceding_text",
223      "[keyword begin]",
224      "    [keyword break]; [keyword end]",
225      ""
226  );
227
228  MT("export_function_one_line_does_not_indent",
229     "[keyword export] [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
230     ""
231  );
232
233  MT("export_task_one_line_does_not_indent",
234     "[keyword export] [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
235     ""
236  );
237
238  MT("export_function_two_lines_indents_properly",
239    "[keyword export]",
240    "    [string \"DPI-C\"] [keyword function] [variable helloFromSV];",
241    ""
242  );
243
244  MT("export_task_two_lines_indents_properly",
245    "[keyword export]",
246    "    [string \"DPI-C\"] [keyword task] [variable helloFromSV];",
247    ""
248  );
249
250  MT("import_function_one_line_does_not_indent",
251    "[keyword import] [string \"DPI-C\"] [keyword function] [variable helloFromC];",
252    ""
253  );
254
255  MT("import_task_one_line_does_not_indent",
256    "[keyword import] [string \"DPI-C\"] [keyword task] [variable helloFromC];",
257    ""
258  );
259
260  MT("import_package_single_line_does_not_indent",
261    "[keyword import] [variable p]::[variable x];",
262    "[keyword import] [variable p]::[variable y];",
263    ""
264  );
265
266  MT("covergroup_with_function_indents_properly",
267    "[keyword covergroup] [variable cg] [keyword with] [keyword function] [variable sample][bracket (][keyword bit] [variable b][bracket )];",
268    "    [variable c] : [keyword coverpoint] [variable c];",
269    "[keyword endgroup]: [variable cg]",
270    ""
271  );
272
273})();