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