test.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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: 2}, "text/x-c");
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  6. MT("indent",
  7. "[type void] [def foo]([type void*] [variable a], [type int] [variable b]) {",
  8. " [type int] [variable c] [operator =] [variable b] [operator +]",
  9. " [number 1];",
  10. " [keyword return] [operator *][variable a];",
  11. "}");
  12. MT("indent_switch",
  13. "[keyword switch] ([variable x]) {",
  14. " [keyword case] [number 10]:",
  15. " [keyword return] [number 20];",
  16. " [keyword default]:",
  17. " [variable printf]([string \"foo %c\"], [variable x]);",
  18. "}");
  19. MT("def",
  20. "[type void] [def foo]() {}",
  21. "[keyword struct] [def bar]{}",
  22. "[type int] [type *][def baz]() {}");
  23. MT("def_new_line",
  24. "::[variable std]::[variable SomeTerribleType][operator <][variable T][operator >]",
  25. "[def SomeLongMethodNameThatDoesntFitIntoOneLine]([keyword const] [variable MyType][operator &] [variable param]) {}")
  26. MT("double_block",
  27. "[keyword for] (;;)",
  28. " [keyword for] (;;)",
  29. " [variable x][operator ++];",
  30. "[keyword return];");
  31. MT("preprocessor",
  32. "[meta #define FOO 3]",
  33. "[type int] [variable foo];",
  34. "[meta #define BAR\\]",
  35. "[meta 4]",
  36. "[type unsigned] [type int] [variable bar] [operator =] [number 8];",
  37. "[meta #include <baz> ][comment // comment]")
  38. var mode_cpp = CodeMirror.getMode({indentUnit: 2}, "text/x-c++src");
  39. function MTCPP(name) { test.mode(name, mode_cpp, Array.prototype.slice.call(arguments, 1)); }
  40. MTCPP("cpp14_literal",
  41. "[number 10'000];",
  42. "[number 0b10'000];",
  43. "[number 0x10'000];",
  44. "[string '100000'];");
  45. MTCPP("ctor_dtor",
  46. "[def Foo::Foo]() {}",
  47. "[def Foo::~Foo]() {}");
  48. var mode_scala = CodeMirror.getMode({indentUnit: 2}, "text/x-scala");
  49. function MTSCALA(name) { test.mode("scala_" + name, mode_scala, Array.prototype.slice.call(arguments, 1)); }
  50. MTSCALA("nested_comments",
  51. "[comment /*]",
  52. "[comment But wait /* this is a nested comment */ for real]",
  53. "[comment /**** let * me * show * you ****/]",
  54. "[comment ///// let / me / show / you /////]",
  55. "[comment */]");
  56. })();