test.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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: 2 }, 'sass')
  5. // Since Sass has an indent-based syntax, is almost impossible to test correctly the indentation in all cases.
  6. // So disable it for tests.
  7. mode.indent = undefined
  8. function MT(name) {
  9. test.mode(name, mode, Array.prototype.slice.call(arguments, 1))
  10. }
  11. MT('comment', '[comment // this is a comment]', '[comment also this is a comment]')
  12. MT('comment_multiline', '[comment /* this is a comment]', '[comment also this is a comment]')
  13. MT('variable', '[variable-2 $page-width][operator :] [number 800][unit px]')
  14. MT(
  15. 'global_attributes',
  16. '[tag body]',
  17. ' [property font][operator :]',
  18. ' [property family][operator :] [atom sans-serif]',
  19. ' [property size][operator :] [number 30][unit em]',
  20. ' [property weight][operator :] [atom bold]'
  21. )
  22. MT(
  23. 'scoped_styles',
  24. '[builtin #contents]',
  25. ' [property width][operator :] [variable-2 $page-width]',
  26. ' [builtin #sidebar]',
  27. ' [property float][operator :] [atom right]',
  28. ' [property width][operator :] [variable-2 $sidebar-width]',
  29. ' [builtin #main]',
  30. ' [property width][operator :] [variable-2 $page-width] [operator -] [variable-2 $sidebar-width]',
  31. ' [property background][operator :] [variable-2 $primary-color]',
  32. ' [tag h2]',
  33. ' [property color][operator :] [keyword blue]'
  34. )
  35. // Sass allows to write the colon as first char instead of a "separator".
  36. // :color red
  37. // Not supported
  38. // MT("property_syntax",
  39. // "[qualifier .foo]",
  40. // " [operator :][property color] [keyword red]")
  41. MT(
  42. 'import',
  43. '[def @import] [string "sass/variables"]',
  44. // Probably it should parsed as above: as a string even without the " or '
  45. // "[def @import] [string sass/baz]"
  46. '[def @import] [tag sass][operator /][tag baz]'
  47. )
  48. MT('def', '[def @if] [variable-2 $foo] [def @else]')
  49. MT('tag_on_more_lines', '[tag td],', '[tag th]', ' [property font-family][operator :] [string "Arial"], [atom serif]')
  50. MT('important', '[qualifier .foo]', ' [property text-decoration][operator :] [atom none] [keyword !important]', '[tag h1]', ' [property font-size][operator :] [number 2.5][unit em]')
  51. MT(
  52. 'selector',
  53. // SCSS doesn't highlight the :
  54. // "[tag h1]:[variable-3 before],",
  55. // "[tag h2]:[variable-3 before]",
  56. '[tag h1][variable-3 :before],',
  57. '[tag h2][variable-3 :before]',
  58. ' [property content][operator :] [string "::"]'
  59. )
  60. MT(
  61. 'definition_mixin_equal',
  62. '[variable-2 $defined-bs-type][operator :] [atom border-box] [keyword !default]',
  63. '[meta =bs][operator (][variable-2 $bs-type][operator :] [variable-2 $defined-bs-type][operator )]',
  64. ' [meta -webkit-][property box-sizing][operator :] [variable-2 $bs-type]',
  65. ' [property box-sizing][operator :] [variable-2 $bs-type]'
  66. )
  67. MT(
  68. 'definition_mixin_with_space',
  69. '[variable-2 $defined-bs-type][operator :] [atom border-box] [keyword !default]',
  70. '[def @mixin] [tag bs][operator (][variable-2 $bs-type][operator :] [variable-2 $defined-bs-type][operator )] ',
  71. ' [meta -moz-][property box-sizing][operator :] [variable-2 $bs-type]',
  72. ' [property box-sizing][operator :] [variable-2 $bs-type]'
  73. )
  74. MT(
  75. 'numbers_start_dot_include_plus',
  76. // The % is not highlighted correctly
  77. // "[meta =button-links][operator (][variable-2 $button-base][operator :] [atom darken][operator (][variable-2 $color11], [number 10][unit %][operator )][operator )]",
  78. '[meta =button-links][operator (][variable-2 $button-base][operator :] [atom darken][operator (][variable-2 $color11], [number 10][operator %))]',
  79. ' [property padding][operator :] [number .3][unit em] [number .6][unit em]',
  80. ' [variable-3 +border-radius][operator (][number 8][unit px][operator )]',
  81. ' [property background-color][operator :] [variable-2 $button-base]'
  82. )
  83. MT('include', '[qualifier .bar]', ' [def @include] [tag border-radius][operator (][number 8][unit px][operator )]')
  84. MT(
  85. 'reference_parent',
  86. '[qualifier .col]',
  87. ' [property clear][operator :] [atom both]',
  88. // SCSS doesn't highlight the :
  89. // " &:[variable-3 after]",
  90. ' &[variable-3 :after]',
  91. " [property content][operator :] [string '']",
  92. ' [property clear][operator :] [atom both]'
  93. )
  94. MT(
  95. 'reference_parent_with_spaces',
  96. '[tag section]',
  97. ' [property border-left][operator :] [number 20][unit px] [atom transparent] [atom solid] ',
  98. ' &[qualifier .section3]',
  99. ' [qualifier .title]',
  100. ' [property color][operator :] [keyword white] ',
  101. ' [qualifier .vermas]',
  102. ' [property display][operator :] [atom none]'
  103. )
  104. MT('font_face', '[def @font-face]', " [property font-family][operator :] [string 'icomoon']", ' [property src][operator :] [atom url][operator (][string fonts/icomoon.ttf][operator )]')
  105. })()