1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501
|
# -*- coding: utf-8 -*-
require File.dirname(__FILE__) + '/../test_helper'
require File.dirname(__FILE__) + '/test_helper'
require 'sass/engine'
require 'stringio'
require 'mock_importer'
require 'pathname'
module Sass::Script::Functions::UserFunctions
def option(name)
Sass::Script::Value::String.new(@options[name.value.to_sym].to_s)
end
def set_a_variable(name, value)
environment.set_var(name.value, value)
return Sass::Script::Value::Null.new
end
def set_a_global_variable(name, value)
environment.set_global_var(name.value, value)
return Sass::Script::Value::Null.new
end
def get_a_variable(name)
environment.var(name.value) || Sass::Script::Value::String.new("undefined")
end
end
module Sass::Script::Functions
include Sass::Script::Functions::UserFunctions
end
class SassEngineTest < Minitest::Test
FAKE_FILE_NAME = __FILE__.gsub(/rb$/,"sass")
# A map of erroneous Sass documents to the error messages they should produce.
# The error messages may be arrays;
# if so, the second element should be the line number that should be reported for the error.
# If this isn't provided, the tests will assume the line number should be the last line of the document.
EXCEPTION_MAP = {
"$a: 1 + " => 'Invalid CSS after "1 +": expected expression (e.g. 1px, bold), was ""',
"$a: 1 + 2 +" => 'Invalid CSS after "1 + 2 +": expected expression (e.g. 1px, bold), was ""',
"$a: 1 + 2 + %" => 'Invalid CSS after "1 + 2 + ": expected expression (e.g. 1px, bold), was "%"',
"$a: foo(\"bar\"" => 'Invalid CSS after "foo("bar"": expected ")", was ""',
"$a: 1 }" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}"',
"$a: 1 }foo\"" => 'Invalid CSS after "1 ": expected expression (e.g. 1px, bold), was "}foo""',
":" => 'Invalid property: ":".',
": a" => 'Invalid property: ": a".',
"a\n :b" => <<MSG,
Invalid property: ":b" (no value).
If ":b" should be a selector, use "\\:b" instead.
MSG
"a\n b:" => 'Invalid property: "b:" (no value).',
"a\n :b: c" => 'Invalid property: ":b: c".',
"a\n :b:c d" => 'Invalid property: ":b:c d".',
"a\n :b c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
"a\n b: c;" => 'Invalid CSS after "c": expected expression (e.g. 1px, bold), was ";"',
".foo ^bar\n a: b" => ['Invalid CSS after ".foo ": expected selector, was "^bar"', 1],
"a\n @extend .foo ^bar" => 'Invalid CSS after ".foo ": expected selector, was "^bar"',
"a\n @extend .foo .bar" => "Can't extend .foo .bar: can't extend nested selectors",
"a\n @extend >" => "Can't extend >: invalid selector",
"a\n @extend &.foo" => "Can't extend &.foo: can't extend parent selectors",
"a: b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.',
":a b" => 'Properties are only allowed within rules, directives, mixin includes, or other properties.',
"$" => 'Invalid variable: "$".',
"$a" => 'Invalid variable: "$a".',
"$ a" => 'Invalid variable: "$ a".',
"$a b" => 'Invalid variable: "$a b".',
"$a: 1b + 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 1b < 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 1b > 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 1b <= 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 1b >= 2c" => "Incompatible units: 'c' and 'b'.",
"a\n b: 1b * 2c" => "2b*c isn't a valid CSS value.",
"a\n b: 1b % 2c" => "Incompatible units: 'c' and 'b'.",
"$a: 2px + #ccc" => "Cannot add a number with units (2px) to a color (#ccc).",
"$a: #ccc + 2px" => "Cannot add a number with units (2px) to a color (#ccc).",
"& a\n :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
"a\n :b\n c" => "Illegal nesting: Only properties may be nested beneath properties.",
"$a: b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.",
"@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.",
"foo\n @import foo.css" => "CSS import directives may only be used at the root of a document.",
"@if true\n @import foo" => "Import directives may not be used within control directives or mixins.",
"@if true\n .foo\n @import foo" => "Import directives may not be used within control directives or mixins.",
"@mixin foo\n @import foo" => "Import directives may not be used within control directives or mixins.",
"@mixin foo\n .foo\n @import foo" => "Import directives may not be used within control directives or mixins.",
"@import foo;" => "Invalid @import: expected end of line, was \";\".",
'$foo: "bar" "baz" !' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "!"},
'$foo: "bar" "baz" $' => %Q{Invalid CSS after ""bar" "baz" ": expected expression (e.g. 1px, bold), was "$"}, #'
"=foo\n :color red\n.bar\n +bang" => "Undefined mixin 'bang'.",
"=foo\n :color red\n.bar\n +bang_bop" => "Undefined mixin 'bang_bop'.",
"=foo\n :color red\n.bar\n +bang-bop" => "Undefined mixin 'bang-bop'.",
".foo\n =foo\n :color red\n.bar\n +foo" => "Undefined mixin 'foo'.",
" a\n b: c" => ["Indenting at the beginning of the document is illegal.", 1],
" \n \n\t\n a\n b: c" => ["Indenting at the beginning of the document is illegal.", 4],
"a\n b: c\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 3],
"a\n b: c\na\n b: c" => ["Inconsistent indentation: 1 space was used for indentation, but the rest of the document was indented using 2 spaces.", 4],
"a\n\t\tb: c\n\tb: c" => ["Inconsistent indentation: 1 tab was used for indentation, but the rest of the document was indented using 2 tabs.", 3],
"a\n b: c\n b: c" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 3],
"a\n b: c\n a\n d: e" => ["Inconsistent indentation: 3 spaces were used for indentation, but the rest of the document was indented using 2 spaces.", 4],
"a\n \tb: c" => ["Indentation can't use both tabs and spaces.", 2],
"=a(" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ""',
"=a(b)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "b)"',
"=a(,)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was ",)"',
"=a($)" => 'Invalid CSS after "(": expected variable (e.g. $foo), was "$)"',
"=a($foo bar)" => 'Invalid CSS after "($foo ": expected ")", was "bar)"',
"=foo\n bar: baz\n+foo" => ["Properties are only allowed within rules, directives, mixin includes, or other properties.", 2],
"a-\#{$b\n c: d" => ['Invalid CSS after "a-#{$b": expected "}", was ""', 1],
"=a($b: 1, $c)" => "Required argument $c must come before any optional arguments.",
"=a($b: 1)\n a: $b\ndiv\n +a(1,2)" => "Mixin a takes 1 argument but 2 were passed.",
"=a($b: 1)\n a: $b\ndiv\n +a(1,$c: 3)" => "Mixin a doesn't have an argument named $c.",
"=a($b)\n a: $b\ndiv\n +a" => "Mixin a is missing argument $b.",
"@function foo()\n 1 + 2" => "Functions can only contain variable declarations and control directives.",
"@function foo()\n foo: bar" => "Functions can only contain variable declarations and control directives.",
"@function foo()\n foo: bar\n @return 3" => ["Functions can only contain variable declarations and control directives.", 2],
"@function foo\n @return 1" => ['Invalid CSS after "": expected "(", was ""', 1],
"@function foo(\n @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was ""', 1],
"@function foo(b)\n @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "b)"', 1],
"@function foo(,)\n @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was ",)"', 1],
"@function foo($)\n @return 1" => ['Invalid CSS after "(": expected variable (e.g. $foo), was "$)"', 1],
"@function foo()\n @return" => 'Invalid @return: expected expression.',
"@function foo()\n @return 1\n $var: val" => 'Illegal nesting: Nothing may be nested beneath return directives.',
"@function foo($a)\n @return 1\na\n b: foo()" => 'Function foo is missing argument $a.',
"@function foo()\n @return 1\na\n b: foo(2)" => 'Function foo takes 0 arguments but 1 was passed.',
"@function foo()\n @return 1\na\n b: foo($a: 1)" => "Function foo doesn't have an argument named $a.",
"@function foo()\n @return 1\na\n b: foo($a: 1, $b: 2)" => "Function foo doesn't have the following arguments: $a, $b.",
"@return 1" => '@return may only be used within a function.',
"@if true\n @return 1" => '@return may only be used within a function.',
"@mixin foo\n @return 1\n@include foo" => ['@return may only be used within a function.', 2],
"@else\n a\n b: c" => ["@else must come after @if.", 1],
"@if false\n@else foo" => "Invalid else directive '@else foo': expected 'if <expr>'.",
"@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.",
"a\n $b: 12\nc\n d: $b" => 'Undefined variable: "$b".',
"=foo\n $b: 12\nc\n +foo\n d: $b" => 'Undefined variable: "$b".',
"c\n d: $b-foo" => 'Undefined variable: "$b-foo".',
"c\n d: $b_foo" => 'Undefined variable: "$b_foo".',
'@for $a from "foo" to 1' => '"foo" is not an integer.',
'@for $a from 1 to "2"' => '"2" is not an integer.',
'@for $a from 1 to "foo"' => '"foo" is not an integer.',
'@for $a from 1 to 1.23232323232' => '1.2323232323 is not an integer.',
'@for $a from 1px to 3em' => "Incompatible units: 'em' and 'px'.",
'@if' => "Invalid if directive '@if': expected expression.",
'@while' => "Invalid while directive '@while': expected expression.",
'@debug' => "Invalid debug directive '@debug': expected expression.",
%Q{@debug "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath debug directives.",
'@error' => "Invalid error directive '@error': expected expression.",
%Q{@error "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath error directives.",
'@warn' => "Invalid warn directive '@warn': expected expression.",
%Q{@warn "a message"\n "nested message"} => "Illegal nesting: Nothing may be nested beneath warn directives.",
"/* foo\n bar\n baz" => "Inconsistent indentation: previous line was indented by 4 spaces, but this line was indented by 2 spaces.",
'+foo(1 + 1: 2)' => 'Invalid CSS after "(1 + 1": expected comma, was ": 2)"',
'+foo($var: )' => 'Invalid CSS after "($var: ": expected mixin argument, was ")"',
'+foo($var: a, $var: b)' => 'Keyword argument "$var" passed more than once',
'+foo($var-var: a, $var_var: b)' => 'Keyword argument "$var_var" passed more than once',
'+foo($var_var: a, $var-var: b)' => 'Keyword argument "$var-var" passed more than once',
"a\n b: foo(1 + 1: 2)" => 'Invalid CSS after "foo(1 + 1": expected comma, was ": 2)"',
"a\n b: foo($var: )" => 'Invalid CSS after "foo($var: ": expected function argument, was ")"',
"a\n b: foo($var: a, $var: b)" => 'Keyword argument "$var" passed more than once',
"a\n b: foo($var-var: a, $var_var: b)" => 'Keyword argument "$var_var" passed more than once',
"a\n b: foo($var_var: a, $var-var: b)" => 'Keyword argument "$var-var" passed more than once',
"@if foo\n @extend .bar" => ["Extend directives may only be used within rules.", 2],
"$var: true\n@while $var\n @extend .bar\n $var: false" => ["Extend directives may only be used within rules.", 3],
"@for $i from 0 to 1\n @extend .bar" => ["Extend directives may only be used within rules.", 2],
"@mixin foo\n @extend .bar\n@include foo" => ["Extend directives may only be used within rules.", 2],
"foo %\n a: b" => ['Invalid CSS after "foo %": expected placeholder name, was ""', 1],
"=foo\n @content error" => "Invalid content directive. Trailing characters found: \"error\".",
"=foo\n @content\n b: c" => "Illegal nesting: Nothing may be nested beneath @content directives.",
"@content" => '@content may only be used within a mixin.',
"=simple\n .simple\n color: red\n+simple\n color: blue" => ['Mixin "simple" does not accept a content block.', 4],
"@import \"foo\" // bar" => "Invalid CSS after \"\"foo\" \": expected media query list, was \"// bar\"",
"@at-root\n a: b" => "Properties are only allowed within rules, directives, mixin includes, or other properties.",
# Regression tests
"a\n b:\n c\n d" => ["Illegal nesting: Only properties may be nested beneath properties.", 3],
"& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1],
"a\n b: c\n& foo\n bar: baz\n blat: bang" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 3],
"@" => "Invalid directive: '@'.",
"$r: 20em * #ccc" => ["Cannot multiply a number with units (20em) to a color (#ccc).", 1],
"$r: #ccc / 1em" => ["Cannot divide a number with units (1em) to a color (#ccc).", 1],
}
def teardown
clean_up_sassc
end
def test_basic_render
renders_correctly "basic", { :style => :compact }
end
def test_empty_render
assert_equal "", render("")
end
def test_multiple_calls_to_render
sass = Sass::Engine.new("a\n b: c")
assert_equal sass.render, sass.render
end
def test_alternate_styles
renders_correctly "expanded", { :style => :expanded }
renders_correctly "compact", { :style => :compact }
renders_correctly "nested", { :style => :nested }
renders_correctly "compressed", { :style => :compressed }
end
def test_compile
assert_equal "div { hello: world; }\n", Sass.compile("$who: world\ndiv\n hello: $who", :syntax => :sass, :style => :compact)
assert_equal "div { hello: world; }\n", Sass.compile("$who: world; div { hello: $who }", :style => :compact)
end
def test_compile_file
FileUtils.mkdir_p(absolutize("tmp"))
open(absolutize("tmp/test_compile_file.sass"), "w") {|f| f.write("$who: world\ndiv\n hello: $who")}
open(absolutize("tmp/test_compile_file.scss"), "w") {|f| f.write("$who: world; div { hello: $who }")}
assert_equal "div { hello: world; }\n", Sass.compile_file(absolutize("tmp/test_compile_file.sass"), :style => :compact)
assert_equal "div { hello: world; }\n", Sass.compile_file(absolutize("tmp/test_compile_file.scss"), :style => :compact)
ensure
FileUtils.rm_rf(absolutize("tmp"))
end
def test_compile_file_to_css_file
FileUtils.mkdir_p(absolutize("tmp"))
open(absolutize("tmp/test_compile_file.sass"), "w") {|f| f.write("$who: world\ndiv\n hello: $who")}
open(absolutize("tmp/test_compile_file.scss"), "w") {|f| f.write("$who: world; div { hello: $who }")}
Sass.compile_file(absolutize("tmp/test_compile_file.sass"), absolutize("tmp/test_compile_file_sass.css"), :style => :compact)
Sass.compile_file(absolutize("tmp/test_compile_file.scss"), absolutize("tmp/test_compile_file_scss.css"), :style => :compact)
assert_equal "div { hello: world; }\n", File.read(absolutize("tmp/test_compile_file_sass.css"))
assert_equal "div { hello: world; }\n", File.read(absolutize("tmp/test_compile_file_scss.css"))
ensure
FileUtils.rm_rf(absolutize("tmp"))
end
def test_flexible_tabulation
assert_equal("p {\n a: b; }\n p q {\n c: d; }\n",
render("p\n a: b\n q\n c: d\n"))
assert_equal("p {\n a: b; }\n p q {\n c: d; }\n",
render("p\n\ta: b\n\tq\n\t\tc: d\n"))
end
def test_import_same_name_different_ext
assert_raise_message Sass::SyntaxError, <<ERROR do
It's not clear which file to import for '@import "same_name_different_ext"'.
Candidates:
same_name_different_ext.sass
same_name_different_ext.scss
Please delete or rename all but one of these files.
ERROR
options = {:load_paths => [File.dirname(__FILE__) + '/templates/']}
munge_filename options
Sass::Engine.new("@import 'same_name_different_ext'", options).render
end
end
def test_import_same_name_different_partiality
assert_raise_message Sass::SyntaxError, <<ERROR do
It's not clear which file to import for '@import "same_name_different_partiality"'.
Candidates:
_same_name_different_partiality.scss
same_name_different_partiality.scss
Please delete or rename all but one of these files.
ERROR
options = {:load_paths => [File.dirname(__FILE__) + '/templates/']}
munge_filename options
Sass::Engine.new("@import 'same_name_different_partiality'", options).render
end
end
EXCEPTION_MAP.each do |key, value|
define_method("test_exception (#{key.inspect})") do
line = 10
begin
silence_warnings {Sass::Engine.new(key, :filename => FAKE_FILE_NAME, :line => line).render}
rescue Sass::SyntaxError => err
value = [value] unless value.is_a?(Array)
assert_equal(value.first.rstrip, err.message, "Line: #{key}")
assert_equal(FAKE_FILE_NAME, err.sass_filename)
assert_equal((value[1] || key.split("\n").length) + line - 1, err.sass_line, "Line: #{key}")
assert_match(/#{Regexp.escape(FAKE_FILE_NAME)}:[0-9]+/, err.backtrace[0], "Line: #{key}")
else
assert(false, "Exception not raised for\n#{key}")
end
end
end
def test_exception_line
to_render = <<SASS
rule
prop: val
// comment!
broken:
SASS
begin
Sass::Engine.new(to_render).render
rescue Sass::SyntaxError => err
assert_equal(5, err.sass_line)
else
assert(false, "Exception not raised for '#{to_render}'!")
end
end
def test_exception_location
to_render = <<SASS
rule
prop: val
// comment!
broken:
SASS
begin
Sass::Engine.new(to_render, :filename => FAKE_FILE_NAME, :line => (__LINE__-7)).render
rescue Sass::SyntaxError => err
assert_equal(FAKE_FILE_NAME, err.sass_filename)
assert_equal((__LINE__-6), err.sass_line)
else
assert(false, "Exception not raised for '#{to_render}'!")
end
end
def test_imported_exception
[1, 2, 3, 4].each do |i|
begin
Sass::Engine.new("@import bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
rescue Sass::SyntaxError => err
assert_equal(2, err.sass_line)
assert_match(/(\/|^)bork#{i}\.sass$/, err.sass_filename)
assert_hash_has(err.sass_backtrace.first,
:filename => err.sass_filename, :line => err.sass_line)
assert_nil(err.sass_backtrace[1][:filename])
assert_equal(1, err.sass_backtrace[1][:line])
assert_match(/(\/|^)bork#{i}\.sass:2$/, err.backtrace.first)
assert_equal("(sass):1", err.backtrace[1])
else
assert(false, "Exception not raised for imported template: bork#{i}")
end
end
end
def test_double_imported_exception
[1, 2, 3, 4].each do |i|
begin
Sass::Engine.new("@import nested_bork#{i}", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
rescue Sass::SyntaxError => err
assert_equal(2, err.sass_line)
assert_match(/(\/|^)bork#{i}\.sass$/, err.sass_filename)
assert_hash_has(err.sass_backtrace.first,
:filename => err.sass_filename, :line => err.sass_line)
assert_match(/(\/|^)nested_bork#{i}\.sass$/, err.sass_backtrace[1][:filename])
assert_equal(2, err.sass_backtrace[1][:line])
assert_nil(err.sass_backtrace[2][:filename])
assert_equal(1, err.sass_backtrace[2][:line])
assert_match(/(\/|^)bork#{i}\.sass:2$/, err.backtrace.first)
assert_match(/(\/|^)nested_bork#{i}\.sass:2$/, err.backtrace[1])
assert_equal("(sass):1", err.backtrace[2])
else
assert(false, "Exception not raised for imported template: bork#{i}")
end
end
end
def test_selector_tracing
actual_css = render(<<-SCSS, :syntax => :scss, :trace_selectors => true)
@mixin mixed {
.mixed { color: red; }
}
.context {
@include mixed;
}
SCSS
assert_equal(<<CSS,actual_css)
/* on line 2 of test_selector_tracing_inline.scss, in `mixed'
from line 5 of test_selector_tracing_inline.scss */
.context .mixed {
color: red; }
CSS
end
def test_mixin_exception
render(<<SASS)
=error-mixin($a)
color: $a * 1em * 1px
=outer-mixin($a)
+error-mixin($a)
.error
+outer-mixin(12)
SASS
assert(false, "Exception not raised")
rescue Sass::SyntaxError => err
assert_equal(2, err.sass_line)
assert_equal(filename_for_test, err.sass_filename)
assert_equal("error-mixin", err.sass_mixin)
assert_hash_has(err.sass_backtrace.first, :line => err.sass_line,
:filename => err.sass_filename, :mixin => err.sass_mixin)
assert_hash_has(err.sass_backtrace[1], :line => 5,
:filename => filename_for_test, :mixin => "outer-mixin")
assert_hash_has(err.sass_backtrace[2], :line => 8,
:filename => filename_for_test, :mixin => nil)
assert_equal("#{filename_for_test}:2:in `error-mixin'", err.backtrace.first)
assert_equal("#{filename_for_test}:5:in `outer-mixin'", err.backtrace[1])
assert_equal("#{filename_for_test}:8", err.backtrace[2])
end
def test_mixin_callsite_exception
render(<<SASS)
=one-arg-mixin($a)
color: $a
=outer-mixin($a)
+one-arg-mixin($a, 12)
.error
+outer-mixin(12)
SASS
assert(false, "Exception not raised")
rescue Sass::SyntaxError => err
assert_hash_has(err.sass_backtrace.first, :line => 5,
:filename => filename_for_test, :mixin => "one-arg-mixin")
assert_hash_has(err.sass_backtrace[1], :line => 5,
:filename => filename_for_test, :mixin => "outer-mixin")
assert_hash_has(err.sass_backtrace[2], :line => 8,
:filename => filename_for_test, :mixin => nil)
end
def test_mixin_exception_cssize
render(<<SASS)
=parent-ref-mixin
& foo
a: b
=outer-mixin
+parent-ref-mixin
+outer-mixin
SASS
assert(false, "Exception not raised")
rescue Sass::SyntaxError => err
assert_hash_has(err.sass_backtrace.first, :line => 2,
:filename => filename_for_test, :mixin => "parent-ref-mixin")
assert_hash_has(err.sass_backtrace[1], :line => 6,
:filename => filename_for_test, :mixin => "outer-mixin")
assert_hash_has(err.sass_backtrace[2], :line => 8,
:filename => filename_for_test, :mixin => nil)
end
def test_mixin_and_import_exception
Sass::Engine.new("@import nested_mixin_bork", :load_paths => [File.dirname(__FILE__) + '/templates/']).render
assert(false, "Exception not raised")
rescue Sass::SyntaxError => err
assert_match(/(\/|^)nested_mixin_bork\.sass$/, err.sass_backtrace.first[:filename])
assert_hash_has(err.sass_backtrace.first, :mixin => "error-mixin", :line => 4)
assert_match(/(\/|^)mixin_bork\.sass$/, err.sass_backtrace[1][:filename])
assert_hash_has(err.sass_backtrace[1], :mixin => "outer-mixin", :line => 2)
assert_match(/(\/|^)mixin_bork\.sass$/, err.sass_backtrace[2][:filename])
assert_hash_has(err.sass_backtrace[2], :mixin => nil, :line => 5)
assert_match(/(\/|^)nested_mixin_bork\.sass$/, err.sass_backtrace[3][:filename])
assert_hash_has(err.sass_backtrace[3], :mixin => nil, :line => 6)
assert_hash_has(err.sass_backtrace[4], :filename => nil, :mixin => nil, :line => 1)
end
def test_recursive_mixin
assert_equal <<CSS, render(<<SASS)
.foo .bar .baz {
color: blue; }
.foo .bar .qux {
color: red; }
.foo .zap {
color: green; }
CSS
@mixin map-to-rule($map-or-color)
@if type-of($map-or-color) == map
@each $key, $value in $map-or-color
.\#{$key}
@include map-to-rule($value)
@else
color: $map-or-color
@include map-to-rule((foo: (bar: (baz: blue, qux: red), zap: green)))
SASS
end
def test_double_import_loop_exception
importer = MockImporter.new
importer.add_import("foo", "@import 'bar'")
importer.add_import("bar", "@import 'foo'")
engine = Sass::Engine.new('@import "foo"', :filename => filename_for_test,
:load_paths => [importer], :importer => importer)
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) {engine.render}
An @import loop has been found:
#{filename_for_test} imports foo
foo imports bar
bar imports foo
ERR
end
def test_deep_import_loop_exception
importer = MockImporter.new
importer.add_import("foo", "@import 'bar'")
importer.add_import("bar", "@import 'baz'")
importer.add_import("baz", "@import 'foo'")
engine = Sass::Engine.new('@import "foo"', :filename => filename_for_test,
:load_paths => [importer], :importer => importer)
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) {engine.render}
An @import loop has been found:
#{filename_for_test} imports foo
foo imports bar
bar imports baz
baz imports foo
ERR
end
def test_exception_css_with_offset
opts = {:full_exception => true, :line => 362}
render(("a\n b: c\n" * 10) + "d\n e:\n" + ("f\n g: h\n" * 10), opts)
rescue Sass::SyntaxError => e
assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e, opts[:line]).split("\n")[0..15].join("\n"))
/*
Error: Invalid property: "e:" (no value).
on line 383 of test_exception_css_with_offset_inline.sass
378: a
379: b: c
380: a
381: b: c
382: d
383: e:
384: f
385: g: h
386: f
387: g: h
388: f
CSS
else
assert(false, "Exception not raised for test_exception_css_with_offset")
end
def test_exception_css_with_mixins
render(<<SASS, :full_exception => true)
=error-mixin($a)
color: $a * 1em * 1px
=outer-mixin($a)
+error-mixin($a)
.error
+outer-mixin(12)
SASS
rescue Sass::SyntaxError => e
assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e).split("\n")[0..13].join("\n"))
/*
Error: 12em*px isn't a valid CSS value.
on line 2 of test_exception_css_with_mixins_inline.sass, in `error-mixin'
from line 5 of test_exception_css_with_mixins_inline.sass, in `outer-mixin'
from line 8 of test_exception_css_with_mixins_inline.sass
1: =error-mixin($a)
2: color: $a * 1em * 1px
3:
4: =outer-mixin($a)
5: +error-mixin($a)
6:
7: .error
CSS
else
assert(false, "Exception not raised")
end
def test_cssize_exception_css
render(<<SASS, :full_exception => true)
.filler
stuff: "stuff!"
a: b
.more.filler
a: b
SASS
rescue Sass::SyntaxError => e
assert_equal(<<CSS, Sass::SyntaxError.exception_to_css(e).split("\n")[0..11].join("\n"))
/*
Error: Properties are only allowed within rules, directives, mixin includes, or other properties.
on line 4 of test_cssize_exception_css_inline.sass
1: .filler
2: stuff: "stuff!"
3:
4: a: b
5:
6: .more.filler
7: a: b
CSS
else
assert(false, "Exception not raised")
end
def test_css_import
assert_equal("@import url(./fonts.css);\n", render("@import \"./fonts.css\""))
end
def test_http_import
assert_equal("@import \"http://fonts.googleapis.com/css?family=Droid+Sans\";\n",
render("@import \"http://fonts.googleapis.com/css?family=Droid+Sans\""))
end
def test_protocol_relative_import
assert_equal("@import \"//fonts.googleapis.com/css?family=Droid+Sans\";\n",
render("@import \"//fonts.googleapis.com/css?family=Droid+Sans\""))
end
def test_import_with_interpolation
assert_equal(<<CSS, render(<<SASS))
@import url("http://fonts.googleapis.com/css?family=Droid+Sans");
CSS
$family: unquote("Droid+Sans")
@import url("http://fonts.googleapis.com/css?family=\#{$family}")
SASS
end
def test_import_with_dynamic_media_query
assert_equal(<<CSS, render(<<SASS))
@import "foo" print and (-webkit-min-device-pixel-ratio-foo: 25);
CSS
$media: print
$key: -webkit-min-device-pixel-ratio
$value: 20
@import "foo" \#{$media} and ($key + "-foo": $value + 5)
SASS
end
def test_url_import
assert_equal("@import url(fonts.sass);\n", render("@import url(fonts.sass)"))
end
def test_sass_import
sassc_file = sassc_path("importee")
assert !File.exist?(sassc_file)
renders_correctly "import", { :style => :compact, :load_paths => [File.dirname(__FILE__) + "/templates"] }
assert File.exist?(sassc_file)
end
def test_sass_pathname_import
sassc_file = sassc_path("importee")
assert !File.exist?(sassc_file)
renders_correctly("import",
:style => :compact,
:load_paths => [Pathname.new(File.dirname(__FILE__) + "/templates")])
assert File.exist?(sassc_file)
end
def test_import_from_global_load_paths
importer = MockImporter.new
importer.add_import("imported", "div{color:red}")
Sass.load_paths << importer
assert_equal "div {\n color: red; }\n", Sass::Engine.new('@import "imported"', :importer => importer).render
ensure
Sass.load_paths.clear
end
def test_nonexistent_import
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) do
File to import not found or unreadable: nonexistent.sass.
ERR
render("@import nonexistent.sass")
end
end
def test_nonexistent_extensionless_import
assert_raise_message(Sass::SyntaxError, <<ERR.rstrip) do
File to import not found or unreadable: nonexistent.
ERR
render("@import nonexistent")
end
end
def test_no_cache
assert !File.exist?(sassc_path("importee"))
renders_correctly("import", {
:style => :compact, :cache => false,
:load_paths => [File.dirname(__FILE__) + "/templates"],
})
assert !File.exist?(sassc_path("importee"))
end
def test_import_in_rule
assert_equal(<<CSS, render(<<SASS, :load_paths => [File.dirname(__FILE__) + '/templates/']))
.foo #foo {
background-color: #baf; }
.bar {
a: b; }
.bar #foo {
background-color: #baf; }
CSS
.foo
@import partial
.bar
a: b
@import partial
SASS
end
def test_units
renders_correctly "units"
end
def test_default_function
assert_equal(<<CSS, render(<<SASS))
foo {
bar: url("foo.png"); }
CSS
foo
bar: url("foo.png")
SASS
assert_equal("foo {\n bar: url(); }\n", render("foo\n bar: url()\n"));
end
def test_string_minus
assert_equal("foo {\n bar: baz-boom-bat; }\n", render(%Q{foo\n bar: baz-boom-bat}))
assert_equal("foo {\n bar: -baz-boom; }\n", render(%Q{foo\n bar: -baz-boom}))
end
def test_string_div
assert_equal("foo {\n bar: baz/boom/bat; }\n", render(%Q{foo\n bar: baz/boom/bat}))
assert_equal("foo {\n bar: /baz/boom; }\n", render(%Q{foo\n bar: /baz/boom}))
end
def test_basic_multiline_selector
assert_equal("#foo #bar,\n#baz #boom {\n foo: bar; }\n",
render("#foo #bar,\n#baz #boom\n foo: bar"))
assert_equal("#foo #bar,\n#foo #baz {\n foo: bar; }\n",
render("#foo\n #bar,\n #baz\n foo: bar"))
assert_equal("#foo,\n#bar {\n foo: bar; }\n #foo #baz,\n #bar #baz {\n foo: bar; }\n",
render("#foo,\n#bar\n foo: bar\n #baz\n foo: bar"))
assert_equal("#foo #bar, #baz #boom { foo: bar; }\n",
render("#foo #bar,\n#baz #boom\n foo: bar", :style => :compact))
assert_equal("#foo #bar,#baz #boom{foo:bar}\n",
render("#foo #bar,\n#baz #boom\n foo: bar", :style => :compressed))
assert_equal("#foo #bar,\n#baz #boom {\n foo: bar; }\n",
render("#foo #bar,,\n,#baz #boom,\n foo: bar"))
assert_equal("#bip #bop {\n foo: bar; }\n",
render("#bip #bop,, ,\n foo: bar"))
end
def test_complex_multiline_selector
renders_correctly "multiline"
end
def test_colon_only
begin
render("a\n b: c", :property_syntax => :old)
rescue Sass::SyntaxError => e
assert_equal("Illegal property syntax: can't use new syntax when :property_syntax => :old is set.",
e.message)
assert_equal(2, e.sass_line)
else
assert(false, "SyntaxError not raised for :property_syntax => :old")
end
begin
silence_warnings {render("a\n :b c", :property_syntax => :new)}
assert_equal(2, e.sass_line)
rescue Sass::SyntaxError => e
assert_equal("Illegal property syntax: can't use old syntax when :property_syntax => :new is set.",
e.message)
else
assert(false, "SyntaxError not raised for :property_syntax => :new")
end
end
def test_pseudo_elements
assert_equal(<<CSS, render(<<SASS))
::first-line {
size: 10em; }
CSS
::first-line
size: 10em
SASS
end
def test_directive
assert_equal("@a b;\n", render("@a b"))
assert_equal("@a {\n b: c; }\n", render("@a\n b: c"))
assert_equal("@a { b: c; }\n", render("@a\n b: c", :style => :compact))
assert_equal("@a {\n b: c;\n}\n", render("@a\n b: c", :style => :expanded))
assert_equal("@a{b:c}\n", render("@a\n b: c", :style => :compressed))
assert_equal("@a {\n b: c;\n d: e; }\n",
render("@a\n b: c\n d: e"))
assert_equal("@a { b: c; d: e; }\n",
render("@a\n b: c\n d: e", :style => :compact))
assert_equal("@a {\n b: c;\n d: e;\n}\n",
render("@a\n b: c\n d: e", :style => :expanded))
assert_equal("@a{b:c;d:e}\n",
render("@a\n b: c\n d: e", :style => :compressed))
assert_equal("@a {\n #b {\n c: d; } }\n",
render("@a\n #b\n c: d"))
assert_equal("@a { #b { c: d; } }\n",
render("@a\n #b\n c: d", :style => :compact))
assert_equal("@a {\n #b {\n c: d;\n }\n}\n",
render("@a\n #b\n c: d", :style => :expanded))
assert_equal("@a{#b{c:d}}\n",
render("@a\n #b\n c: d", :style => :compressed))
assert_equal("@a {\n #b {\n a: b; }\n #b #c {\n d: e; } }\n",
render("@a\n #b\n a: b\n #c\n d: e"))
assert_equal("@a { #b { a: b; }\n #b #c { d: e; } }\n",
render("@a\n #b\n a: b\n #c\n d: e", :style => :compact))
assert_equal("@a {\n #b {\n a: b;\n }\n #b #c {\n d: e;\n }\n}\n",
render("@a\n #b\n a: b\n #c\n d: e", :style => :expanded))
assert_equal("@a{#b{a:b}#b #c{d:e}}\n",
render("@a\n #b\n a: b\n #c\n d: e", :style => :compressed))
assert_equal("@a {\n #foo,\n #bar {\n b: c; } }\n",
render("@a\n #foo, \n #bar\n b: c"))
assert_equal("@a { #foo, #bar { b: c; } }\n",
render("@a\n #foo, \n #bar\n b: c", :style => :compact))
assert_equal("@a {\n #foo,\n #bar {\n b: c;\n }\n}\n",
render("@a\n #foo, \n #bar\n b: c", :style => :expanded))
assert_equal("@a{#foo,#bar{b:c}}\n",
render("@a\n #foo, \n #bar\n b: c", :style => :compressed))
to_render = <<END
@a
b: c
#d
e: f
g: h
END
rendered = <<END
@a { b: c;
#d { e: f; }
g: h; }
END
assert_equal(rendered, render(to_render, :style => :compact))
assert_equal("@a{b:c;#d{e:f}g:h}\n", render(to_render, :style => :compressed))
end
def test_property_hacks
assert_equal(<<CSS, render(<<SASS))
foo {
_name: val;
*name: val;
#name: val;
.name: val;
name/**/: val;
name/*\\**/: val;
name: val; }
CSS
foo
_name: val
*name: val
#name: val
.name: val
name/**/: val
name/*\\**/: val
name: val
SASS
end
def test_properties_with_space_after_colon
assert_equal <<CSS, render(<<SASS)
foo {
bar: baz;
bizz: bap; }
CSS
foo
bar : baz
bizz : bap
SASS
end
def test_line_annotations
assert_equal(<<CSS, render(<<SASS, :line_comments => true, :style => :compact))
/* line 2, test_line_annotations_inline.sass */
foo bar { foo: bar; }
/* line 5, test_line_annotations_inline.sass */
foo baz { blip: blop; }
/* line 9, test_line_annotations_inline.sass */
floodle { flop: blop; }
/* line 18, test_line_annotations_inline.sass */
bup { mix: on; }
/* line 15, test_line_annotations_inline.sass */
bup mixin { moop: mup; }
/* line 22, test_line_annotations_inline.sass */
bip hop, skip hop { a: b; }
CSS
foo
bar
foo: bar
baz
blip: blop
floodle
flop: blop
=mxn
mix: on
mixin
moop: mup
bup
+mxn
bip, skip
hop
a: b
SASS
end
def test_line_annotations_with_filename
renders_correctly "line_numbers", :line_comments => true, :load_paths => [File.dirname(__FILE__) + "/templates"]
end
def test_debug_info
return skip "temporarily skip for Debian"
esc_file_name = Sass::SCSS::RX.escape_ident(Sass::Util.scope("test_debug_info_inline.sass"))
assert_equal(<<CSS, render(<<SASS, :debug_info => true, :style => :compact))
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000032}}
foo bar { foo: bar; }
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000035}}
foo baz { blip: blop; }
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000039}}
floodle { flop: blop; }
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\0000318}}
bup { mix: on; }
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\0000315}}
bup mixin { moop: mup; }
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\0000322}}
bip hop, skip hop { a: b; }
CSS
foo
bar
foo: bar
baz
blip: blop
floodle
flop: blop
=mxn
mix: on
mixin
moop: mup
bup
+mxn
bip, skip
hop
a: b
SASS
end
def test_debug_info_without_filename
assert_equal(<<CSS, Sass::Engine.new(<<SASS, :debug_info => true).render)
@media -sass-debug-info{filename{}line{font-family:\\000031}}
foo {
a: b; }
CSS
foo
a: b
SASS
end
def test_debug_info_with_compressed
assert_equal(<<CSS, render(<<SASS, :debug_info => true, :style => :compressed))
foo{a:b}
CSS
foo
a: b
SASS
end
def test_debug_info_with_line_annotations
return skip "temporarily skip for Debian"
esc_file_name = Sass::SCSS::RX.escape_ident(Sass::Util.scope("test_debug_info_with_line_annotations_inline.sass"))
assert_equal(<<CSS, render(<<SASS, :debug_info => true, :line_comments => true))
@media -sass-debug-info{filename{font-family:file\\:\\/\\/#{esc_file_name}}line{font-family:\\000031}}
foo {
a: b; }
CSS
foo
a: b
SASS
end
def test_debug_info_in_keyframes
assert_equal(<<CSS, render(<<SASS, :debug_info => true))
@-webkit-keyframes warm {
from {
color: black; }
to {
color: red; } }
CSS
@-webkit-keyframes warm
from
color: black
to
color: red
SASS
end
def test_empty_first_line
assert_equal("#a {\n b: c; }\n", render("#a\n\n b: c"))
end
def test_escaped_rule
assert_equal(":focus {\n a: b; }\n", render("\\:focus\n a: b"))
assert_equal("a {\n b: c; }\n a :focus {\n d: e; }\n", render("\\a\n b: c\n \\:focus\n d: e"))
end
def test_cr_newline
assert_equal("foo {\n a: b;\n c: d;\n e: f; }\n", render("foo\r a: b\r\n c: d\n\r e: f"))
end
def test_property_with_content_and_nested_props
assert_equal(<<CSS, render(<<SASS))
foo {
a: b;
a-c: d;
a-c-e: f; }
CSS
foo
a: b
c: d
e: f
SASS
assert_equal(<<CSS, render(<<SASS))
foo {
a: b;
a-c-e: f; }
CSS
foo
a: b
c:
e: f
SASS
end
def test_guarded_assign
assert_equal("foo {\n a: b; }\n", render(%Q{$foo: b\n$foo: c !default\nfoo\n a: $foo}))
assert_equal("foo {\n a: b; }\n", render(%Q{$foo: b !default\nfoo\n a: $foo}))
assert_equal("foo {\n a: b; }\n", render(%Q{$foo: null\n$foo: b !default\nfoo\n a: $foo}))
end
def test_mixins
renders_correctly "mixins", { :style => :expanded }
end
def test_directive_style_mixins
assert_equal <<CSS, render(<<SASS)
bar {
prop: baz; }
CSS
@mixin foo($arg)
prop: $arg
bar
@include foo(baz)
SASS
end
def test_mixins_dont_interfere_with_sibling_combinator
assert_equal("foo + bar {\n a: b; }\nfoo + baz {\n c: d; }\n",
render("foo\n +\n bar\n a: b\n baz\n c: d"))
end
def test_mixin_args
assert_equal("blat {\n baz: hi; }\n", render(<<SASS))
=foo($bar)
baz: $bar
blat
+foo(hi)
SASS
assert_equal("blat {\n baz: 3; }\n", render(<<SASS))
=foo($a, $b)
baz: $a + $b
blat
+foo(1, 2)
SASS
assert_equal("blat {\n baz: 4;\n baz: 3;\n baz: 5;\n bang: 3; }\n", render(<<SASS))
=foo($c: (6 + 4) / 2)
baz: $c
$c: 3
blat
+foo($c + 1)
+foo(($c + 3)/2)
+foo
bang: $c
SASS
end
def test_default_values_for_mixin_arguments
assert_equal(<<CSS, render(<<SASS))
white {
color: #FFF; }
black {
color: #000; }
CSS
=foo($a: #FFF)
color: $a
white
+foo
black
+foo(#000)
SASS
assert_equal(<<CSS, render(<<SASS))
one {
color: #fff;
padding: 1px;
margin: 4px; }
two {
color: #fff;
padding: 2px;
margin: 5px; }
three {
color: #fff;
padding: 2px;
margin: 3px; }
CSS
$a: 5px
=foo($a, $b: 1px, $c: 3px + $b)
color: $a
padding: $b
margin: $c
one
+foo(#fff)
two
+foo(#fff, 2px)
three
+foo(#fff, 2px, 3px)
SASS
assert_equal(<<CSS, render(<<SASS))
one {
color: #fff;
padding: 1px;
margin: 4px; }
two {
color: #fff;
padding: 2px;
margin: 5px; }
three {
color: #fff;
padding: 2px;
margin: 3px; }
CSS
$a: 5px
=foo($a, $b: 1px, $c: null)
$c: 3px + $b !default
color: $a
padding: $b
margin: $c
one
+foo(#fff)
two
+foo(#fff, 2px)
three
+foo(#fff, 2px, 3px)
SASS
end
def test_hyphen_underscore_insensitive_mixins
assert_equal(<<CSS, render(<<SASS))
a {
b: 12;
c: foo; }
CSS
=mixin-hyphen
b: 12
=mixin_under
c: foo
a
+mixin_hyphen
+mixin-under
SASS
end
def test_css_identifier_mixin
assert_equal(<<CSS, render(<<SASS))
a {
foo: 12; }
CSS
=\\{foo\\(12\\)($a)
foo: $a
a
+\\{foo\\(12\\)(12)
SASS
end
def test_basic_function
assert_equal(<<CSS, render(<<SASS))
bar {
a: 3; }
CSS
@function foo()
@return 1 + 2
bar
a: foo()
SASS
end
def test_function_args
assert_equal(<<CSS, render(<<SASS))
bar {
a: 3; }
CSS
@function plus($var1, $var2)
@return $var1 + $var2
bar
a: plus(1, 2)
SASS
end
def test_function_arg_default
assert_equal(<<CSS, render(<<SASS))
bar {
a: 3; }
CSS
@function plus($var1, $var2: 2)
@return $var1 + $var2
bar
a: plus(1)
SASS
end
def test_function_arg_keyword
assert_equal(<<CSS, render(<<SASS))
bar {
a: 1bar; }
CSS
@function plus($var1: 1, $var2: 2)
@return $var1 + $var2
bar
a: plus($var2: bar)
SASS
end
def test_function_with_missing_argument
render(<<SASS)
@function plus($var1, $var2)
@return $var1 + $var2
bar
a: plus($var2: bar)
SASS
flunk("Expected exception")
rescue Sass::SyntaxError => e
assert_equal("Function plus is missing argument $var1.", e.message)
end
def test_function_with_extra_argument
render(<<SASS)
@function plus($var1, $var2)
@return $var1 + $var2
bar
a: plus($var1: foo, $var2: bar, $var3: baz)
SASS
flunk("Expected exception")
rescue Sass::SyntaxError => e
assert_equal("Function plus doesn't have an argument named $var3.", e.message)
end
def test_function_with_positional_and_keyword_argument
render(<<SASS)
@function plus($var1, $var2)
@return $var1 + $var2
bar
a: plus(foo, bar, $var2: baz)
SASS
flunk("Expected exception")
rescue Sass::SyntaxError => e
assert_equal("Function plus was passed argument $var2 both by position and by name.", e.message)
end
def test_function_with_keyword_before_positional_argument
render(<<SASS)
@function plus($var1, $var2)
@return $var1 + $var2
bar
a: plus($var2: foo, bar)
SASS
flunk("Expected exception")
rescue Sass::SyntaxError => e
assert_equal("Positional arguments must come before keyword arguments.", e.message)
end
def test_function_with_if
assert_equal(<<CSS, render(<<SASS))
bar {
a: foo;
b: bar; }
CSS
@function my-if($cond, $val1, $val2)
@if $cond
@return $val1
@else
@return $val2
bar
a: my-if(true, foo, bar)
b: my-if(false, foo, bar)
SASS
end
def test_function_with_var
assert_equal(<<CSS, render(<<SASS))
bar {
a: 1; }
CSS
@function foo($val1, $val2)
$intermediate: $val1 + $val2
@return $intermediate/3
bar
a: foo(1, 2)
SASS
end
def test_user_defined_function_variable_scope
render(<<SASS)
bar
-no-op: set-a-variable(variable, 5)
a: $variable
SASS
flunk("Exception not raised for test_user_defined_function_variable_scope")
rescue Sass::SyntaxError => e
assert_equal('Undefined variable: "$variable".', e.message)
end
def test_user_defined_function_can_change_global_variable
assert_equal(<<CSS, render(<<SASS))
bar {
a: 5; }
CSS
$variable: 0
bar
$local: 10
-no-op: set-a-global-variable(variable, 5)
a: $variable
SASS
end
def test_user_defined_function_cannot_read_local_variable
assert_equal(<<CSS, render(<<SASS))
bar {
global: 0;
local: undefined; }
CSS
$global: 0
bar
$local: 10
global: get-a-variable(global)
local: get-a-variable(local)
SASS
end
def test_control_directive_in_nested_property
assert_equal(<<CSS, render(<<SASS))
foo {
a-b: c; }
CSS
foo
a:
@if true
b: c
SASS
end
def test_interpolation
assert_equal("a-1 {\n b-2-3: c-3; }\n", render(<<SASS))
$a: 1
$b: 2
$c: 3
a-\#{$a}
b-\#{$b}-\#{$c}: c-\#{$a + $b}
SASS
end
def test_complex_property_interpolation
assert_equal(<<CSS, render(<<SASS))
a-1 {
b-2 3-fizzap18: c-3; }
CSS
$a: 1
$b: 2
$c: 3
a-\#{$a}
b-\#{$b $c}-\#{fizzap + ($c + 15)}: c-\#{$a + $b}
SASS
end
def test_if_directive
assert_equal("a {\n b: 1; }\n", render(<<SASS))
$var: true
a
@if $var
b: 1
@if not $var
b: 2
SASS
assert_equal("a {\n b: 2; }\n", render(<<SASS))
$var: null
a
@if $var
b: 1
@if not $var
b: 2
SASS
end
def test_for
assert_equal(<<CSS, render(<<SASS))
a-0 {
two-i: 0; }
a-1 {
two-i: 2; }
a-2 {
two-i: 4; }
a-3 {
two-i: 6; }
b-1 {
j-1: 0; }
b-2 {
j-1: 1; }
b-3 {
j-1: 2; }
b-4 {
j-1: 3; }
CSS
$a: 3
@for $i from 0 to $a + 1
a-\#{$i}
two-i: 2 * $i
@for $j from 1 through 4
b-\#{$j}
j-1: $j - 1
SASS
end
def test_while
assert_equal(<<CSS, render(<<SASS))
a-5 {
blooble: gloop; }
a-4 {
blooble: gloop; }
a-3 {
blooble: gloop; }
a-2 {
blooble: gloop; }
a-1 {
blooble: gloop; }
CSS
$a: 5
@while $a != 0
a-\#{$a}
blooble: gloop
$a: $a - 1 !global
SASS
end
def test_else
assert_equal(<<CSS, render(<<SASS))
a {
t1: t;
t2: t;
t3: t;
t4: t; }
CSS
a
@if true
t1: t
@else
f1: f
@if false
f2: f
@else
t2: t
@if false
f3: f1
@else if 1 + 1 == 3
f3: f2
@else
t3: t
@if false
f4: f1
@else if 1 + 1 == 2
t4: t
@else
f4: f2
@if false
f5: f1
@else if false
f5: f2
SASS
end
def test_each
assert_equal(<<CSS, render(<<SASS))
a {
b: 1px;
b: 2px;
b: 3px;
b: 4px;
c: foo;
c: bar;
c: baz;
c: bang;
d: blue; }
CSS
a
@each $number in 1px 2px 3px 4px
b: $number
@each $str in foo, bar, baz, bang
c: $str
@each $single in blue
d: $single
SASS
end
def test_destructuring_each
assert_equal <<CSS, render(<<SCSS)
a {
foo: 1px;
bar: 2px;
baz: 3px; }
c {
foo: "Value is bar";
bar: "Value is baz";
bang: "Value is "; }
CSS
a
@each $name, $number in (foo: 1px, bar: 2px, baz: 3px)
\#{$name}: $number
c
@each $key, $value in (foo bar) (bar, baz) bang
\#{$key}: "Value is \#{$value}"
SCSS
end
def test_variable_reassignment
assert_equal(<<CSS, render(<<SASS))
a {
b: 1;
c: 2; }
CSS
a
$a: 1
b: $a
$a: 2
c: $a
SASS
end
def test_hyphen_underscore_insensitive_variables
assert_equal(<<CSS, render(<<SASS))
d {
e: 13;
f: foobar; }
CSS
$var-hyphen: 12
$var_under: foo
$var_hyphen: 1 + $var_hyphen
$var-under: $var-under + bar
d
e: $var-hyphen
f: $var_under
SASS
end
def test_css_identifier_variable
assert_equal(<<CSS, render(<<SASS))
a {
b: 12; }
CSS
$\\{foo\\(12\\): 12
a
b: $\\{foo\\(12\\)
SASS
end
def test_important
assert_equal(<<CSS, render(<<SASS))
a {
b: 12px !important; }
CSS
$foo: 12px
a
b: $foo !important
SASS
end
def test_argument_error
assert_raises(Sass::SyntaxError) { render("a\n b: hsl(1)") }
end
def test_comments_at_the_top_of_a_document
render(<<SASS)
//
This is a comment that
continues to the second line.
foo
bar: baz
SASS
end
def test_loud_comments_containing_a_comment_close
actual_css = render(<<SASS)
/*
This is a comment that
continues to the second line. */
foo
bar: baz
SASS
assert_equal(<<CSS, actual_css)
/* This is a comment that
* continues to the second line. */
foo {
bar: baz; }
CSS
end
def test_loud_comments_with_starred_lines
assert_equal(<<CSS, render(<<SASS))
/* This is a comment that
* continues to the second line.
* And even to the third! */
CSS
/* This is a comment that
* continues to the second line.
* And even to the third!
SASS
end
def test_loud_comments_with_no_space_after_starred_lines
assert_equal(<<CSS, render(<<SASS))
/*bip bop
*beep boop
*bap blimp */
CSS
/*bip bop
*beep boop
*bap blimp
SASS
end
def test_comment_indentation_at_beginning_of_doc
assert_equal <<CSS, render(<<SASS)
/* foo
* bar
* baz */
foo {
a: b; }
CSS
/* foo
bar
baz
foo
a: b
SASS
end
def test_unusual_comment_indentation
assert_equal <<CSS, render(<<SASS)
foo {
/* foo
* bar
* baz */ }
CSS
foo
/* foo
bar
baz
SASS
end
def test_loud_comment_with_close
assert_equal <<CSS, render(<<SASS)
foo {
/* foo
* bar */ }
CSS
foo
/* foo
bar */
SASS
end
def test_loud_comment_with_separate_line_close
assert_equal <<CSS, render(<<SASS)
foo {
/* foo
* bar
*/ }
CSS
foo
/* foo
* bar
*/
SASS
end
def test_loud_comment_in_compressed_mode
assert_equal <<CSS, render(<<SASS, :style => :compressed)
foo{color:blue;/*! foo
* bar
*/}
CSS
foo
color: blue
/*! foo
* bar
*/
SASS
end
def test_loud_comment_is_evaluated
assert_equal <<CSS, render(<<SASS)
/*! Hue: 327.2164948454deg */
CSS
/*! Hue: \#{hue(#f836a0)}
SASS
end
def test_attribute_selector_with_spaces
assert_equal(<<CSS, render(<<SASS))
a b[foo=bar] {
c: d; }
CSS
a
b[foo = bar]
c: d
SASS
end
def test_quoted_colon
assert_equal(<<CSS, render(<<SASS))
a b[foo="bar: baz"] {
c: d; }
CSS
a
b[foo="bar: baz"]
c: d
SASS
end
def test_quoted_comma
assert_equal(<<CSS, render(<<SASS))
a b[foo="bar, baz"] {
c: d; }
CSS
a
b[foo="bar, baz"]
c: d
SASS
end
def test_quoted_ampersand
assert_equal(<<CSS, render(<<SASS))
a b[foo="bar & baz"] {
c: d; }
CSS
a
b[foo="bar & baz"]
c: d
SASS
end
def test_empty_selector_warning
assert_warning(<<END) {render("foo bar")}
WARNING on line 1 of test_empty_selector_warning_inline.sass:
This selector doesn't have any properties and will not be rendered.
END
end
def test_nonprinting_empty_property
assert_equal(<<CSS, render(<<SASS))
a {
c: "";
e: f; }
CSS
$null-value: null
$empty-string: ''
$empty-list: (null)
a
b: $null-value
c: $empty-string
d: $empty-list
e: f
g
h: null
SASS
end
def test_root_level_pseudo_class_with_new_properties
assert_equal(<<CSS, render(<<SASS, :property_syntax => :new))
:focus {
outline: 0; }
CSS
:focus
outline: 0
SASS
end
def test_pseudo_class_with_new_properties
assert_equal(<<CSS, render(<<SASS, :property_syntax => :new))
p :focus {
outline: 0; }
CSS
p
:focus
outline: 0
SASS
end
def test_nil_option
assert_equal(<<CSS, render(<<SASS, :format => nil))
foo {
a: b; }
CSS
foo
a: b
SASS
end
def test_interpolation_in_raw_functions
assert_equal(<<CSS, render(<<SASS))
foo {
filter: progid:Microsoft.foo.bar.Baz(flip=foobar, bang=#00ff00cc); }
CSS
foo
filter: progid:Microsoft.foo.bar.Baz(flip=\#{foo + bar}, bang=#00ff00cc)
SASS
end
# SassScript string behavior
def test_plus_preserves_quotedness
assert_equal(<<CSS, render(<<SASS))
foo {
a: "foo1";
b: "1foo";
c: foo1;
d: 1foo;
e: "foobar";
f: foobar; }
CSS
foo
a: "foo" + 1
b: 1 + "foo"
c: foo + 1
d: 1 + foo
e: "foo" + bar
f: foo + "bar"
SASS
end
def test_colon_properties_preserve_quotedness
assert_equal(<<CSS, render(<<SASS))
foo {
a: "foo";
b: bar;
c: "foo" bar;
d: foo, "bar"; }
CSS
foo
a: "foo"
b: bar
c: "foo" bar
d: foo, "bar"
SASS
end
def test_colon_variables_preserve_quotedness
assert_equal(<<CSS, render(<<SASS))
foo {
a: "foo";
b: bar; }
CSS
$a: "foo"
$b: bar
foo
a: $a
b: $b
SASS
end
def test_colon_args_preserve_quotedness
assert_equal(<<CSS, render(<<SASS))
foo {
a: "foo";
b: bar;
c: "foo" bar;
d: foo, "bar"; }
CSS
=foo($a: "foo", $b: bar, $c: "foo" bar, $d: (foo, "bar"))
foo
a: $a
b: $b
c: $c
d: $d
+foo
SASS
end
def test_interpolation_unquotes_strings
assert_equal(<<CSS, render(<<SASS))
.foo-bar {
a: b; }
CSS
.foo-\#{"bar"}
a: b
SASS
assert_equal(<<CSS, render(<<SASS))
.foo {
a: b c; }
CSS
.foo
a: b \#{"c"}
SASS
end
def test_interpolation_unquotes_strings_in_vars
assert_equal(<<CSS, render(<<SASS))
.foo-bar {
a: b; }
CSS
$var: "bar"
.foo-\#{$var}
a: b
SASS
end
def test_interpolation_deep_unquotes_strings
assert_equal(<<CSS, render(<<SASS))
.foo {
a: bar baz; }
CSS
.foo
a: \#{"bar" "baz"}
SASS
end
def test_warn_directive
expected_warning = <<EXPECTATION
WARNING: this is a warning
on line 4 of test_warn_directive_inline.sass
WARNING: this is a mixin warning
on line 2 of test_warn_directive_inline.sass, in `foo'
from line 7 of test_warn_directive_inline.sass
EXPECTATION
assert_warning expected_warning do
assert_equal <<CSS, render(<<SASS)
bar {
c: d; }
CSS
=foo
@warn "this is a mixin warning"
@warn "this is a warning"
bar
c: d
+foo
SASS
end
end
def test_warn_directive_when_quiet
assert_warning "" do
assert_equal <<CSS, render(<<SASS, :quiet => true)
CSS
@warn "this is a warning"
SASS
end
end
def test_warn_with_imports
prefix = Sass::Util.cleanpath(File.dirname(__FILE__)).to_s
expected_warning = <<WARN
WARNING: In the main file
on line 1 of #{prefix}/templates/warn.sass
WARNING: Imported
on line 1 of #{prefix}/templates/warn_imported.sass
from line 2 of #{prefix}/templates/warn.sass
WARNING: In an imported mixin
on line 4 of #{prefix}/templates/warn_imported.sass, in `emits-a-warning'
from line 3 of #{prefix}/templates/warn.sass
WARN
assert_warning expected_warning do
renders_correctly "warn", :style => :compact, :load_paths => ["#{prefix}/templates"]
end
end
def test_media_bubbling
assert_equal <<CSS, render(<<SASS)
.foo {
a: b; }
@media bar {
.foo {
c: d; } }
.foo .baz {
e: f; }
@media bip {
.foo .baz {
g: h; } }
.other {
i: j; }
CSS
.foo
a: b
@media bar
c: d
.baz
e: f
@media bip
g: h
.other
i: j
SASS
assert_equal <<CSS, render(<<SASS, :style => :compact)
.foo { a: b; }
@media bar { .foo { c: d; } }
.foo .baz { e: f; }
@media bip { .foo .baz { g: h; } }
.other { i: j; }
CSS
.foo
a: b
@media bar
c: d
.baz
e: f
@media bip
g: h
.other
i: j
SASS
assert_equal <<CSS, render(<<SASS, :style => :expanded)
.foo {
a: b;
}
@media bar {
.foo {
c: d;
}
}
.foo .baz {
e: f;
}
@media bip {
.foo .baz {
g: h;
}
}
.other {
i: j;
}
CSS
.foo
a: b
@media bar
c: d
.baz
e: f
@media bip
g: h
.other
i: j
SASS
end
def test_double_media_bubbling
assert_equal <<CSS, render(<<SASS)
@media bar and (a: b) {
.foo {
c: d; } }
CSS
@media bar
@media (a: b)
.foo
c: d
SASS
assert_equal <<CSS, render(<<SASS)
@media bar {
.foo {
a: b; } }
@media bar and (a: b) {
.foo {
c: d; } }
CSS
.foo
@media bar
a: b
@media (a: b)
c: d
SASS
end
def test_double_media_bubbling_with_commas
assert_equal <<CSS, render(<<SASS)
@media (a: b) and (e: f), (c: d) and (e: f), (a: b) and (g: h), (c: d) and (g: h) {
.foo {
c: d; } }
CSS
@media (a: b), (c: d)
@media (e: f), (g: h)
.foo
c: d
SASS
end
def test_double_media_bubbling_with_surrounding_rules
assert_equal <<CSS, render(<<SASS)
@media (min-width: 0) {
a {
a: a; }
b {
before: b;
after: b; } }
@media (min-width: 0) and (max-width: 5000px) {
b {
x: x; } }
@media (min-width: 0) {
c {
c: c; } }
CSS
@media (min-width: 0)
a
a: a
b
before: b
@media (max-width: 5000px)
x: x
after: b
c
c: c
SASS
end
def test_rule_media_rule_bubbling
assert_equal <<CSS, render(<<SASS)
@media bar {
.foo {
a: b;
e: f; }
.foo .baz {
c: d; } }
CSS
.foo
@media bar
a: b
.baz
c: d
e: f
SASS
end
def test_nested_media_around_properties
assert_equal <<CSS, render(<<SASS)
.outside {
color: red;
background: blue; }
@media print {
.outside {
color: black; } }
@media print and (a: b) {
.outside .inside {
border: 1px solid black; } }
.outside .middle {
display: block; }
CSS
.outside
color: red
@media print
color: black
.inside
@media (a: b)
border: 1px solid black
background: blue
.middle
display: block
SASS
end
def test_media_with_parent_references
sass_str = <<SASS
.outside
@media print
&.inside
border: 1px solid black
SASS
css_str = <<CSS
@media print {
.outside.inside {
border: 1px solid black; } }
CSS
assert_equal css_str, render(sass_str)
end
def test_eliminated_media_bubbling
assert_equal <<CSS, render(<<SASS)
@media screen {
a: b; }
CSS
@media screen
a: b
@media print
c: d
SASS
assert_equal <<CSS, render(<<SASS)
@media not print {
a: b; }
CSS
@media not print
a: b
@media print
c: d
SASS
assert_equal <<CSS, render(<<SASS)
@media not print {
a: b; }
CSS
@media not print
a: b
@media not screen
c: d
SASS
end
def test_non_eliminated_media_bubbling
assert_equal <<CSS, render(<<SASS)
@media screen {
a: b; }
@media screen and (a: b) {
c: d; }
CSS
@media screen
a: b
@media screen and (a: b)
c: d
SASS
assert_equal <<CSS, render(<<SASS)
@media not print {
a: b; }
@media screen {
c: d; }
CSS
@media not print
a: b
@media screen
c: d
SASS
assert_equal <<CSS, render(<<SASS)
@media only screen {
a: b; }
@media only screen and (a: b) {
c: d; }
CSS
@media only screen
a: b
@media screen and (a: b)
c: d
SASS
end
def test_directive_interpolation
assert_equal <<CSS, render(<<SASS)
@foo bar12 qux {
a: b; }
CSS
$baz: 12
@foo bar\#{$baz} qux
a: b
SASS
end
def test_media_interpolation
assert_equal <<CSS, render(<<SASS)
@media bar12 {
a: b; }
CSS
$baz: 12
@media bar\#{$baz}
a: b
SASS
end
def test_variables_in_media
assert_equal <<CSS, render(<<SASS)
@media screen and (-webkit-min-device-pixel-ratio-foo: 25), only print {
a: b; }
CSS
$media1: screen
$media2: print
$var: -webkit-min-device-pixel-ratio
$val: 20
@media \#{$media1} and ($var + "-foo": $val + 5), only \#{$media2}
a: b
SASS
end
def test_at_root
assert_equal <<CSS, render(<<SASS)
.bar {
a: b; }
CSS
.foo
@at-root
.bar
a: b
SASS
end
def test_at_root_with_selector
assert_equal <<CSS, render(<<SASS)
.bar {
a: b; }
CSS
.foo
@at-root .bar
a: b
SASS
end
def test_at_root_with_query
assert_equal <<CSS, render(<<SASS)
.foo .bar {
a: b; }
CSS
.foo
@media screen
@at-root (without: media)
.bar
a: b
SASS
end
def test_variable_assignment_with_global
assert_no_warning {assert_equal(<<CSS, render(<<SASS))}
.foo {
a: x; }
.bar {
b: x; }
CSS
$var: 1
.foo
$var: x !global
a: $var
.bar
b: $var
SASS
end
# Regression tests
def test_interpolation_in_multiline_selector
assert_equal(<<CSS, render(<<SASS))
.foo,
.bar {
a: b; }
CSS
.foo,
\#{".bar"}
a: b
SASS
end
def test_list_separator_with_arg_list
assert_equal(<<CSS, render(<<SASS))
.test {
separator: comma; }
CSS
@mixin arglist-test($args...)
separator: list-separator($args)
.test
@include arglist-test(this, is, comma, separated)
SASS
end
def test_parent_mixin_in_content_nested
assert_equal(<<CSS, render(<<SASS))
a {
b: c; }
CSS
=foo
@content
=bar
+foo
+foo
a
b: c
+bar
SASS
end
def test_supports_bubbles
assert_equal <<CSS, render(<<SASS)
parent {
background: orange; }
@supports (perspective: 10px) or (-moz-perspective: 10px) {
parent child {
background: blue; } }
CSS
parent
background: orange
@supports (perspective: 10px) or (-moz-perspective: 10px)
child
background: blue
SASS
end
def test_line_numbers_with_dos_line_endings
assert_equal <<CSS, render(<<SASS, :line_comments => true)
/* line 5, test_line_numbers_with_dos_line_endings_inline.sass */
.foo {
a: b; }
CSS
\r
\r
\r
\r
.foo
a: b
SASS
end
def test_variable_in_media_in_mixin
assert_equal <<CSS, render(<<SASS)
@media screen and (min-width: 10px) {
body {
background: red; } }
@media screen and (min-width: 20px) {
body {
background: blue; } }
CSS
@mixin respond-to($width)
@media screen and (min-width: $width)
@content
body
@include respond-to(10px)
background: red
@include respond-to(20px)
background: blue
SASS
end
def test_interpolated_comment_in_mixin
assert_equal <<CSS, render(<<SASS)
/*! color: red */
.foo {
color: red; }
/*! color: blue */
.foo {
color: blue; }
/*! color: green */
.foo {
color: green; }
CSS
=foo($var)
/*! color: \#{$var}
.foo
color: $var
+foo(red)
+foo(blue)
+foo(green)
SASS
end
def test_parens_in_mixins
assert_equal(<<CSS, render(<<SASS))
.foo {
color: #01ff7f;
background-color: #000102; }
CSS
=foo($c1, $c2: rgb(0, 1, 2))
color: $c1
background-color: $c2
.foo
+foo(rgb(1,255,127))
SASS
end
def test_comment_beneath_prop
assert_equal(<<RESULT, render(<<SOURCE))
.box {
border-style: solid; }
RESULT
.box
border:
//color: black
style: solid
SOURCE
assert_equal(<<RESULT, render(<<SOURCE))
.box {
/* color: black */
border-style: solid; }
RESULT
.box
border:
/* color: black
style: solid
SOURCE
assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
.box{border-style:solid}
RESULT
.box
border:
/*color: black
style: solid
SOURCE
end
def test_compressed_comment_beneath_directive
assert_equal(<<RESULT, render(<<SOURCE, :style => :compressed))
@foo{a:b}
RESULT
@foo
a: b
/*b: c
SOURCE
end
def test_comment_with_crazy_indentation
assert_equal(<<CSS, render(<<SASS))
/* This is a loud comment:
* Where the indentation is wonky. */
.comment {
width: 1px; }
CSS
/*
This is a loud comment:
Where the indentation is wonky.
//
This is a silent comment:
Where the indentation is wonky.
.comment
width: 1px
SASS
end
def test_plus_with_space
assert_equal(<<CSS, render(<<SASS))
a + b {
color: green; }
CSS
a
+ b
color: green
SASS
end
def test_empty_line_comment
assert_equal(<<CSS, render(<<SASS))
/* Foo
*
* Bar */
CSS
/*
Foo
Bar
SASS
end
def test_empty_comment
assert_equal(<<CSS, render(<<SASS))
/* */
a {
/* */
b: c; }
CSS
/*
a
/*
b: c
SASS
end
def test_options_available_in_environment
assert_equal(<<CSS, render(<<SASS))
a {
b: nested; }
CSS
a
b: option("style")
SASS
end
def test_import_with_commas_in_url
assert_equal <<CSS, render(<<SASS)
@import url(foo.css?bar,baz);
CSS
@import url(foo.css?bar,baz)
SASS
end
def test_silent_comment_in_prop_val_after_important
assert_equal(<<CSS, render(<<SASS))
.advanced {
display: none !important; }
CSS
.advanced
display: none !important // yeah, yeah. it's not really a style anyway.
SASS
end
def test_mixin_with_keyword_args
assert_equal <<CSS, render(<<SASS)
.mixed {
required: foo;
arg1: default-val1;
arg2: non-default-val2; }
CSS
=a-mixin($required, $arg1: default-val1, $arg2: default-val2)
required: $required
arg1: $arg1
arg2: $arg2
.mixed
+a-mixin(foo, $arg2: non-default-val2)
SASS
end
def test_mixin_with_keyword_arg_variable_value
assert_equal <<CSS, render(<<SASS)
.mixed {
required: foo;
arg1: default-val1;
arg2: a-value; }
CSS
=a-mixin($required, $arg1: default-val1, $arg2: default-val2)
required: $required
arg1: $arg1
arg2: $arg2
.mixed
$a-value: a-value
+a-mixin(foo, $arg2: $a-value)
SASS
end
def test_mixin_keyword_args_handle_variable_underscore_dash_equivalence
assert_equal <<CSS, render(<<SASS)
.mixed {
required: foo;
arg1: non-default-val1;
arg2: non-default-val2; }
CSS
=a-mixin($required, $arg-1: default-val1, $arg_2: default-val2)
required: $required
arg1: $arg_1
arg2: $arg-2
.mixed
+a-mixin(foo, $arg-2: non-default-val2, $arg_1: non-default-val1)
SASS
end
def test_passing_required_args_as_a_keyword_arg
assert_equal <<CSS, render(<<SASS)
.mixed {
required: foo;
arg1: default-val1;
arg2: default-val2; }
CSS
=a-mixin($required, $arg1: default-val1, $arg2: default-val2)
required: $required
arg1: $arg1
arg2: $arg2
.mixed
+a-mixin($required: foo)
SASS
end
def test_passing_all_as_keyword_args_in_opposite_order
assert_equal <<CSS, render(<<SASS)
.mixed {
required: foo;
arg1: non-default-val1;
arg2: non-default-val2; }
CSS
=a-mixin($required, $arg1: default-val1, $arg2: default-val2)
required: $required
arg1: $arg1
arg2: $arg2
.mixed
+a-mixin($arg2: non-default-val2, $arg1: non-default-val1, $required: foo)
SASS
end
def test_function_output_with_comma
assert_equal <<CSS, render(<<SASS)
foo {
a: b(c), d(e); }
CSS
foo
a: b(c), d(e)
SASS
end
def test_interpolation_with_comma
assert_equal <<CSS, render(<<SASS)
foo {
a: foo, bar; }
CSS
$foo: foo
foo
a: \#{$foo}, bar
SASS
end
def test_string_interpolation_with_comma
assert_equal <<CSS, render(<<SASS)
foo {
a: "bip foo bap", bar; }
CSS
$foo: foo
foo
a: "bip \#{$foo} bap", bar
SASS
end
def test_unknown_directive
assert_equal <<CSS, render(<<SASS)
@baz {
c: d; }
CSS
@baz
c: d
SASS
end
def test_loud_comment_interpolations_can_be_escaped
assert_equal <<CSS, render(<<SASS)
/* \#{foo} */
CSS
/* \\\#{foo}
SASS
assert_equal <<CSS, render(<<SASS)
/*! \#{foo} */
CSS
/*! \\\#{foo}
SASS
end
def test_selector_compression
assert_equal <<CSS, render(<<SASS, :style => :compressed)
a>b,c+d,:-moz-any(e,f,g){h:i}
CSS
a > b, c + d, :-moz-any(e, f, g)
h: i
SASS
end
def test_comment_like_selector
assert_raise_message(Sass::SyntaxError, 'Invalid CSS after "/": expected identifier, was " foo"') {render(<<SASS)}
/ foo
a: b
SASS
end
def test_nested_empty_directive
assert_equal <<CSS, render(<<SASS)
@media screen {
.foo {
a: b; }
@unknown-directive; }
CSS
@media screen
.foo
a: b
@unknown-directive
SASS
end
def test_original_filename_set
importer = MockImporter.new
importer.add_import("imported", "div{color:red}")
original_filename = filename_for_test
engine = Sass::Engine.new('@import "imported"; div{color:blue}',
:filename => original_filename, :load_paths => [importer], :syntax => :scss, :importer => importer)
engine.render
assert_equal original_filename, engine.options[:original_filename]
assert_equal original_filename, importer.engine("imported").options[:original_filename]
end
def test_changing_precision
old_precision = Sass::Script::Value::Number.precision
begin
Sass::Script::Value::Number.precision = 8
assert_equal <<CSS, render(<<SASS)
div {
maximum: 1.00000001;
too-much: 1; }
CSS
div
maximum : 1.00000001
too-much: 1.000000001
SASS
ensure
Sass::Script::Value::Number.precision = old_precision
end
end
def test_content
assert_equal <<CSS, render(<<SASS)
.children {
background-color: red;
color: blue;
border-color: red; }
CSS
$color: blue
=context($class, $color: red)
.\#{$class}
background-color: $color
@content
border-color: $color
+context(children)
color: $color
SASS
end
def test_selector_in_content
assert_equal <<CSS, render(<<SASS)
.parent {
background-color: red;
border-color: red; }
.parent .children {
color: blue; }
CSS
$color: blue
=context($class, $color: red)
.\#{$class}
background-color: $color
@content
border-color: $color
+context(parent)
.children
color: $color
SASS
end
def test_using_parent_mixin_in_content
assert_equal <<CSS, render(<<SASS)
.parent {
before-color: red;
after-color: red; }
.parent .sibling {
before-color: yellow;
after-color: yellow; }
.parent .sibling .child {
before-color: green;
color: blue;
after-color: green; }
CSS
$color: blue
=context($class, $color: red)
.\#{$class}
before-color: $color
@content
after-color: $color
+context(parent)
+context(sibling, $color: yellow)
+context(child, $color: green)
color: $color
SASS
end
def test_content_more_than_once
assert_equal <<CSS, render(<<SASS)
.once {
color: blue; }
.twice {
color: blue; }
CSS
$color: blue
=context($class, $color: red)
.once
@content
.twice
@content
+context(parent)
color: $color
SASS
end
def test_content_with_variable
assert_equal <<CSS, render(<<SASS)
.foo {
a: 1px; }
CSS
=foo
.foo
@content
+foo
$a: 1px
a: $a
SASS
end
def test_nested_content_blocks
assert_equal <<CSS, render(<<SASS)
.foo {
a: foo; }
.foo .bar {
a: bar; }
.foo .bar .baz {
a: baz; }
.foo .bar .baz .outside {
a: outside;
color: red; }
CSS
$a: outside
=baz($a: baz)
.baz
a: $a
@content
=bar($a: bar)
.bar
a: $a
+baz
@content
=foo($a: foo)
.foo
a: $a
+bar
@content
+foo
.outside
a: $a
color: red
SASS
end
def test_content_not_seen_through_mixin
assert_equal <<CSS, render(<<SASS)
a foo {
mixin: foo;
a: b; }
a foo bar {
mixin: bar; }
CSS
=foo
foo
mixin: foo
@content
+bar
=bar
bar
mixin: bar
@content
a
+foo
a: b
SASS
end
def test_content_backtrace_for_perform
render(<<SASS)
=foo
@content
a
+foo
b: 1em + 2px
SASS
assert(false, "Expected exception")
rescue Sass::SyntaxError => e
assert_equal([
{:mixin => '@content', :line => 6, :filename => 'test_content_backtrace_for_perform_inline.sass'},
{:mixin => 'foo', :line => 2, :filename => 'test_content_backtrace_for_perform_inline.sass'},
{:line => 5, :filename => 'test_content_backtrace_for_perform_inline.sass'},
], e.sass_backtrace)
end
def test_content_backtrace_for_cssize
render(<<SASS)
=foo
@content
a
+foo
@extend foo bar baz
SASS
assert(false, "Expected exception")
rescue Sass::SyntaxError => e
assert_equal([
{:mixin => '@content', :line => 6, :filename => 'test_content_backtrace_for_cssize_inline.sass'},
{:mixin => 'foo', :line => 2, :filename => 'test_content_backtrace_for_cssize_inline.sass'},
{:line => 5, :filename => 'test_content_backtrace_for_cssize_inline.sass'},
], e.sass_backtrace)
end
def test_mixin_with_args_and_varargs_passed_no_var_args
assert_equal <<CSS, render(<<SASS, :syntax => :scss)
.foo {
a: 1;
b: 2;
c: 3; }
CSS
@mixin three-or-more-args($a, $b, $c, $rest...) {
a: $a;
b: $b;
c: $c;
}
.foo {
@include three-or-more-args($a: 1, $b: 2, $c: 3);
}
SASS
end
def test_debug_inspects_sass_objects
assert_warning(<<END) {render("@debug (a: 1, b: 2)")}
test_debug_inspects_sass_objects_inline.sass:1 DEBUG: (a: 1, b: 2)
END
assert_warning(<<END) {render("$map: (a: 1, b: 2); @debug $map", :syntax => :scss)}
test_debug_inspects_sass_objects_inline.scss:1 DEBUG: (a: 1, b: 2)
END
end
def test_error_throws_sass_objects
assert_raise_message(Sass::SyntaxError, "(a: 1, b: 2)") {render("@error (a: 1, b: 2)")}
assert_raise_message(Sass::SyntaxError, "(a: 1, b: 2)") do
render("$map: (a: 1, b: 2); @error $map", :syntax => :scss)
end
end
def test_default_arg_before_splat
assert_equal <<CSS, render(<<SASS, :syntax => :scss)
.foo-positional {
a: 1;
b: 2;
positional-arguments: 3, 4;
keyword-arguments: (); }
.foo-keywords {
a: true;
positional-arguments: ();
keyword-arguments: (c: c, d: d); }
CSS
@mixin foo($a: true, $b: null, $arguments...) {
a: $a;
b: $b;
positional-arguments: inspect($arguments);
keyword-arguments: inspect(keywords($arguments));
}
.foo-positional {
@include foo(1, 2, 3, 4);
}
.foo-keywords {
@include foo($c: c, $d: d);
}
SASS
end
def test_keyframes
assert_equal <<CSS, render(<<SASS)
@keyframes identifier {
0% {
top: 0;
left: 0; }
30% {
top: 50px; }
68%, 72% {
left: 50px; }
100% {
top: 100px;
left: 100%; } }
CSS
@keyframes identifier
0%
top: 0
left: 0
\#{"30%"}
top: 50px
68%, 72%
left: 50px
100%
top: 100px
left: 100%
SASS
end
def test_prefixed_keyframes
assert_equal <<CSS, render(<<SASS)
@-moz-keyframes identifier {
0% {
top: 0;
left: 0; }
30% {
top: 50px; }
68%, 72% {
left: 50px; }
100% {
top: 100px;
left: 100%; } }
CSS
@-moz-keyframes identifier
0%
top: 0
left: 0
\#{"30%"}
top: 50px
68%, 72%
left: 50px
100%
top: 100px
left: 100%
SASS
end
def test_uppercase_keyframes
assert_equal <<CSS, render(<<SASS)
@KEYFRAMES identifier {
0% {
top: 0;
left: 0; }
30% {
top: 50px; }
68%, 72% {
left: 50px; }
100% {
top: 100px;
left: 100%; } }
CSS
@KEYFRAMES identifier
0%
top: 0
left: 0
\#{"30%"}
top: 50px
68%, 72%
left: 50px
100%
top: 100px
left: 100%
SASS
end
def test_compressed_unknown_directive
assert_equal(<<CSS, render(<<SASS, :style => :compressed))
x{@foo;a:b;@bar}
CSS
x
@foo
a: b
@bar
SASS
end
def test_compressed_unknown_directive_in_directive
assert_equal(<<CSS, render(<<SASS, :style => :compressed))
@x{@foo;a:b;@bar}
CSS
@x
@foo
a: b
@bar
SASS
end
def test_compressed_unknown_directive_with_children_in_directive
assert_equal(<<CSS, render(<<SASS, :style => :compressed))
@x{@foo{a:b}c:d;@bar{e:f}}
CSS
@x
@foo
a: b
c: d
@bar
e: f
SASS
end
def test_compressed_rule_in_directive
assert_equal(<<CSS, render(<<SASS, :style => :compressed))
@x{foo{a:b}c:d;bar{e:f}}
CSS
@x
foo
a: b
c: d
bar
e: f
SASS
end
def test_import_two_css_files_issue_1806
assert_equal(<<CSS, render(<<SASS, :syntax => :scss, :style => :compressed))
@import url(\"foo.css\");@import url(\"bar.css\");@import url(\"baz.css\")
CSS
@import url("foo.css");
@import url("bar.css");
@import url("baz.css");
SASS
end
def test_numeric_formatting_of_integers
assert_equal(<<CSS, render(<<SASS, :syntax => :scss, :style => :compressed))
a{near:3.0000000001;plus:3;minus:3;negative:-3}
CSS
a {
near: (3 + 0.0000000001);
plus: (3 + 0.000000000001);
minus: (3 - 0.000000000001);
negative: (-3 + 0.000000000001);
}
SASS
end
def test_escaped_semicolons_are_not_compressed
assert_equal(<<'CSS', render(<<'SASS', :syntax => :scss, :style => :compressed))
div{color:#f00000\9 \0 \;}
CSS
div {
color: #f00000\9\0\;
}
SASS
end
def test_compressed_output_of_nth_selectors
assert_equal(<<CSS, render(<<SASS, :syntax => :scss, :style => :compressed))
:nth-of-type(2n-1),:nth-child(2n-1),:nth(2n-1),:nth-of-type(2n-1),:nth-of-type(2n-1){color:red}:nth-of-type(2n+1),:nth-child(2n+1),:nth(2n+1),:nth-of-type(2n+1),:nth-of-type(2n+1){color:red}
CSS
:nth-of-type(2n-1), :nth-child(2n- 1), :nth(2n -1), :nth-of-type(2n - 1), :nth-of-type( 2n - 1 ) {
color: red }
:nth-of-type(2n+1), :nth-child(2n+ 1), :nth(2n +1), :nth-of-type(2n + 1), :nth-of-type( 2n + 1 ) {
color: red }
SASS
end
def test_descendant_selectors_with_leading_dash
assert_equal(<<CSS, render(<<SASS, :syntax => :scss, :style => :compressed))
a -b{color:red}
CSS
a -b {
color: red }
SASS
end
def test_import_with_supports_clause_interp
assert_equal(<<CSS, render(<<'SASS', :style => :compressed))
@import url("fallback-layout.css") supports(not (display: flex))
CSS
$display-type: flex
@import url("fallback-layout.css") supports(not (display: #{$display-type}))
SASS
end
def test_import_with_supports_clause
assert_equal(<<CSS, render(<<SASS, :style => :compressed))
@import url("fallback-layout.css") supports(not (display: flex))
CSS
@import url("fallback-layout.css") supports(not (display: flex))
SASS
end
def test_compressed_commas_in_attribute_selectors
assert_equal(<<CSS, render(<<SASS, :style => :compressed))
.classname[a="1, 2, 3"],.another[b="4, 5, 6"]{color:red}
CSS
.classname[a="1, 2, 3"], .another[b="4, 5, 6"]
color: red
SASS
end
def test_trailing_commas_in_arglists
assert_equal(<<CSS, render(<<SASS, :style => :nested))
.includes {
one-positional-arg: positional 1 a;
two-positional-args: positional 2 a b;
one-keyword-arg: keyword 1 z;
two-keyword-args: keyword 2 y z;
mixed-args: mixed 2 y z; }
.calls {
one-positional-arg: positional 1 a;
two-positional-args: positional 2 a b;
one-keyword-arg: keyword 1 z;
two-keyword-args: keyword 2 y z;
mixed-args: mixed 2 y z; }
CSS
=one-positional-arg($a,)
one-positional-arg: positional 1 $a
=two-positional-args($a, $b,)
two-positional-args: positional 2 $a $b
=one-keyword-arg($a: a,)
one-keyword-arg: keyword 1 $a
=two-keyword-args($a: a, $b: b,)
two-keyword-args: keyword 2 $a $b
=mixed-args($a, $b: b,)
mixed-args: mixed 2 $a $b
@function one-positional-arg($a)
@return positional 1 $a
@function two-positional-args($a, $b)
@return positional 2 $a $b
@function one-keyword-arg($a: a)
@return keyword 1 $a
@function two-keyword-args($a: a, $b: b)
@return keyword 2 $a $b
@function mixed-args($a, $b: b)
@return mixed 2 $a $b
.includes
+one-positional-arg(a,)
+two-positional-args(a, b,)
+one-keyword-arg($a: z,)
+two-keyword-args($a: y, $b: z,)
+mixed-args(y, $b: z,)
.calls
one-positional-arg: one-positional-arg(a)
two-positional-args: two-positional-args(a, b)
one-keyword-arg: one-keyword-arg($a: z)
two-keyword-args: two-keyword-args($a: y, $b: z)
mixed-args: mixed-args(y, $b: z)
SASS
end
private
def assert_hash_has(hash, expected)
expected.each do |k, v|
if v.nil?
assert_nil(hash[k])
else
assert_equal(v, hash[k])
end
end
end
def assert_renders_encoded(css, sass)
result = render(sass)
assert_equal css.encoding, result.encoding
assert_equal css, result
end
def render(sass, options = {})
munge_filename options
options[:importer] ||= MockImporter.new
Sass::Engine.new(sass, options).render
end
def renders_correctly(name, options={})
sass_file = load_file(name, "sass")
css_file = load_file(name, "css")
options[:filename] ||= filename(name, "sass")
options[:syntax] ||= :sass
options[:css_filename] ||= filename(name, "css")
css_result = Sass::Engine.new(sass_file, options).render
assert_equal css_file, css_result
end
def load_file(name, type = "sass")
@result = ''
File.new(filename(name, type)).each_line { |l| @result += l }
@result
end
def filename(name, type)
path = File.dirname(__FILE__) + "/#{type == 'sass' ? 'templates' : 'results'}/#{name}.#{type}"
Sass::Util.cleanpath(path).to_s
end
def sassc_path(template)
sassc_path = File.join(File.dirname(__FILE__) + "/templates/#{template}.sass")
engine = Sass::Engine.new("", :filename => sassc_path,
:importer => Sass::Importers::Filesystem.new("."))
key = engine.send(:sassc_key)
File.join(engine.options[:cache_location], key)
end
end
|