parse.test.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. var TESTS = [
  2. {
  3. input: "/* fuuuu */",
  4. result: {
  5. cssRules: []
  6. }
  7. },
  8. {
  9. input: "/**/",
  10. result: {
  11. cssRules: []
  12. }
  13. },
  14. {
  15. input: "/*a {content: '* {color:#000}'}*/",
  16. result: {
  17. cssRules: []
  18. }
  19. },
  20. {
  21. input: "a {color: red}",
  22. result: {
  23. cssRules: [
  24. {
  25. selectorText: "a",
  26. style: {
  27. 0: "color",
  28. color: "red",
  29. length: 1
  30. }
  31. }
  32. ]
  33. }
  34. },
  35. {
  36. input: ".left {float: left;}",
  37. result: {
  38. cssRules: [
  39. {
  40. selectorText: ".left",
  41. style: {
  42. 0: "float",
  43. float: "left",
  44. length: 1
  45. }
  46. }
  47. ]
  48. }
  49. },
  50. {
  51. input: "h1 {font-family: 'Times New Roman', Helvetica Neue, sans-serif }",
  52. result: {
  53. cssRules: [
  54. {
  55. selectorText: "h1",
  56. style: {
  57. 0: "font-family",
  58. "font-family": "'Times New Roman', Helvetica Neue, sans-serif",
  59. length: 1
  60. }
  61. }
  62. ]
  63. }
  64. },
  65. {
  66. input: "h2 {font: normal\n1.6em\r\nTimes New Roman,\tserif ;}",
  67. result: {
  68. cssRules: [
  69. {
  70. selectorText: "h2",
  71. style: {
  72. 0: "font",
  73. font: "normal 1.6em Times New Roman, serif",
  74. length: 1
  75. }
  76. }
  77. ]
  78. }
  79. },
  80. {
  81. input: ".icon>*{background-image: url(../images/ramona_strong.gif);}",
  82. result: {
  83. cssRules: [
  84. {
  85. selectorText: ".icon>*",
  86. style: {
  87. 0: "background-image",
  88. "background-image": "url(../images/ramona_strong.gif)",
  89. length: 1
  90. }
  91. }
  92. ]
  93. }
  94. },
  95. {
  96. input: "*/**/{}",
  97. result: {
  98. cssRules: [
  99. {
  100. selectorText: "*",
  101. style: {
  102. length: 0
  103. }
  104. }
  105. ]
  106. }
  107. },
  108. {
  109. input: "/**/*{}",
  110. result: {
  111. cssRules: [
  112. {
  113. selectorText: "*",
  114. style: {
  115. length: 0
  116. }
  117. }
  118. ]
  119. }
  120. },
  121. {
  122. input: "* /**/*{}",
  123. result: {
  124. cssRules: [
  125. {
  126. selectorText: "* *",
  127. style: {
  128. length: 0
  129. }
  130. }
  131. ]
  132. }
  133. },
  134. {
  135. input: "*/*/*/ *{}",
  136. result: {
  137. cssRules: [
  138. {
  139. selectorText: "* *",
  140. style: {
  141. length: 0
  142. }
  143. }
  144. ]
  145. }
  146. },
  147. {
  148. input: "#a {b:c;}\n#d {e:f}",
  149. result: {
  150. cssRules: [
  151. {
  152. selectorText: "#a",
  153. style: {
  154. 0: "b",
  155. b: "c",
  156. length: 1
  157. }
  158. }, {
  159. selectorText: "#d",
  160. style: {
  161. 0: "e",
  162. e: "f",
  163. length: 1
  164. }
  165. }
  166. ]
  167. }
  168. },
  169. {
  170. input: "* { border: none } \n#foo {font-size: 12px; background:#fff;}",
  171. result: {
  172. cssRules: [
  173. {
  174. selectorText: "*",
  175. style: {
  176. 0: "border",
  177. border: "none",
  178. length: 1
  179. }
  180. },
  181. {
  182. selectorText: "#foo",
  183. style: {
  184. 0: "font-size",
  185. "font-size": "12px",
  186. 1: "background",
  187. background: "#fff",
  188. length: 2
  189. }
  190. }
  191. ]
  192. }
  193. },
  194. {
  195. input: "span {display: inline-block !important; vertical-align: middle !important} .error{color:red!important;}",
  196. result: {
  197. cssRules: [
  198. {
  199. selectorText: "span",
  200. style: {
  201. 0: "display",
  202. 1: "vertical-align",
  203. display: "inline-block",
  204. "vertical-align": "middle",
  205. length: 2
  206. }
  207. },
  208. {
  209. selectorText: ".error",
  210. style: {
  211. 0: "color",
  212. color: "red",
  213. length: 1
  214. }
  215. }
  216. ]
  217. }
  218. },
  219. {
  220. input: "@media handheld, only screen and (max-device-width: 480px) {body{max-width:480px}}",
  221. result: {
  222. cssRules: [
  223. {
  224. media: {
  225. 0: "handheld",
  226. 1: "only screen and (max-device-width: 480px)",
  227. length: 2
  228. },
  229. cssRules: [
  230. {
  231. selectorText: "body",
  232. style: {
  233. 0: "max-width",
  234. "max-width": "480px",
  235. length: 1
  236. }
  237. }
  238. ]
  239. }
  240. ]
  241. }
  242. },
  243. {
  244. input: "@media screen, screen, screen {/* Match Firefox and Opera behavior here rather than WebKit. \nSane person shouldn't write like this anyway. */}",
  245. result: {
  246. cssRules: [
  247. {
  248. media: {
  249. 0: "screen",
  250. 1: "screen",
  251. 2: "screen",
  252. length: 3
  253. },
  254. cssRules: []
  255. }
  256. ]
  257. }
  258. },
  259. {
  260. input: "@media/**/print {*{background:#fff}}",
  261. result: {
  262. cssRules: [
  263. {
  264. media: {
  265. 0: "print",
  266. length: 1
  267. },
  268. cssRules: [
  269. {
  270. selectorText: "*",
  271. style: {
  272. 0: "background",
  273. background: "#fff",
  274. length: 1
  275. }
  276. }
  277. ]
  278. }
  279. ]
  280. }
  281. },
  282. {
  283. input: "a{}@media all{b{color:#000}}",
  284. result: {
  285. cssRules: [
  286. {
  287. selectorText: "a",
  288. style: {
  289. length: 0
  290. }
  291. },
  292. {
  293. media: {
  294. 0: "all",
  295. length: 1
  296. },
  297. cssRules: [
  298. {
  299. selectorText: "b",
  300. style: {
  301. 0: "color",
  302. color: "#000",
  303. length: 1
  304. }
  305. }
  306. ]
  307. }
  308. ]
  309. }
  310. },
  311. {
  312. input: "@mediaall {}",
  313. result: {
  314. cssRules: []
  315. }
  316. },
  317. {
  318. input: "some invalid junk @media projection {body{background:black}}",
  319. result: {
  320. cssRules: [
  321. {
  322. media: {
  323. 0: "projection",
  324. length: 1
  325. },
  326. cssRules: [
  327. {
  328. selectorText: "body",
  329. style: {
  330. 0: "background",
  331. background: "black",
  332. length: 1
  333. }
  334. }
  335. ]
  336. }
  337. ]
  338. }
  339. }
  340. ];
  341. // Run tests.
  342. for (var i=0; i<TESTS.length; i++) {
  343. compare(TESTS[i].input, TESTS[i].result, TESTS[i].name);
  344. }