test.js 6.6 KB

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