test.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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({}, 'shell')
  5. function MT(name) {
  6. test.mode(name, mode, Array.prototype.slice.call(arguments, 1))
  7. }
  8. MT('var', 'text [def $var] text')
  9. MT('varBraces', 'text[def ${var}]text')
  10. MT('varVar', 'text [def $a$b] text')
  11. MT('varBracesVarBraces', 'text[def ${a}${b}]text')
  12. MT('singleQuotedVar', "[string 'text $var text']")
  13. MT('singleQuotedVarBraces', "[string 'text ${var} text']")
  14. MT('doubleQuotedVar', '[string "text ][def $var][string text"]')
  15. MT('doubleQuotedVarBraces', '[string "text][def ${var}][string text"]')
  16. MT('doubleQuotedVarPunct', '[string "text ][def $@][string text"]')
  17. MT('doubleQuotedVarVar', '[string "][def $a$b][string "]')
  18. MT('doubleQuotedVarBracesVarBraces', '[string "][def ${a}${b}][string "]')
  19. MT('notAString', "text\\'text")
  20. MT('escapes', 'outside\\\'\\"\\`\\\\[string "inside\\`\\\'\\"\\\\`\\$notAVar"]outside\\$\\(notASubShell\\)')
  21. MT('subshell', '[builtin echo] [quote $(whoami)] s log, stardate [quote `date`].')
  22. MT('doubleQuotedSubshell', '[builtin echo] [string "][quote $(whoami)][string \'s log, stardate `date`."]')
  23. MT('hashbang', '[meta #!/bin/bash]')
  24. MT('comment', 'text [comment # Blurb]')
  25. MT('numbers', '[number 0] [number 1] [number 2]')
  26. MT('keywords', '[keyword while] [atom true]; [keyword do]', ' [builtin sleep] [number 3]', '[keyword done]')
  27. MT('options', '[builtin ls] [attribute -l] [attribute --human-readable]')
  28. MT('operator', '[def var][operator =]value')
  29. MT('doubleParens', 'foo [quote $((bar))]')
  30. MT('nested braces', '[builtin echo] [def ${A[${B}]]}]')
  31. MT('strings in parens', '[def FOO][operator =]([quote $(<][string "][def $MYDIR][string "][quote /myfile grep ][string \'hello$\'][quote )])')
  32. MT('string ending in dollar', '[def a][operator =][string "xyz$"]; [def b][operator =][string "y"]')
  33. MT('quote ending in dollar', '[quote $(echo a$)]')
  34. MT('heredoc', '[builtin cat] [string-2 <<- end]', '[string-2 content one]', '[string-2 content two end]', '[string-2 end]', '[builtin echo]')
  35. })()