test.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function() {
  4. var mode = CodeMirror.getMode({indentUnit: 2}, "jsx")
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)) }
  6. MT("selfclose",
  7. "[keyword var] [def x] [operator =] [bracket&tag <] [tag foo] [bracket&tag />] [operator +] [number 1];")
  8. MT("openclose",
  9. "([bracket&tag <][tag foo][bracket&tag >]hello [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
  10. MT("attr",
  11. "([bracket&tag <][tag foo] [attribute abc]=[string 'value'][bracket&tag >]hello [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
  12. MT("braced_attr",
  13. "([bracket&tag <][tag foo] [attribute abc]={[number 10]}[bracket&tag >]hello [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
  14. MT("braced_text",
  15. "([bracket&tag <][tag foo][bracket&tag >]hello {[number 10]} [atom &amp;][bracket&tag </][tag foo][bracket&tag >][operator ++])")
  16. MT("nested_tag",
  17. "([bracket&tag <][tag foo][bracket&tag ><][tag bar][bracket&tag ></][tag bar][bracket&tag ></][tag foo][bracket&tag >][operator ++])")
  18. MT("nested_jsx",
  19. "[keyword return] (",
  20. " [bracket&tag <][tag foo][bracket&tag >]",
  21. " say {[number 1] [operator +] [bracket&tag <][tag bar] [attribute attr]={[number 10]}[bracket&tag />]}!",
  22. " [bracket&tag </][tag foo][bracket&tag >][operator ++]",
  23. ")")
  24. MT("preserve_js_context",
  25. "[variable x] [operator =] [string-2 `quasi${][bracket&tag <][tag foo][bracket&tag />][string-2 }quoted`]")
  26. MT("line_comment",
  27. "([bracket&tag <][tag foo] [comment // hello]",
  28. " [bracket&tag ></][tag foo][bracket&tag >][operator ++])")
  29. MT("line_comment_not_in_tag",
  30. "([bracket&tag <][tag foo][bracket&tag >] // hello",
  31. " [bracket&tag </][tag foo][bracket&tag >][operator ++])")
  32. MT("block_comment",
  33. "([bracket&tag <][tag foo] [comment /* hello]",
  34. "[comment line 2]",
  35. "[comment line 3 */] [bracket&tag ></][tag foo][bracket&tag >][operator ++])")
  36. MT("block_comment_not_in_tag",
  37. "([bracket&tag <][tag foo][bracket&tag >]/* hello",
  38. " line 2",
  39. " line 3 */ [bracket&tag </][tag foo][bracket&tag >][operator ++])")
  40. MT("missing_attr",
  41. "([bracket&tag <][tag foo] [attribute selected][bracket&tag />][operator ++])")
  42. MT("indent_js",
  43. "([bracket&tag <][tag foo][bracket&tag >]",
  44. " [bracket&tag <][tag bar] [attribute baz]={[keyword function]() {",
  45. " [keyword return] [number 10]",
  46. " }}[bracket&tag />]",
  47. " [bracket&tag </][tag foo][bracket&tag >])")
  48. MT("spread",
  49. "([bracket&tag <][tag foo] [attribute bar]={[meta ...][variable baz] [operator /][number 2]}[bracket&tag />])")
  50. MT("tag_attribute",
  51. "([bracket&tag <][tag foo] [attribute bar]=[bracket&tag <][tag foo][bracket&tag />/>][operator ++])")
  52. })()