本站源代码
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.

218 lines
7.3KB

  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}, "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 parentheses.
  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("atMediaFeatureValueKeyword",
  17. "[def @media] ([property orientation]: [keyword landscape]) { }");
  18. MT("atMediaUnknownFeatureValueKeyword",
  19. "[def @media] ([property orientation]: [error upsidedown]) { }");
  20. MT("atMediaUppercase",
  21. "[def @MEDIA] ([property orienTAtion]: [keyword landScape]) { }");
  22. MT("tagSelector",
  23. "[tag foo] { }");
  24. MT("classSelector",
  25. "[qualifier .foo-bar_hello] { }");
  26. MT("idSelector",
  27. "[builtin #foo] { [error #foo] }");
  28. MT("tagSelectorUnclosed",
  29. "[tag foo] { [property margin]: [number 0] } [tag bar] { }");
  30. MT("tagStringNoQuotes",
  31. "[tag foo] { [property font-family]: [variable hello] [variable world]; }");
  32. MT("tagStringDouble",
  33. "[tag foo] { [property font-family]: [string \"hello world\"]; }");
  34. MT("tagStringSingle",
  35. "[tag foo] { [property font-family]: [string 'hello world']; }");
  36. MT("tagColorKeyword",
  37. "[tag foo] {",
  38. " [property color]: [keyword black];",
  39. " [property color]: [keyword navy];",
  40. " [property color]: [keyword yellow];",
  41. "}");
  42. MT("tagColorHex3",
  43. "[tag foo] { [property background]: [atom #fff]; }");
  44. MT("tagColorHex4",
  45. "[tag foo] { [property background]: [atom #ffff]; }");
  46. MT("tagColorHex6",
  47. "[tag foo] { [property background]: [atom #ffffff]; }");
  48. MT("tagColorHex8",
  49. "[tag foo] { [property background]: [atom #ffffffff]; }");
  50. MT("tagColorHex5Invalid",
  51. "[tag foo] { [property background]: [atom&error #fffff]; }");
  52. MT("tagColorHexInvalid",
  53. "[tag foo] { [property background]: [atom&error #ffg]; }");
  54. MT("tagNegativeNumber",
  55. "[tag foo] { [property margin]: [number -5px]; }");
  56. MT("tagPositiveNumber",
  57. "[tag foo] { [property padding]: [number 5px]; }");
  58. MT("tagVendor",
  59. "[tag foo] { [meta -foo-][property box-sizing]: [meta -foo-][atom border-box]; }");
  60. MT("tagBogusProperty",
  61. "[tag foo] { [property&error barhelloworld]: [number 0]; }");
  62. MT("tagTwoProperties",
  63. "[tag foo] { [property margin]: [number 0]; [property padding]: [number 0]; }");
  64. MT("tagTwoPropertiesURL",
  65. "[tag foo] { [property background]: [variable&callee url]([string //example.com/foo.png]); [property padding]: [number 0]; }");
  66. MT("indent_tagSelector",
  67. "[tag strong], [tag em] {",
  68. " [property background]: [variable&callee rgba](",
  69. " [number 255], [number 255], [number 0], [number .2]",
  70. " );",
  71. "}");
  72. MT("indent_atMedia",
  73. "[def @media] {",
  74. " [tag foo] {",
  75. " [property color]:",
  76. " [keyword yellow];",
  77. " }",
  78. "}");
  79. MT("indent_comma",
  80. "[tag foo] {",
  81. " [property font-family]: [variable verdana],",
  82. " [atom sans-serif];",
  83. "}");
  84. MT("indent_parentheses",
  85. "[tag foo]:[variable-3 before] {",
  86. " [property background]: [variable&callee url](",
  87. "[string blahblah]",
  88. "[string etc]",
  89. "[string ]) [keyword !important];",
  90. "}");
  91. MT("font_face",
  92. "[def @font-face] {",
  93. " [property font-family]: [string 'myfont'];",
  94. " [error nonsense]: [string 'abc'];",
  95. " [property src]: [variable&callee url]([string http://blah]),",
  96. " [variable&callee url]([string http://foo]);",
  97. "}");
  98. MT("empty_url",
  99. "[def @import] [variable&callee url]() [attribute screen];");
  100. MT("parens",
  101. "[qualifier .foo] {",
  102. " [property background-image]: [variable&callee fade]([atom #000], [number 20%]);",
  103. " [property border-image]: [variable&callee linear-gradient](",
  104. " [atom to] [atom bottom],",
  105. " [variable&callee fade]([atom #000], [number 20%]) [number 0%],",
  106. " [variable&callee fade]([atom #000], [number 20%]) [number 100%]",
  107. " );",
  108. "}");
  109. MT("css_variable",
  110. ":[variable-3 root] {",
  111. " [variable-2 --main-color]: [atom #06c];",
  112. "}",
  113. "[tag h1][builtin #foo] {",
  114. " [property color]: [variable&callee var]([variable-2 --main-color]);",
  115. "}");
  116. MT("blank_css_variable",
  117. ":[variable-3 root] {",
  118. " [variable-2 --]: [atom #06c];",
  119. "}",
  120. "[tag h1][builtin #foo] {",
  121. " [property color]: [variable&callee var]([variable-2 --]);",
  122. "}");
  123. MT("supports",
  124. "[def @supports] ([keyword not] (([property text-align-last]: [atom justify]) [keyword or] ([meta -moz-][property text-align-last]: [atom justify])) {",
  125. " [property text-align-last]: [atom justify];",
  126. "}");
  127. MT("document",
  128. "[def @document] [variable&callee url]([string http://blah]),",
  129. " [variable&callee url-prefix]([string https://]),",
  130. " [variable&callee domain]([string blah.com]),",
  131. " [variable&callee regexp]([string \".*blah.+\"]) {",
  132. " [builtin #id] {",
  133. " [property background-color]: [keyword white];",
  134. " }",
  135. " [tag foo] {",
  136. " [property font-family]: [variable Verdana], [atom sans-serif];",
  137. " }",
  138. "}");
  139. MT("document_url",
  140. "[def @document] [variable&callee url]([string http://blah]) { [qualifier .class] { } }");
  141. MT("document_urlPrefix",
  142. "[def @document] [variable&callee url-prefix]([string https://]) { [builtin #id] { } }");
  143. MT("document_domain",
  144. "[def @document] [variable&callee domain]([string blah.com]) { [tag foo] { } }");
  145. MT("document_regexp",
  146. "[def @document] [variable&callee regexp]([string \".*blah.+\"]) { [builtin #id] { } }");
  147. MT("counter-style",
  148. "[def @counter-style] [variable binary] {",
  149. " [property system]: [atom numeric];",
  150. " [property symbols]: [number 0] [number 1];",
  151. " [property suffix]: [string \".\"];",
  152. " [property range]: [atom infinite];",
  153. " [property speak-as]: [atom numeric];",
  154. "}");
  155. MT("counter-style-additive-symbols",
  156. "[def @counter-style] [variable simple-roman] {",
  157. " [property system]: [atom additive];",
  158. " [property additive-symbols]: [number 10] [variable X], [number 5] [variable V], [number 1] [variable I];",
  159. " [property range]: [number 1] [number 49];",
  160. "}");
  161. MT("counter-style-use",
  162. "[tag ol][qualifier .roman] { [property list-style]: [variable simple-roman]; }");
  163. MT("counter-style-symbols",
  164. "[tag ol] { [property list-style]: [variable&callee symbols]([atom cyclic] [string \"*\"] [string \"\\2020\"] [string \"\\2021\"] [string \"\\A7\"]); }");
  165. MT("comment-does-not-disrupt",
  166. "[def @font-face] [comment /* foo */] {",
  167. " [property src]: [variable&callee url]([string x]);",
  168. " [property font-family]: [variable One];",
  169. "}")
  170. })();
上海开阖软件有限公司 沪ICP备12045867号-1