all repos — NoPaste @ 3e3c433f026c49e04d0efa0f0f39fc688ed32bb1

Resurrected - The PussTheCat.org fork of NoPaste

scripts/CodeMirror/mode/shell/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({}, "shell");
 6  function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
 7
 8  MT("var",
 9     "text [def $var] text");
10  MT("varBraces",
11     "text[def ${var}]text");
12  MT("varVar",
13     "text [def $a$b] text");
14  MT("varBracesVarBraces",
15     "text[def ${a}${b}]text");
16
17  MT("singleQuotedVar",
18     "[string 'text $var text']");
19  MT("singleQuotedVarBraces",
20     "[string 'text ${var} text']");
21
22  MT("doubleQuotedVar",
23     '[string "text ][def $var][string  text"]');
24  MT("doubleQuotedVarBraces",
25     '[string "text][def ${var}][string text"]');
26  MT("doubleQuotedVarPunct",
27     '[string "text ][def $@][string  text"]');
28  MT("doubleQuotedVarVar",
29     '[string "][def $a$b][string "]');
30  MT("doubleQuotedVarBracesVarBraces",
31     '[string "][def ${a}${b}][string "]');
32
33  MT("notAString",
34     "text\\'text");
35  MT("escapes",
36     "outside\\'\\\"\\`\\\\[string \"inside\\`\\'\\\"\\\\`\\$notAVar\"]outside\\$\\(notASubShell\\)");
37
38  MT("subshell",
39     "[builtin echo] [quote $(whoami)] s log, stardate [quote `date`].");
40  MT("doubleQuotedSubshell",
41     "[builtin echo] [string \"][quote $(whoami)][string 's log, stardate `date`.\"]");
42
43  MT("hashbang",
44     "[meta #!/bin/bash]");
45  MT("comment",
46     "text [comment # Blurb]");
47
48  MT("numbers",
49     "[number 0] [number 1] [number 2]");
50  MT("keywords",
51     "[keyword while] [atom true]; [keyword do]",
52     "  [builtin sleep] [number 3]",
53     "[keyword done]");
54  MT("options",
55     "[builtin ls] [attribute -l] [attribute --human-readable]");
56  MT("operator",
57     "[def var][operator =]value");
58
59  MT("doubleParens",
60     "foo [quote $((bar))]")
61
62  MT("nested braces",
63     "[builtin echo] [def ${A[${B}]]}]")
64
65  MT("strings in parens",
66     "[def FOO][operator =]([quote $(<][string \"][def $MYDIR][string \"][quote /myfile grep ][string 'hello$'][quote )])")
67
68  MT ("string ending in dollar",
69     '[def a][operator =][string "xyz$"]; [def b][operator =][string "y"]')
70
71  MT ("quote ending in dollar",
72     "[quote $(echo a$)]")
73})();