You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
3.2 KiB

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