test.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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}, "soy");
  5. function MT(name) {test.mode(name, mode, Array.prototype.slice.call(arguments, 1));}
  6. // Test of small keywords and words containing them.
  7. MT('keywords-test',
  8. '[keyword {] [keyword as] worrying [keyword and] notorious [keyword as]',
  9. ' the Fandor-alias assassin, [keyword or]',
  10. ' Corcand cannot fit [keyword in] [keyword }]');
  11. MT('let-test',
  12. '[keyword {template] [def .name][keyword }]',
  13. ' [keyword {let] [def $name]: [string "world"][keyword /}]',
  14. ' [tag&bracket <][tag h1][tag&bracket >]',
  15. ' Hello, [keyword {][variable-2 $name][keyword }]',
  16. ' [tag&bracket </][tag h1][tag&bracket >]',
  17. '[keyword {/template}]',
  18. '');
  19. MT('param-type-test',
  20. '[keyword {@param] [def a]: ' +
  21. '[variable-3 list]<[[[variable-3 a]: [variable-3 int], ' +
  22. '[variable-3 b]: [variable-3 map]<[variable-3 string], ' +
  23. '[variable-3 bool]>]]>][keyword }]');
  24. MT('undefined-var',
  25. '[keyword {][variable-2&error $var]');
  26. MT('param-scope-test',
  27. '[keyword {template] [def .a][keyword }]',
  28. ' [keyword {@param] [def x]: [variable-3 string][keyword }]',
  29. ' [keyword {][variable-2 $x][keyword }]',
  30. '[keyword {/template}]',
  31. '',
  32. '[keyword {template] [def .b][keyword }]',
  33. ' [keyword {][variable-2&error $x][keyword }]',
  34. '[keyword {/template}]',
  35. '');
  36. MT('if-variable-test',
  37. '[keyword {if] [variable-2&error $showThing][keyword }]',
  38. ' Yo!',
  39. '[keyword {/if}]',
  40. '');
  41. MT('defined-if-variable-test',
  42. '[keyword {template] [def .foo][keyword }]',
  43. ' [keyword {@param?] [def showThing]: [variable-3 bool][keyword }]',
  44. ' [keyword {if] [variable-2 $showThing][keyword }]',
  45. ' Yo!',
  46. ' [keyword {/if}]',
  47. '[keyword {/template}]',
  48. '');
  49. MT('template-calls-test',
  50. '[keyword {template] [def .foo][keyword }]',
  51. ' Yo!',
  52. '[keyword {/template}]',
  53. '[keyword {call] [variable-2 .foo][keyword /}]',
  54. '[keyword {call] [variable foo][keyword /}]',
  55. '[keyword {call] [variable .bar][keyword /}]',
  56. '[keyword {call] [variable bar][keyword /}]',
  57. '');
  58. MT('foreach-scope-test',
  59. '[keyword {@param] [def bar]: [variable-3 string][keyword }]',
  60. '[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
  61. ' [keyword {][variable-2 $foo][keyword }]',
  62. '[keyword {/foreach}]',
  63. '[keyword {][variable-2&error $foo][keyword }]',
  64. '[keyword {][variable-2 $bar][keyword }]');
  65. MT('foreach-ifempty-indent-test',
  66. '[keyword {foreach] [def $foo] [keyword in] [variable-2&error $foos][keyword }]',
  67. ' something',
  68. '[keyword {ifempty}]',
  69. ' nothing',
  70. '[keyword {/foreach}]',
  71. '');
  72. MT('nested-kind-test',
  73. '[keyword {template] [def .foo] [attribute kind]=[string "html"][keyword }]',
  74. ' [tag&bracket <][tag div][tag&bracket >]',
  75. ' [keyword {call] [variable .bar][keyword }]',
  76. ' [keyword {param] [attribute kind]=[string "js"][keyword }]',
  77. ' [keyword var] [def bar] [operator =] [number 5];',
  78. ' [keyword {/param}]',
  79. ' [keyword {/call}]',
  80. ' [tag&bracket </][tag div][tag&bracket >]',
  81. '[keyword {/template}]',
  82. '');
  83. MT('tag-starting-with-function-call-is-not-a-keyword',
  84. '[keyword {]index([variable-2&error $foo])[keyword }]',
  85. '[keyword {css] [string "some-class"][keyword }]',
  86. '[keyword {]css([string "some-class"])[keyword }]',
  87. '');
  88. MT('allow-missing-colon-in-@param',
  89. '[keyword {template] [def .foo][keyword }]',
  90. ' [keyword {@param] [def showThing] [variable-3 bool][keyword }]',
  91. ' [keyword {if] [variable-2 $showThing][keyword }]',
  92. ' Yo!',
  93. ' [keyword {/if}]',
  94. '[keyword {/template}]',
  95. '');
  96. MT('single-quote-strings',
  97. '[keyword {][string "foo"] [string \'bar\'][keyword }]',
  98. '');
  99. MT('literal-comments',
  100. '[keyword {literal}]/* comment */ // comment[keyword {/literal}]');
  101. MT('highlight-command-at-eol',
  102. '[keyword {msg]',
  103. ' [keyword }]');
  104. })();