123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- // Initiate ModeTest and set defaults
- var MT = ModeTest;
- MT.modeName = 'css';
- MT.modeOptions = {};
- // Requires at least one media query
- MT.testMode(
- 'atMediaEmpty',
- '@media { }',
- [
- 'def', '@media',
- null, ' ',
- 'error', '{',
- null, ' }'
- ]
- );
- MT.testMode(
- 'atMediaMultiple',
- '@media not screen and (color), not print and (color) { }',
- [
- 'def', '@media',
- null, ' ',
- 'keyword', 'not',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'operator', 'and',
- null, ' (',
- 'property', 'color',
- null, '), ',
- 'keyword', 'not',
- null, ' ',
- 'attribute', 'print',
- null, ' ',
- 'operator', 'and',
- null, ' (',
- 'property', 'color',
- null, ') { }'
- ]
- );
- MT.testMode(
- 'atMediaCheckStack',
- '@media screen { } foo { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' { } ',
- 'tag', 'foo',
- null, ' { }'
- ]
- );
- MT.testMode(
- 'atMediaCheckStack',
- '@media screen (color) { } foo { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' (',
- 'property', 'color',
- null, ') { } ',
- 'tag', 'foo',
- null, ' { }'
- ]
- );
- MT.testMode(
- 'atMediaCheckStackInvalidAttribute',
- '@media foobarhello { } foo { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute error', 'foobarhello',
- null, ' { } ',
- 'tag', 'foo',
- null, ' { }'
- ]
- );
- // Error, because "and" is only allowed immediately preceding a media expression
- MT.testMode(
- 'atMediaInvalidAttribute',
- '@media foobarhello { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute error', 'foobarhello',
- null, ' { }'
- ]
- );
- // Error, because "and" is only allowed immediately preceding a media expression
- MT.testMode(
- 'atMediaInvalidAnd',
- '@media and screen { }',
- [
- 'def', '@media',
- null, ' ',
- 'error', 'and',
- null, ' ',
- 'attribute', 'screen',
- null, ' { }'
- ]
- );
- // Error, because "not" is only allowed as the first item in each media query
- MT.testMode(
- 'atMediaInvalidNot',
- '@media screen not (not) { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'error', 'not',
- null, ' (',
- 'error', 'not',
- null, ') { }'
- ]
- );
- // Error, because "only" is only allowed as the first item in each media query
- MT.testMode(
- 'atMediaInvalidOnly',
- '@media screen only (only) { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'error', 'only',
- null, ' (',
- 'error', 'only',
- null, ') { }'
- ]
- );
- // Error, because "foobarhello" is neither a known type or property, but
- // property was expected (after "and"), and it should be in parenthese.
- MT.testMode(
- 'atMediaUnknownType',
- '@media screen and foobarhello { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'operator', 'and',
- null, ' ',
- 'error', 'foobarhello',
- null, ' { }'
- ]
- );
- // Error, because "color" is not a known type, but is a known property, and
- // should be in parentheses.
- MT.testMode(
- 'atMediaInvalidType',
- '@media screen and color { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'operator', 'and',
- null, ' ',
- 'error', 'color',
- null, ' { }'
- ]
- );
- // Error, because "print" is not a known property, but is a known type,
- // and should not be in parenthese.
- MT.testMode(
- 'atMediaInvalidProperty',
- '@media screen and (print) { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'operator', 'and',
- null, ' (',
- 'error', 'print',
- null, ') { }'
- ]
- );
- // Soft error, because "foobarhello" is not a known property or type.
- MT.testMode(
- 'atMediaUnknownProperty',
- '@media screen and (foobarhello) { }',
- [
- 'def', '@media',
- null, ' ',
- 'attribute', 'screen',
- null, ' ',
- 'operator', 'and',
- null, ' (',
- 'property error', 'foobarhello',
- null, ') { }'
- ]
- );
- MT.testMode(
- 'tagSelector',
- 'foo { }',
- [
- 'tag', 'foo',
- null, ' { }'
- ]
- );
- MT.testMode(
- 'classSelector',
- '.foo-bar_hello { }',
- [
- 'qualifier', '.foo-bar_hello',
- null, ' { }'
- ]
- );
- MT.testMode(
- 'idSelector',
- '#foo { #foo }',
- [
- 'builtin', '#foo',
- null, ' { ',
- 'error', '#foo',
- null, ' }'
- ]
- );
- MT.testMode(
- 'tagSelectorUnclosed',
- 'foo { margin: 0 } bar { }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'margin',
- 'operator', ':',
- null, ' ',
- 'number', '0',
- null, ' } ',
- 'tag', 'bar',
- null, ' { }'
- ]
- );
- MT.testMode(
- 'tagStringNoQuotes',
- 'foo { font-family: hello world; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'font-family',
- 'operator', ':',
- null, ' ',
- 'variable-2', 'hello',
- null, ' ',
- 'variable-2', 'world',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagStringDouble',
- 'foo { font-family: "hello world"; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'font-family',
- 'operator', ':',
- null, ' ',
- 'string', '"hello world"',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagStringSingle',
- 'foo { font-family: \'hello world\'; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'font-family',
- 'operator', ':',
- null, ' ',
- 'string', '\'hello world\'',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagColorKeyword',
- 'foo { color: black; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'color',
- 'operator', ':',
- null, ' ',
- 'keyword', 'black',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagColorHex3',
- 'foo { background: #fff; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'background',
- 'operator', ':',
- null, ' ',
- 'atom', '#fff',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagColorHex6',
- 'foo { background: #ffffff; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'background',
- 'operator', ':',
- null, ' ',
- 'atom', '#ffffff',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagColorHex4',
- 'foo { background: #ffff; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'background',
- 'operator', ':',
- null, ' ',
- 'atom error', '#ffff',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagColorHexInvalid',
- 'foo { background: #ffg; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'background',
- 'operator', ':',
- null, ' ',
- 'atom error', '#ffg',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagNegativeNumber',
- 'foo { margin: -5px; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'margin',
- 'operator', ':',
- null, ' ',
- 'number', '-5px',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagPositiveNumber',
- 'foo { padding: 5px; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'padding',
- 'operator', ':',
- null, ' ',
- 'number', '5px',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagVendor',
- 'foo { -foo-box-sizing: -foo-border-box; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'meta', '-foo-',
- 'property', 'box-sizing',
- 'operator', ':',
- null, ' ',
- 'meta', '-foo-',
- 'string-2', 'border-box',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagBogusProperty',
- 'foo { barhelloworld: 0; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property error', 'barhelloworld',
- 'operator', ':',
- null, ' ',
- 'number', '0',
- null, '; }'
- ]
- );
- MT.testMode(
- 'tagTwoProperties',
- 'foo { margin: 0; padding: 0; }',
- [
- 'tag', 'foo',
- null, ' { ',
- 'property', 'margin',
- 'operator', ':',
- null, ' ',
- 'number', '0',
- null, '; ',
- 'property', 'padding',
- 'operator', ':',
- null, ' ',
- 'number', '0',
- null, '; }'
- ]
- );
- //
- //MT.testMode(
- // 'tagClass',
- // '@media only screen and (min-width: 500px), print {foo.bar#hello { color: black !important; background: #f00; margin: -5px; padding: 5px; -foo-box-sizing: border-box; } /* world */}',
- // [
- // 'def', '@media',
- // null, ' ',
- // 'keyword', 'only',
- // null, ' ',
- // 'attribute', 'screen',
- // null, ' ',
- // 'operator', 'and',
- // null, ' ',
- // 'bracket', '(',
- // 'property', 'min-width',
- // 'operator', ':',
- // null, ' ',
- // 'number', '500px',
- // 'bracket', ')',
- // null, ', ',
- // 'attribute', 'print',
- // null, ' {',
- // 'tag', 'foo',
- // 'qualifier', '.bar',
- // 'header', '#hello',
- // null, ' { ',
- // 'property', 'color',
- // 'operator', ':',
- // null, ' ',
- // 'keyword', 'black',
- // null, ' ',
- // 'keyword', '!important',
- // null, '; ',
- // 'property', 'background',
- // 'operator', ':',
- // null, ' ',
- // 'atom', '#f00',
- // null, '; ',
- // 'property', 'padding',
- // 'operator', ':',
- // null, ' ',
- // 'number', '5px',
- // null, '; ',
- // 'property', 'margin',
- // 'operator', ':',
- // null, ' ',
- // 'number', '-5px',
- // null, '; ',
- // 'meta', '-foo-',
- // 'property', 'box-sizing',
- // 'operator', ':',
- // null, ' ',
- // 'string-2', 'border-box',
- // null, '; } ',
- // 'comment', '/* world */',
- // null, '}'
- // ]
- //);
|