|
1 | 1 | import {createParser, ast} from './import.js';
|
2 | 2 |
|
3 | 3 | describe('CSS Modules', () => {
|
| 4 | + describe('css-position-1', () => { |
| 5 | + it('should parse position-1 pseudo-classes when module is enabled', () => { |
| 6 | + const parse = createParser({ |
| 7 | + modules: ['css-position-1'] |
| 8 | + }); |
| 9 | + |
| 10 | + expect(parse(':static')).toEqual( |
| 11 | + ast.selector({ |
| 12 | + rules: [ |
| 13 | + ast.rule({ |
| 14 | + items: [ast.pseudoClass({name: 'static'})] |
| 15 | + }) |
| 16 | + ] |
| 17 | + }) |
| 18 | + ); |
| 19 | + |
| 20 | + expect(parse(':relative')).toEqual( |
| 21 | + ast.selector({ |
| 22 | + rules: [ |
| 23 | + ast.rule({ |
| 24 | + items: [ast.pseudoClass({name: 'relative'})] |
| 25 | + }) |
| 26 | + ] |
| 27 | + }) |
| 28 | + ); |
| 29 | + |
| 30 | + expect(parse(':absolute')).toEqual( |
| 31 | + ast.selector({ |
| 32 | + rules: [ |
| 33 | + ast.rule({ |
| 34 | + items: [ast.pseudoClass({name: 'absolute'})] |
| 35 | + }) |
| 36 | + ] |
| 37 | + }) |
| 38 | + ); |
| 39 | + |
| 40 | + // Should reject fixed as it's not in position-1 |
| 41 | + const strictParse = createParser({ |
| 42 | + modules: ['css-position-1'], |
| 43 | + syntax: { |
| 44 | + pseudoClasses: { |
| 45 | + unknown: 'reject' |
| 46 | + } |
| 47 | + } |
| 48 | + }); |
| 49 | + |
| 50 | + expect(() => strictParse(':fixed')).toThrow('Unknown pseudo-class: "fixed".'); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + describe('css-position-2', () => { |
| 55 | + it('should parse position-2 pseudo-classes when module is enabled', () => { |
| 56 | + const parse = createParser({ |
| 57 | + modules: ['css-position-2'] |
| 58 | + }); |
| 59 | + |
| 60 | + // Position-2 adds fixed |
| 61 | + expect(parse(':fixed')).toEqual( |
| 62 | + ast.selector({ |
| 63 | + rules: [ |
| 64 | + ast.rule({ |
| 65 | + items: [ast.pseudoClass({name: 'fixed'})] |
| 66 | + }) |
| 67 | + ] |
| 68 | + }) |
| 69 | + ); |
| 70 | + |
| 71 | + // Should reject sticky as it's not in position-2 |
| 72 | + const strictParse = createParser({ |
| 73 | + modules: ['css-position-2'], |
| 74 | + syntax: { |
| 75 | + pseudoClasses: { |
| 76 | + unknown: 'reject' |
| 77 | + } |
| 78 | + } |
| 79 | + }); |
| 80 | + |
| 81 | + expect(() => strictParse(':sticky')).toThrow('Unknown pseudo-class: "sticky".'); |
| 82 | + }); |
| 83 | + }); |
| 84 | + |
4 | 85 | describe('css-position-3', () => {
|
5 | 86 | it('should parse position pseudo-classes when module is enabled', () => {
|
6 | 87 | const parse = createParser({
|
|
0 commit comments