openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

test.js (4101B)


      1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
      2 // Distributed under an MIT license: http://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-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('param-type-test',
     24      '[keyword {@param] [def a]: ' +
     25          '[variable-3 list]<[[[variable-3 a]: [variable-3 int], ' +
     26          '[variable-3 b]: [variable-3 map]<[variable-3 string], ' +
     27          '[variable-3 bool]>]]>][keyword }]');
     28 
     29   MT('undefined-var',
     30      '[keyword {][variable-2&error $var]');
     31 
     32   MT('param-scope-test',
     33      '[keyword {template] [def .a][keyword }]',
     34      '  [keyword {@param] [def x]: [variable-3 string][keyword }]',
     35      '  [keyword {][variable-2 $x][keyword }]',
     36      '[keyword {/template}]',
     37      '',
     38      '[keyword {template] [def .b][keyword }]',
     39      '  [keyword {][variable-2&error $x][keyword }]',
     40      '[keyword {/template}]',
     41      '');
     42 
     43   MT('if-variable-test',
     44      '[keyword {if] [variable-2&error $showThing][keyword }]',
     45      '  Yo!',
     46      '[keyword {/if}]',
     47      '');
     48 
     49   MT('defined-if-variable-test',
     50      '[keyword {template] [def .foo][keyword }]',
     51      '  [keyword {@param?] [def showThing]: [variable-3 bool][keyword }]',
     52      '  [keyword {if] [variable-2 $showThing][keyword }]',
     53      '    Yo!',
     54      '  [keyword {/if}]',
     55      '[keyword {/template}]',
     56      '');
     57 
     58   MT('template-calls-test',
     59      '[keyword {template] [def .foo][keyword }]',
     60      '  Yo!',
     61      '[keyword {/template}]',
     62      '[keyword {call] [variable-2 .foo][keyword /}]',
     63      '[keyword {call] [variable foo][keyword /}]',
     64      '[keyword {call] [variable .bar][keyword /}]',
     65      '[keyword {call] [variable bar][keyword /}]',
     66      '');
     67 
     68   MT('foreach-scope-test',
     69      '[keyword {@param] [def bar]: [variable-3 string][keyword }]',
     70      '[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
     71      '  [keyword {][variable-2 $foo][keyword }]',
     72      '[keyword {/foreach}]',
     73      '[keyword {][variable-2&error $foo][keyword }]',
     74      '[keyword {][variable-2 $bar][keyword }]');
     75 
     76   MT('foreach-ifempty-indent-test',
     77      '[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
     78      '  something',
     79      '[keyword {ifempty}]',
     80      '  nothing',
     81      '[keyword {/foreach}]',
     82      '');
     83 
     84   MT('nested-kind-test',
     85      '[keyword {template] [def .foo] [attribute kind]=[string "html"][keyword }]',
     86      '  [tag&bracket <][tag div][tag&bracket >]',
     87      '    [keyword {call] [variable .bar][keyword }]',
     88      '      [keyword {param] [attribute kind]=[string "js"][keyword }]',
     89      '        [keyword var] [def bar] [operator =] [number 5];',
     90      '      [keyword {/param}]',
     91      '    [keyword {/call}]',
     92      '  [tag&bracket </][tag div][tag&bracket >]',
     93      '[keyword {/template}]',
     94      '');
     95 
     96   MT('tag-starting-with-function-call-is-not-a-keyword',
     97      '[keyword {]index([variable-2&error $foo])[keyword }]',
     98      '[keyword {css] [string "some-class"][keyword }]',
     99      '[keyword {]css([string "some-class"])[keyword }]',
    100      '');
    101 
    102   MT('allow-missing-colon-in-@param',
    103      '[keyword {template] [def .foo][keyword }]',
    104      '  [keyword {@param] [def showThing] [variable-3 bool][keyword }]',
    105      '  [keyword {if] [variable-2 $showThing][keyword }]',
    106      '    Yo!',
    107      '  [keyword {/if}]',
    108      '[keyword {/template}]',
    109      '');
    110 
    111   MT('single-quote-strings',
    112      '[keyword {][string "foo"] [string \'bar\'][keyword }]',
    113      '');
    114 })();