Mercurial
comparison .cms/lib/codemirror/mode/python/test.js @ 0:78edf6b517a0 draft
24.10
author | Coffee CMS <info@coffee-cms.ru> |
---|---|
date | Fri, 11 Oct 2024 22:40:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:78edf6b517a0 |
---|---|
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others | |
2 // Distributed under an MIT license: https://codemirror.net/5/LICENSE | |
3 | |
4 (function() { | |
5 var mode = CodeMirror.getMode({indentUnit: 4}, | |
6 {name: "python", | |
7 version: 3, | |
8 singleLineStringErrors: false}); | |
9 function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); } | |
10 | |
11 // Error, because "foobarhello" is neither a known type or property, but | |
12 // property was expected (after "and"), and it should be in parentheses. | |
13 MT("decoratorStartOfLine", | |
14 "[meta @dec]", | |
15 "[keyword def] [def function]():", | |
16 " [keyword pass]"); | |
17 | |
18 MT("decoratorIndented", | |
19 "[keyword class] [def Foo]:", | |
20 " [meta @dec]", | |
21 " [keyword def] [def function]():", | |
22 " [keyword pass]"); | |
23 | |
24 MT("matmulWithSpace:", "[variable a] [operator @] [variable b]"); | |
25 MT("matmulWithoutSpace:", "[variable a][operator @][variable b]"); | |
26 MT("matmulSpaceBefore:", "[variable a] [operator @][variable b]"); | |
27 var before_equal_sign = ["+", "-", "*", "/", "=", "!", ">", "<"]; | |
28 for (var i = 0; i < before_equal_sign.length; ++i) { | |
29 var c = before_equal_sign[i] | |
30 MT("before_equal_sign_" + c, "[variable a] [operator " + c + "=] [variable b]"); | |
31 } | |
32 | |
33 MT("fValidStringPrefix", "[string f'this is a]{[variable formatted]}[string string']"); | |
34 MT("fValidExpressionInFString", "[string f'expression ]{[number 100][operator *][number 5]}[string string']"); | |
35 MT("fInvalidFString", "[error f'this is wrong}]"); | |
36 MT("fNestedFString", "[string f'expression ]{[number 100] [operator +] [string f'inner]{[number 5]}[string ']}[string string']"); | |
37 MT("uValidStringPrefix", "[string u'this is an unicode string']"); | |
38 | |
39 MT("nestedString", "[string f']{[variable b][[ [string \"c\"] ]]}[string f'] [comment # oops]") | |
40 | |
41 MT("bracesInFString", "[string f']{[variable x] [operator +] {}}[string !']") | |
42 | |
43 MT("nestedFString", "[string f']{[variable b][[ [string f\"c\"] ]]}[string f'] [comment # oops]") | |
44 | |
45 MT("dontIndentTypeDecl", | |
46 "[variable i]: [builtin int] [operator =] [number 32]", | |
47 "[builtin print]([variable i])") | |
48 | |
49 MT("dedentElse", | |
50 "[keyword if] [variable x]:", | |
51 " [variable foo]()", | |
52 "[keyword elif] [variable y]:", | |
53 " [variable bar]()", | |
54 "[keyword else]:", | |
55 " [variable baz]()") | |
56 | |
57 MT("dedentElsePass", | |
58 "[keyword if] [variable x]:", | |
59 " [keyword pass]", | |
60 "[keyword elif] [variable y]:", | |
61 " [keyword pass]", | |
62 "[keyword else]:", | |
63 " [keyword pass]") | |
64 | |
65 MT("dedentElseInFunction", | |
66 "[keyword def] [def foo]():", | |
67 " [keyword if] [variable x]:", | |
68 " [variable foo]()", | |
69 " [keyword elif] [variable y]:", | |
70 " [variable bar]()", | |
71 " [keyword pass]", | |
72 " [keyword else]:", | |
73 " [variable baz]()") | |
74 | |
75 MT("dedentCase", | |
76 "[keyword match] [variable x]:", | |
77 " [keyword case] [variable y]:", | |
78 " [variable foo]()") | |
79 MT("dedentCasePass", | |
80 "[keyword match] [variable x]:", | |
81 " [keyword case] [variable y]:", | |
82 " [keyword pass]") | |
83 | |
84 MT("dedentCaseInFunction", | |
85 "[keyword def] [def foo]():", | |
86 " [keyword match] [variable x]:", | |
87 " [keyword case] [variable y]:", | |
88 " [variable foo]()") | |
89 })(); |