test.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function() {
  4. var mode = CodeMirror.getMode({indentUnit: 2}, "css");
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  6. // Error, because "foobarhello" is neither a known type or property, but
  7. // property was expected (after "and"), and it should be in parenthese.
  8. MT("atMediaUnknownType",
  9. "[def @media] [attribute screen] [keyword and] [error foobarhello] { }");
  10. // Soft error, because "foobarhello" is not a known property or type.
  11. MT("atMediaUnknownProperty",
  12. "[def @media] [attribute screen] [keyword and] ([error foobarhello]) { }");
  13. // Make sure nesting works with media queries
  14. MT("atMediaMaxWidthNested",
  15. "[def @media] [attribute screen] [keyword and] ([property max-width]: [number 25px]) { [tag foo] { } }");
  16. MT("tagSelector",
  17. "[tag foo] { }");
  18. MT("classSelector",
  19. "[qualifier .foo-bar_hello] { }");
  20. MT("idSelector",
  21. "[builtin #foo] { [error #foo] }");
  22. MT("tagSelectorUnclosed",
  23. "[tag foo] { [property margin]: [number 0] } [tag bar] { }");
  24. MT("tagStringNoQuotes",
  25. "[tag foo] { [property font-family]: [variable hello] [variable world]; }");
  26. MT("tagStringDouble",
  27. "[tag foo] { [property font-family]: [string \"hello world\"]; }");
  28. MT("tagStringSingle",
  29. "[tag foo] { [property font-family]: [string 'hello world']; }");
  30. MT("tagColorKeyword",
  31. "[tag foo] {",
  32. " [property color]: [keyword black];",
  33. " [property color]: [keyword navy];",
  34. " [property color]: [keyword yellow];",
  35. "}");
  36. MT("tagColorHex3",
  37. "[tag foo] { [property background]: [atom #fff]; }");
  38. MT("tagColorHex6",
  39. "[tag foo] { [property background]: [atom #ffffff]; }");
  40. MT("tagColorHex4",
  41. "[tag foo] { [property background]: [atom&error #ffff]; }");
  42. MT("tagColorHexInvalid",
  43. "[tag foo] { [property background]: [atom&error #ffg]; }");
  44. MT("tagNegativeNumber",
  45. "[tag foo] { [property margin]: [number -5px]; }");
  46. MT("tagPositiveNumber",
  47. "[tag foo] { [property padding]: [number 5px]; }");
  48. MT("tagVendor",
  49. "[tag foo] { [meta -foo-][property box-sizing]: [meta -foo-][atom border-box]; }");
  50. MT("tagBogusProperty",
  51. "[tag foo] { [property&error barhelloworld]: [number 0]; }");
  52. MT("tagTwoProperties",
  53. "[tag foo] { [property margin]: [number 0]; [property padding]: [number 0]; }");
  54. MT("tagTwoPropertiesURL",
  55. "[tag foo] { [property background]: [atom url]([string //example.com/foo.png]); [property padding]: [number 0]; }");
  56. MT("commentSGML",
  57. "[comment <!--comment-->]");
  58. MT("commentSGML2",
  59. "[comment <!--comment]",
  60. "[comment -->] [tag div] {}");
  61. MT("indent_tagSelector",
  62. "[tag strong], [tag em] {",
  63. " [property background]: [atom rgba](",
  64. " [number 255], [number 255], [number 0], [number .2]",
  65. " );",
  66. "}");
  67. MT("indent_atMedia",
  68. "[def @media] {",
  69. " [tag foo] {",
  70. " [property color]:",
  71. " [keyword yellow];",
  72. " }",
  73. "}");
  74. MT("indent_comma",
  75. "[tag foo] {",
  76. " [property font-family]: [variable verdana],",
  77. " [atom sans-serif];",
  78. "}");
  79. MT("indent_parentheses",
  80. "[tag foo]:[variable-3 before] {",
  81. " [property background]: [atom url](",
  82. "[string blahblah]",
  83. "[string etc]",
  84. "[string ]) [keyword !important];",
  85. "}");
  86. MT("font_face",
  87. "[def @font-face] {",
  88. " [property font-family]: [string 'myfont'];",
  89. " [error nonsense]: [string 'abc'];",
  90. " [property src]: [atom url]([string http://blah]),",
  91. " [atom url]([string http://foo]);",
  92. "}");
  93. MT("empty_url",
  94. "[def @import] [tag url]() [tag screen];");
  95. MT("parens",
  96. "[qualifier .foo] {",
  97. " [property background-image]: [variable fade]([atom #000], [number 20%]);",
  98. " [property border-image]: [atom linear-gradient](",
  99. " [atom to] [atom bottom],",
  100. " [variable fade]([atom #000], [number 20%]) [number 0%],",
  101. " [variable fade]([atom #000], [number 20%]) [number 100%]",
  102. " );",
  103. "}");
  104. MT("css_variable",
  105. ":[variable-3 root] {",
  106. " [variable-2 --main-color]: [atom #06c];",
  107. "}",
  108. "[tag h1][builtin #foo] {",
  109. " [property color]: [atom var]([variable-2 --main-color]);",
  110. "}");
  111. MT("supports",
  112. "[def @supports] ([keyword not] (([property text-align-last]: [atom justify]) [keyword or] ([meta -moz-][property text-align-last]: [atom justify])) {",
  113. " [property text-align-last]: [atom justify];",
  114. "}");
  115. MT("document",
  116. "[def @document] [tag url]([string http://blah]),",
  117. " [tag url-prefix]([string https://]),",
  118. " [tag domain]([string blah.com]),",
  119. " [tag regexp]([string \".*blah.+\"]) {",
  120. " [builtin #id] {",
  121. " [property background-color]: [keyword white];",
  122. " }",
  123. " [tag foo] {",
  124. " [property font-family]: [variable Verdana], [atom sans-serif];",
  125. " }",
  126. " }");
  127. MT("document_url",
  128. "[def @document] [tag url]([string http://blah]) { [qualifier .class] { } }");
  129. MT("document_urlPrefix",
  130. "[def @document] [tag url-prefix]([string https://]) { [builtin #id] { } }");
  131. MT("document_domain",
  132. "[def @document] [tag domain]([string blah.com]) { [tag foo] { } }");
  133. MT("document_regexp",
  134. "[def @document] [tag regexp]([string \".*blah.+\"]) { [builtin #id] { } }");
  135. MT("counter-style",
  136. "[def @counter-style] [variable binary] {",
  137. " [property system]: [atom numeric];",
  138. " [property symbols]: [number 0] [number 1];",
  139. " [property suffix]: [string \".\"];",
  140. " [property range]: [atom infinite];",
  141. " [property speak-as]: [atom numeric];",
  142. "}");
  143. MT("counter-style-additive-symbols",
  144. "[def @counter-style] [variable simple-roman] {",
  145. " [property system]: [atom additive];",
  146. " [property additive-symbols]: [number 10] [variable X], [number 5] [variable V], [number 1] [variable I];",
  147. " [property range]: [number 1] [number 49];",
  148. "}");
  149. MT("counter-style-use",
  150. "[tag ol][qualifier .roman] { [property list-style]: [variable simple-roman]; }");
  151. MT("counter-style-symbols",
  152. "[tag ol] { [property list-style]: [atom symbols]([atom cyclic] [string \"*\"] [string \"\\2020\"] [string \"\\2021\"] [string \"\\A7\"]); }");
  153. })();