|
| 1 | +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 | +<html xmlns="http://www.w3.org/1999/xhtml" > |
| 3 | + <head> |
| 4 | + <title>Sassij Engine Tests</title> |
| 5 | + <script language="javascript" src="../lib/jquery-1.3.1.min.js" type="text/javascript"></script> |
| 6 | + <script language="javascript" src="../lib/testrunner.js" type="text/javascript"></script> |
| 7 | + <link media="screen" href="../lib/testsuite.css" type="text/css" rel="stylesheet"/> |
| 8 | + </head> |
| 9 | + <body> |
| 10 | + <script language="javascript" type="text/javascript"> |
| 11 | + |
| 12 | + /* |
| 13 | + * A map of erroneous Sass documents to the error messages they should produce. |
| 14 | + * The error messages may be arrays; |
| 15 | + * if so, the second element should be the line number that should be reported for the error. |
| 16 | + * If this isn't provided, the tests will assume the line number should be the last line of the document. |
| 17 | + */ |
| 18 | + EXCEPTION_MAP = { |
| 19 | + "!a = 1 + " => 'Expected expression, was end of text.', |
| 20 | + "!a = 1 + 2 +" => 'Expected expression, was end of text.', |
| 21 | + "!a = 1 + 2 + %" => 'Expected expression, was mod token.', |
| 22 | + "!a = foo(\"bar\"" => 'Expected rparen token, was end of text.', |
| 23 | + "!a = 1 }" => 'Unexpected right_bracket token.', |
| 24 | + "!a = 1 }foo\"" => 'Unexpected right_bracket token.', |
| 25 | + "!a = #aaa - \"a\"" => 'Undefined operation: "#aaaaaa minus a".', |
| 26 | + "!a = #aaa / \"a\"" => 'Undefined operation: "#aaaaaa div a".', |
| 27 | + "!a = #aaa * \"a\"" => 'Undefined operation: "#aaaaaa times a".', |
| 28 | + "!a = #aaa % \"a\"" => 'Undefined operation: "#aaaaaa mod a".', |
| 29 | + "!a = 1 - \"a\"" => 'Undefined operation: "1 minus a".', |
| 30 | + "!a = 1 * \"a\"" => 'Undefined operation: "1 times a".', |
| 31 | + "!a = 1 / \"a\"" => 'Undefined operation: "1 div a".', |
| 32 | + "!a = 1 % \"a\"" => 'Undefined operation: "1 mod a".', |
| 33 | + ":" => 'Invalid attribute: ":".', |
| 34 | + ": a" => 'Invalid attribute: ": a".', |
| 35 | + ":= a" => 'Invalid attribute: ":= a".', |
| 36 | + "a\n :b" => 'Invalid attribute: ":b ".', |
| 37 | + "a\n :b: c" => 'Invalid attribute: ":b: c".', |
| 38 | + "a\n :b:c d" => 'Invalid attribute: ":b:c d".', |
| 39 | + "a\n :b=c d" => 'Invalid attribute: ":b=c d".', |
| 40 | + "a\n :b c;" => 'Invalid attribute: ":b c;" (This isn\'t CSS!).', |
| 41 | + "a\n b : c" => 'Invalid attribute: "b : c".', |
| 42 | + "a\n b=c: d" => 'Invalid attribute: "b=c: d".', |
| 43 | + ":a" => 'Attributes aren\'t allowed at the root of a document.', |
| 44 | + "!" => 'Invalid variable: "!".', |
| 45 | + "!a" => 'Invalid variable: "!a".', |
| 46 | + "! a" => 'Invalid variable: "! a".', |
| 47 | + "!a b" => 'Invalid variable: "!a b".', |
| 48 | + "!a = 1b + 2c" => "Incompatible units: 'c' and 'b'.", |
| 49 | + "a\n :b= 1b * 2c" => "2b*c isn't a valid CSS value.", |
| 50 | + "a\n :b= 1b % 2c" => "Cannot modulo by a number with units: 2c.", |
| 51 | + "!a = 2px + #ccc" => "Cannot add a number with units (2px) to a color (#cccccc).", |
| 52 | + "!a = #ccc + 2px" => "Cannot add a number with units (2px) to a color (#cccccc).", |
| 53 | + "& a\n :b c" => ["Base-level rules cannot contain the parent-selector-referencing character '&'.", 1], |
| 54 | + "a\n :b\n c" => "Illegal nesting: Only attributes may be nested beneath attributes.", |
| 55 | + "a,\n :b c" => ["Rules can\'t end in commas.", 1], |
| 56 | + "a," => "Rules can\'t end in commas.", |
| 57 | + "a,\n!b = 1" => ["Rules can\'t end in commas.", 1], |
| 58 | + "!a = b\n :c d\n" => "Illegal nesting: Nothing may be nested beneath variable declarations.", |
| 59 | + "@import foo.sass" => "File to import not found or unreadable: foo.sass.", |
| 60 | + "@import templates/basic\n foo" => "Illegal nesting: Nothing may be nested beneath import directives.", |
| 61 | + "foo\n @import templates/basic" => "Import directives may only be used at the root of a document.", |
| 62 | + %Q{!foo = "bar" "baz" !} => %Q{Syntax error in '"bar" "baz" !' at character 20.}, |
| 63 | + "=foo\n :color red\n.bar\n +bang" => "Undefined mixin 'bang'.", |
| 64 | + ".bar\n =foo\n :color red\n" => ["Mixins may only be defined at the root of a document.", 2], |
| 65 | + "=foo\n :color red\n.bar\n +foo\n :color red" => "Illegal nesting: Nothing may be nested beneath mixin directives.", |
| 66 | + " a\n b: c" => ["Indenting at the beginning of the document is illegal.", 1], |
| 67 | + " \n \n\t\n a\n b: c" => ["Indenting at the beginning of the document is illegal.", 4], |
| 68 | + "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], |
| 69 | + "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], |
| 70 | + "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], |
| 71 | + "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], |
| 72 | + "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], |
| 73 | + "a\n b: c\na\n d: e" => ["The line was indented 2 levels deeper than the previous line.", 4], |
| 74 | + "a\n b: c\n a\n d: e" => ["The line was indented 3 levels deeper than the previous line.", 4], |
| 75 | + "a\n \tb: c" => ["Indentation can't use both tabs and spaces.", 2], |
| 76 | + "=a(" => 'Invalid mixin "a(".', |
| 77 | + "=a(b)" => 'Mixin argument "b" must begin with an exclamation point (!).', |
| 78 | + "=a(,)" => "Mixin arguments can't be empty.", |
| 79 | + "=a(!)" => "Mixin arguments can't be empty.", |
| 80 | + "=a(!foo bar)" => "Invalid variable \"!foo bar\".", |
| 81 | + "=foo\n bar: baz\n+foo" => ["Attributes aren't allowed at the root of a document.", 2], |
| 82 | + "a-\#{!b\n c: d" => ["Expected right_bracket token, was end of text.", 1], |
| 83 | + "=a(!b = 1, !c)" => "Required arguments must not follow optional arguments \"!c\".", |
| 84 | + "=a(!b = 1)\n :a= !b\ndiv\n +a(1,2)" => "Mixin a takes 1 argument but 2 were passed.", |
| 85 | + "=a(!b)\n :a= !b\ndiv\n +a" => "Mixin a is missing parameter !b.", |
| 86 | + "@else\n a\n b: c" => ["@else must come after @if.", 1], |
| 87 | + "@if false\n@else foo" => "Invalid else directive '@else foo': expected 'if <expr>'.", |
| 88 | + "@if false\n@else if " => "Invalid else directive '@else if': expected 'if <expr>'.", |
| 89 | + "a\n !b = 12\nc\n d = !b" => 'Undefined variable: "!b".', |
| 90 | + "=foo\n !b = 12\nc\n +foo\n d = !b" => 'Undefined variable: "!b".', |
| 91 | + '@for !a from 1 to "foo"' => '"foo" is not an integer.', |
| 92 | + '@for !a from 1 to 1.232323' => '1.232 is not an integer.', |
| 93 | + '@if' => "Invalid if directive '@if': expected expression.", |
| 94 | + '@while' => "Invalid while directive '@while': expected expression.", |
| 95 | + '@debug' => "Invalid debug directive '@debug': expected expression.", |
| 96 | + // Regression tests |
| 97 | + "a\n b:\n c\n d" => [ "Illegal nesting: Only attributes may be nested beneath attributes.", 3 ], |
| 98 | + "& foo\n bar: baz\n blat: bang" => [ "Base-level rules cannot contain the parent-selector-referencing character '&'.", 1 ], |
| 99 | + "a\n b: c\n& foo\n bar: baz\n blat: bang" => [ "Base-level rules cannot contain the parent-selector-referencing character '&'.", 3 ], |
| 100 | + } |
| 101 | + |
| 102 | + qUnitTesting( function( config ){ |
| 103 | + |
| 104 | + config.beforeEach = function(){ |
| 105 | + } |
| 106 | + |
| 107 | + config.afterEach = function(){ |
| 108 | + } |
| 109 | + |
| 110 | + module( "Sassij Engine Tests"); |
| 111 | + |
| 112 | + test( "should show the correct Exception when invalid syntax is supplied to the renderer", function(){ |
| 113 | + $( EXCEPTION_MAP ).each( function( key, value ) { |
| 114 | + try { |
| 115 | + Sassij.Engine.new( key ).render(); |
| 116 | + } catch( error ) { |
| 117 | + equals( error, value, "Line: " + key ); |
| 118 | + } |
| 119 | + }) |
| 120 | + |
| 121 | + }) |
| 122 | + |
| 123 | + test( "should render css import command", function(){ |
| 124 | + equals( render( "@import url(./fonts.css) screen", "@import url(./fonts.css) screen;" ) ); |
| 125 | + equals( render( "@import \"./fonts.css\" screen", "@import \"./fonts.css\" screen;" ) ); |
| 126 | + }) |
| 127 | + |
| 128 | + }); |
| 129 | + |
| 130 | + </script> |
| 131 | + |
| 132 | + <h1>My Foo Tests</h1> |
| 133 | + <h2 id="banner"></h2> |
| 134 | + <ol id="tests"></ol> |
| 135 | + <div id="results"></div> |
| 136 | + <div id="main"></div> |
| 137 | + |
| 138 | + </body> |
| 139 | +</html> |
0 commit comments