test.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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) {
  6. test.mode(name, mode, Array.prototype.slice.call(arguments, 1))
  7. }
  8. MT(
  9. 'indent',
  10. '[type void] [def foo]([type void*] [variable a], [type int] [variable b]) {',
  11. ' [type int] [variable c] [operator =] [variable b] [operator +]',
  12. ' [number 1];',
  13. ' [keyword return] [operator *][variable a];',
  14. '}'
  15. )
  16. MT(
  17. 'indent_switch',
  18. '[keyword switch] ([variable x]) {',
  19. ' [keyword case] [number 10]:',
  20. ' [keyword return] [number 20];',
  21. ' [keyword default]:',
  22. ' [variable printf]([string "foo %c"], [variable x]);',
  23. '}'
  24. )
  25. MT('def', '[type void] [def foo]() {}', '[keyword struct] [def bar]{}', '[keyword enum] [def zot]{}', '[keyword union] [def ugh]{}', '[type int] [type *][def baz]() {}')
  26. MT(
  27. 'def_new_line',
  28. '::[variable std]::[variable SomeTerribleType][operator <][variable T][operator >]',
  29. '[def SomeLongMethodNameThatDoesntFitIntoOneLine]([keyword const] [variable MyType][operator &] [variable param]) {}'
  30. )
  31. MT('double_block', '[keyword for] (;;)', ' [keyword for] (;;)', ' [variable x][operator ++];', '[keyword return];')
  32. MT(
  33. 'preprocessor',
  34. '[meta #define FOO 3]',
  35. '[type int] [variable foo];',
  36. '[meta #define BAR\\]',
  37. '[meta 4]',
  38. '[type unsigned] [type int] [variable bar] [operator =] [number 8];',
  39. '[meta #include <baz> ][comment // comment]'
  40. )
  41. MT('c_underscores', '[builtin __FOO];', '[builtin _Complex];', '[builtin __aName];', '[variable _aName];')
  42. MT(
  43. 'c_types',
  44. '[type int];',
  45. '[type long];',
  46. '[type char];',
  47. '[type short];',
  48. '[type double];',
  49. '[type float];',
  50. '[type unsigned];',
  51. '[type signed];',
  52. '[type void];',
  53. '[type bool];',
  54. '[type foo_t];',
  55. '[variable foo_T];',
  56. '[variable _t];'
  57. )
  58. var mode_cpp = CodeMirror.getMode({ indentUnit: 2 }, 'text/x-c++src')
  59. function MTCPP(name) {
  60. test.mode(name, mode_cpp, Array.prototype.slice.call(arguments, 1))
  61. }
  62. MTCPP('cpp14_literal', "[number 10'000];", "[number 0b10'000];", "[number 0x10'000];", "[string '100000'];")
  63. MTCPP('ctor_dtor', '[def Foo::Foo]() {}', '[def Foo::~Foo]() {}')
  64. MTCPP('cpp_underscores', '[builtin __FOO];', '[builtin _Complex];', '[builtin __aName];', '[variable _aName];')
  65. var mode_objc = CodeMirror.getMode({ indentUnit: 2 }, 'text/x-objectivec')
  66. function MTOBJC(name) {
  67. test.mode(name, mode_objc, Array.prototype.slice.call(arguments, 1))
  68. }
  69. MTOBJC('objc_underscores', '[builtin __FOO];', '[builtin _Complex];', '[builtin __aName];', '[variable _aName];')
  70. MTOBJC(
  71. 'objc_interface',
  72. '[keyword @interface] [def foo] {',
  73. ' [type int] [variable bar];',
  74. '}',
  75. '[keyword @property] ([keyword atomic], [keyword nullable]) [variable NSString][operator *] [variable a];',
  76. '[keyword @property] ([keyword nonatomic], [keyword assign]) [type int] [variable b];',
  77. '[operator -]([type instancetype])[variable initWithFoo]:([type int])[variable a] ' + '[builtin NS_DESIGNATED_INITIALIZER];',
  78. '[keyword @end]'
  79. )
  80. MTOBJC(
  81. 'objc_implementation',
  82. '[keyword @implementation] [def foo] {',
  83. ' [type int] [variable bar];',
  84. '}',
  85. '[keyword @property] ([keyword readwrite]) [type SEL] [variable a];',
  86. '[operator -]([type instancetype])[variable initWithFoo]:([type int])[variable a] {',
  87. ' [keyword if](([keyword self] [operator =] [[[keyword super] [variable init] ]])) {}',
  88. ' [keyword return] [keyword self];',
  89. '}',
  90. '[keyword @end]'
  91. )
  92. MTOBJC('objc_types', '[type int];', '[type foo_t];', '[variable foo_T];', '[type id];', '[type SEL];', '[type instancetype];', '[type Class];', '[type Protocol];', '[type BOOL];')
  93. var mode_scala = CodeMirror.getMode({ indentUnit: 2 }, 'text/x-scala')
  94. function MTSCALA(name) {
  95. test.mode('scala_' + name, mode_scala, Array.prototype.slice.call(arguments, 1))
  96. }
  97. MTSCALA(
  98. 'nested_comments',
  99. '[comment /*]',
  100. '[comment But wait /* this is a nested comment */ for real]',
  101. '[comment /**** let * me * show * you ****/]',
  102. '[comment ///// let / me / show / you /////]',
  103. '[comment */]'
  104. )
  105. var mode_java = CodeMirror.getMode({ indentUnit: 2 }, 'text/x-java')
  106. function MTJAVA(name) {
  107. test.mode('java_' + name, mode_java, Array.prototype.slice.call(arguments, 1))
  108. }
  109. MTJAVA(
  110. 'types',
  111. '[type byte];',
  112. '[type short];',
  113. '[type int];',
  114. '[type long];',
  115. '[type float];',
  116. '[type double];',
  117. '[type boolean];',
  118. '[type char];',
  119. '[type void];',
  120. '[type Boolean];',
  121. '[type Byte];',
  122. '[type Character];',
  123. '[type Double];',
  124. '[type Float];',
  125. '[type Integer];',
  126. '[type Long];',
  127. '[type Number];',
  128. '[type Object];',
  129. '[type Short];',
  130. '[type String];',
  131. '[type StringBuffer];',
  132. '[type StringBuilder];',
  133. '[type Void];'
  134. )
  135. })()