all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/soy/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}, "soy");
  6  function MT(name) {test.mode(name, mode, Array.prototype.slice.call(arguments, 1));}
  7
  8  // Test of small keywords and words containing them.
  9  MT('keywords-test',
 10     '[keyword {] [keyword as] worrying [keyword and] notorious [keyword as]',
 11     '    the Fandor[operator -]alias assassin, [keyword or]',
 12     '    Corcand cannot fit [keyword in] [keyword }]');
 13
 14  MT('let-test',
 15     '[keyword {template] [def .name][keyword }]',
 16     '  [keyword {let] [def $name]: [string "world"][keyword /}]',
 17     '  [tag&bracket <][tag h1][tag&bracket >]',
 18     '    Hello, [keyword {][variable-2 $name][keyword }]',
 19     '  [tag&bracket </][tag h1][tag&bracket >]',
 20     '[keyword {/template}]',
 21     '');
 22
 23  MT('function-test',
 24     '[keyword {] [callee&variable css]([string "MyClass"])[keyword }]',
 25     '[tag&bracket <][tag input] [attribute value]=[string "]' +
 26     '[keyword {] [callee&variable index]([variable-2&error $list])[keyword }]' +
 27        '[string "][tag&bracket />]');
 28
 29  MT('namespace-test',
 30     '[keyword {namespace] [variable namespace][keyword }]')
 31
 32  MT('namespace-with-attribute-test',
 33     '[keyword {namespace] [variable my.namespace.templates] ' +
 34         '[attribute requirecss]=[string "my.namespace"][keyword }]');
 35
 36  MT('operators-test',
 37     '[keyword {] [atom 1] [operator ==] [atom 1] [keyword }]',
 38     '[keyword {] [atom 1] [operator !=] [atom 2] [keyword }]',
 39     '[keyword {] [atom 2] [operator +] [atom 2] [keyword }]',
 40     '[keyword {] [atom 2] [operator -] [atom 2] [keyword }]',
 41     '[keyword {] [atom 2] [operator *] [atom 2] [keyword }]',
 42     '[keyword {] [atom 2] [operator /] [atom 2] [keyword }]',
 43     '[keyword {] [atom 2] [operator %] [atom 2] [keyword }]',
 44     '[keyword {] [atom 2] [operator <=] [atom 2] [keyword }]',
 45     '[keyword {] [atom 2] [operator >=] [atom 2] [keyword }]',
 46     '[keyword {] [atom 3] [operator >] [atom 2] [keyword }]',
 47     '[keyword {] [atom 2] [operator >] [atom 3] [keyword }]',
 48     '[keyword {] [atom null] [operator ?:] [string ""] [keyword }]',
 49     '[keyword {] [variable-2&error $variable] [operator |] safeHtml [keyword }]')
 50
 51  MT('primitive-test',
 52     '[keyword {] [atom true] [keyword }]',
 53     '[keyword {] [atom false] [keyword }]',
 54     '[keyword {] truethy [keyword }]',
 55     '[keyword {] falsey [keyword }]',
 56     '[keyword {] [atom 42] [keyword }]',
 57     '[keyword {] [atom .42] [keyword }]',
 58     '[keyword {] [atom 0.42] [keyword }]',
 59     '[keyword {] [atom -0.42] [keyword }]',
 60     '[keyword {] [atom -.2] [keyword }]',
 61     '[keyword {] [atom 6.03e23] [keyword }]',
 62     '[keyword {] [atom -0.03e0] [keyword }]',
 63     '[keyword {] [atom 0x1F] [keyword }]',
 64     '[keyword {] [atom 0x1F00BBEA] [keyword }]');
 65
 66  MT('param-type-record',
 67     '[keyword {@param] [def record]: [[[property foo]: [type bool], [property bar]: [type int] ]][keyword }]'
 68  );
 69
 70  MT('param-type-map',
 71     '[keyword {@param] [def unknown]: [type map]<[type string], [type bool]>[keyword }]'
 72  );
 73
 74  MT('param-type-list',
 75     '[keyword {@param] [def list]: [type list]<[type ?]>[keyword }]'
 76  );
 77
 78  MT('param-type-any',
 79     '[keyword {@param] [def unknown]: [type ?][keyword }]'
 80  );
 81
 82  MT('param-type-nested',
 83     '[keyword {@param] [def a]: ' +
 84         '[type list]<[[[property a]: [type int], ' +
 85         '[property b]: [type map]<[type string], ' +
 86         '[type bool]>]]>][keyword }]');
 87
 88  MT('undefined-var',
 89     '[keyword {][variable-2&error $var]');
 90
 91  MT('param-scope-test',
 92     '[keyword {template] [def .a][keyword }]',
 93     '  [keyword {@param] [def x]: [type string][keyword }]',
 94     '  [keyword {][variable-2 $x][keyword }]',
 95     '[keyword {/template}]',
 96     '',
 97     '[keyword {template] [def .b][keyword }]',
 98     '  [keyword {][variable-2&error $x][keyword }]',
 99     '[keyword {/template}]',
100     '');
101
102  MT('if-variable-test',
103     '[keyword {if] [variable-2&error $showThing][keyword }]',
104     '  Yo!',
105     '[keyword {/if}]',
106     '');
107
108  MT('defined-if-variable-test',
109     '[keyword {template] [def .foo][keyword }]',
110     '  [keyword {@param?] [def showThing]: [type bool][keyword }]',
111     '  [keyword {if] [variable-2 $showThing][keyword }]',
112     '    Yo!',
113     '  [keyword {/if}]',
114     '[keyword {/template}]',
115     '');
116
117  MT('template-calls-test',
118     '[keyword {call] [variable-2 .foo][keyword /}]',
119     '[keyword {call] [variable foo][keyword /}]',
120     '[keyword {call] [variable foo][keyword }] [keyword {/call}]',
121     '[keyword {call] [variable first1.second.third_3][keyword /}]',
122     '[keyword {call] [variable first1.second.third_3] [keyword }] [keyword {/call}]',
123     '');
124
125  MT('foreach-scope-test',
126     '[keyword {@param] [def bar]: [type string][keyword }]',
127     '[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
128     '  [keyword {][variable-2 $foo][keyword }]',
129     '[keyword {/foreach}]',
130     '[keyword {][variable-2&error $foo][keyword }]',
131     '[keyword {][variable-2 $bar][keyword }]');
132
133  MT('foreach-ifempty-indent-test',
134     '[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
135     '  something',
136     '[keyword {ifempty}]',
137     '  nothing',
138     '[keyword {/foreach}]',
139     '');
140
141   MT('foreach-index',
142      '[keyword {foreach] [def $foo],[def $index] [keyword in] [[]] [keyword }]',
143      '  [keyword {][variable-2 $foo][keyword }] [keyword {][variable-2 $index][keyword }]',
144      '[keyword {/foreach}]');
145
146  MT('nested-kind-test',
147     '[keyword {template] [def .foo] [attribute kind]=[string "html"][keyword }]',
148     '  [tag&bracket <][tag div][tag&bracket >]',
149     '    [keyword {call] [variable-2 .bar][keyword }]',
150     '      [keyword {param] [property propertyName] [attribute kind]=[string "js"][keyword }]',
151     '        [keyword var] [def bar] [operator =] [number 5];',
152     '      [keyword {/param}]',
153     '    [keyword {/call}]',
154     '  [tag&bracket </][tag div][tag&bracket >]',
155     '[keyword {/template}]',
156     '');
157
158  MT('tag-starting-with-function-call-is-not-a-keyword',
159     '[keyword {][callee&variable index]([variable-2&error $foo])[keyword }]',
160     '[keyword {css] [string "some-class"][keyword }]',
161     '[keyword {][callee&variable css]([string "some-class"])[keyword }]',
162     '');
163
164  MT('allow-missing-colon-in-@param',
165     '[keyword {template] [def .foo][keyword }]',
166     '  [keyword {@param] [def showThing] [type bool][keyword }]',
167     '  [keyword {if] [variable-2 $showThing][keyword }]',
168     '    Yo!',
169     '  [keyword {/if}]',
170     '[keyword {/template}]',
171     '');
172
173  MT('param-type-and-default-value',
174     '[keyword {template] [def .foo][keyword }]',
175     '  [keyword {@param] [def bar]: [type bool] = [atom true][keyword }]',
176     '[keyword {/template}]',
177     '');
178
179   MT('state-variable-reference',
180     '[keyword {template] [def .foo][keyword }]',
181     '  [keyword {@param] [def bar]:= [atom true][keyword }]',
182     '  [keyword {@state] [def foobar]:= [variable-2 $bar][keyword }]',
183     '[keyword {/template}]',
184     '');
185
186   MT('param-type-template',
187     '[keyword {template] [def .foo][keyword }]',
188     '  [keyword {@param] [def renderer]: ([def s]:[type string])=>[type html][keyword }]',
189     '  [keyword {call] [variable-2 $renderer] [keyword /}]',
190     '[keyword {/template}]',
191     '');
192
193  MT('single-quote-strings',
194     '[keyword {][string "foo"] [string \'bar\'][keyword }]',
195     '');
196
197  MT('literal-comments',
198     '[keyword {literal}]/* comment */ // comment[keyword {/literal}]');
199
200  MT('highlight-command-at-eol',
201     '[keyword {msg]',
202     '    [keyword }]');
203
204  MT('switch-indent-test',
205     '[keyword {let] [def $marbles]: [atom 5] [keyword /}]',
206     '[keyword {switch] [variable-2 $marbles][keyword }]',
207     '  [keyword {case] [atom 0][keyword }]',
208     '    No marbles',
209     '  [keyword {default}]',
210     '    At least 1 marble',
211     '[keyword {/switch}]',
212     '');
213
214  MT('if-elseif-else-indent',
215     '[keyword {if] [atom true][keyword }]',
216     '  [keyword {let] [def $a]: [atom 5] [keyword /}]',
217     '[keyword {elseif] [atom false][keyword }]',
218     '  [keyword {let] [def $bar]: [atom 5] [keyword /}]',
219     '[keyword {else}]',
220     '  [keyword {let] [def $bar]: [atom 5] [keyword /}]',
221     '[keyword {/if}]');
222
223  MT('msg-fallbackmsg-indent',
224     '[keyword {msg] [attribute desc]=[string "A message"][keyword }]',
225     '  A message',
226     '[keyword {fallbackmsg] [attribute desc]=[string "A message"][keyword }]',
227     '  Old message',
228     '[keyword {/msg}]');
229
230  MT('literal-indent',
231     '[keyword {template] [def .name][keyword }]',
232     '  [keyword {literal}]',
233     '    Lerum',
234     '  [keyword {/literal}]',
235     '  Ipsum',
236     '[keyword {/template}]');
237
238  MT('special-chars',
239     '[keyword {sp}]',
240     '[keyword {nil}]',
241     '[keyword {\\r}]',
242     '[keyword {\\n}]',
243     '[keyword {\\t}]',
244     '[keyword {lb}]',
245     '[keyword {rb}]');
246
247  MT('let-list-literal',
248     '[keyword {let] [def $test]: [[[[[string \'a\'] ], [[[string \'b\'] ] ] [keyword /}]');
249
250  MT('let-record-literal',
251     '[keyword {let] [def $test]: [keyword record]([property test]: [callee&variable bidiGlobalDir](), ' +
252         '[property foo]: [atom 5]) [keyword /}]');
253
254  MT('let-map-literal',
255     '[keyword {let] [def $test]: [keyword map]([string \'outer\']: [keyword map]([atom 5]: [atom false]), ' +
256         '[string \'foo\']: [string \'bar\']) [keyword /}]');
257
258  MT('wrong-closing-tag',
259     '[keyword {if] [atom true][keyword }]',
260     '  Optional',
261     '[keyword&error {/badend][keyword }]');
262
263  MT('list-comprehension',
264     '[keyword {let] [def $myList]: [[[[[string \'a\'] ] ] [keyword /}] ' +
265     '[keyword {let] [def $test]: [[[variable $a] [operator +] [atom 1] [keyword for] ' +
266         '[def $a] [keyword in] [variable-2 $myList] [keyword if] [variable-2 $a] [operator >=] [atom 3] ] [keyword /}]');
267
268  MT('list-comprehension-index',
269     '[keyword {let] [def $test]: [[[variable $a] [operator +] [variable $index] [keyword for] ' +
270         '[def $a],[def $index] [keyword in] [[]] [keyword if] [variable-2 $a] [operator >=] [variable-2 $index] ] [keyword /}]');
271
272
273  MT('list-comprehension-variable-scope',
274     '[keyword {let] [def $name]: [string "world"][keyword /}]',
275     '[keyword {let] [def $test]: [[[variable $a] [operator +] [variable $index] [keyword for] ' +
276         '[def $a],[def $index] [keyword in] [[]] [keyword if] [variable-2 $a] [operator >=] [variable-2 $index] ] [keyword /}]',
277     '[keyword {][variable-2&error $a][keyword }]',
278     '[keyword {][variable-2&error $index][keyword }]',
279     '[keyword {][variable-2 $test][keyword }]',
280     '[keyword {][variable-2 $name][keyword }]');
281
282  MT('import',
283   '[keyword import] {[def Name], [variable Person] [keyword as] [def P]} [keyword from] [string \'examples/proto/example.proto\'];');
284})();