test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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({ indentUnit: 4 }, { name: 'python', version: 3, singleLineStringErrors: false })
  5. function MT(name) {
  6. test.mode(name, mode, Array.prototype.slice.call(arguments, 1))
  7. }
  8. // Error, because "foobarhello" is neither a known type or property, but
  9. // property was expected (after "and"), and it should be in parentheses.
  10. MT('decoratorStartOfLine', '[meta @dec]', '[keyword def] [def function]():', ' [keyword pass]')
  11. MT('decoratorIndented', '[keyword class] [def Foo]:', ' [meta @dec]', ' [keyword def] [def function]():', ' [keyword pass]')
  12. MT('matmulWithSpace:', '[variable a] [operator @] [variable b]')
  13. MT('matmulWithoutSpace:', '[variable a][operator @][variable b]')
  14. MT('matmulSpaceBefore:', '[variable a] [operator @][variable b]')
  15. var before_equal_sign = ['+', '-', '*', '/', '=', '!', '>', '<']
  16. for (var i = 0; i < before_equal_sign.length; ++i) {
  17. var c = before_equal_sign[i]
  18. MT('before_equal_sign_' + c, '[variable a] [operator ' + c + '=] [variable b]')
  19. }
  20. MT('fValidStringPrefix', "[string f'this is a]{[variable formatted]}[string string']")
  21. MT('fValidExpressionInFString', "[string f'expression ]{[number 100][operator *][number 5]}[string string']")
  22. MT('fInvalidFString', "[error f'this is wrong}]")
  23. MT('fNestedFString', "[string f'expression ]{[number 100] [operator +] [string f'inner]{[number 5]}[string ']}[string string']")
  24. MT('uValidStringPrefix', "[string u'this is an unicode string']")
  25. MT('nestedString', '[string f\']{[variable b][[ [string "c"] ]]}[string f\'] [comment # oops]')
  26. MT('bracesInFString', "[string f']{[variable x] [operator +] {}}[string !']")
  27. MT('nestedFString', '[string f\']{[variable b][[ [string f"c"] ]]}[string f\'] [comment # oops]')
  28. MT('dontIndentTypeDecl', '[variable i]: [builtin int] [operator =] [number 32]', '[builtin print]([variable i])')
  29. MT('dedentElse', '[keyword if] [variable x]:', ' [variable foo]()', '[keyword elif] [variable y]:', ' [variable bar]()', '[keyword else]:', ' [variable baz]()')
  30. MT('dedentElsePass', '[keyword if] [variable x]:', ' [keyword pass]', '[keyword elif] [variable y]:', ' [keyword pass]', '[keyword else]:', ' [keyword pass]')
  31. MT(
  32. 'dedentElseInFunction',
  33. '[keyword def] [def foo]():',
  34. ' [keyword if] [variable x]:',
  35. ' [variable foo]()',
  36. ' [keyword elif] [variable y]:',
  37. ' [variable bar]()',
  38. ' [keyword pass]',
  39. ' [keyword else]:',
  40. ' [variable baz]()'
  41. )
  42. })()