|
| 1 | +import assert from 'assert'; |
| 2 | +import { lexer } from '../index.js'; |
| 3 | + |
| 4 | +describe('lexer relative colors', () => { |
| 5 | + describe('rgb() with relative colors', () => { |
| 6 | + it('should match rgb(25 25 25 / 50%)', () => { |
| 7 | + const result = lexer.matchProperty('color', 'rgb(25 25 25 / 50%)'); |
| 8 | + |
| 9 | + assert(result.matched, 'Should match relative color syntax'); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should match rgb(from hsl(0 100% 50%) r g b)', () => { |
| 13 | + const result = lexer.matchProperty('color', 'rgb(from hsl(0 100% 50%) r g b)'); |
| 14 | + |
| 15 | + assert(result.matched, 'Should match relative color syntax'); |
| 16 | + }); |
| 17 | + |
| 18 | + it('should match rgb(from hsl(0 100% 50%) 132 132 224)', () => { |
| 19 | + const result = lexer.matchProperty('color', 'rgb(from hsl(0 100% 50%) 132 132 224)'); |
| 20 | + |
| 21 | + assert(result.matched, 'Should match relative color syntax'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should match rgb(from #123456 calc(r + 40) calc(g + 40) b)', () => { |
| 25 | + const result = lexer.matchProperty('color', 'rgb(from #123456 calc(r + 40) calc(g + 40) b)'); |
| 26 | + |
| 27 | + assert(result.matched, 'Should match relative color with calc functions'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should match rgb(from hwb(120deg 10% 20%) r g calc(b + 200))', () => { |
| 31 | + const result = lexer.matchProperty('color', 'rgb(from hwb(120deg 10% 20%) r g calc(b + 200))'); |
| 32 | + |
| 33 | + assert(result.matched, 'Should match relative color with hwb and calc'); |
| 34 | + }); |
| 35 | + |
| 36 | + it('should match rgb(25 25 25 / 50%)', () => { |
| 37 | + const result = lexer.matchProperty('color', 'rgb(25 25 25 / 50%)'); |
| 38 | + |
| 39 | + assert(result.matched, 'Should match relative color syntax'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should match rgb(from hsl(0 100% 50%) r 80 80)', () => { |
| 43 | + const result = lexer.matchProperty('color', 'rgb(from hsl(0 100% 50%) r 80 80)'); |
| 44 | + |
| 45 | + assert(result.matched, 'Should match relative color syntax'); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should match rgb(from hsl(0 100% 50% / 0.8) r g b / alpha)', () => { |
| 49 | + const result = lexer.matchProperty('color', 'rgb(from hsl(0 100% 50% / 0.8) r g b / alpha)'); |
| 50 | + |
| 51 | + assert(result.matched, 'Should match relative color syntax'); |
| 52 | + }); |
| 53 | + |
| 54 | + it('should match rgb(from hsl(0 100% 50% / 0.8) r g b / 0.5)', () => { |
| 55 | + const result = lexer.matchProperty('color', 'rgb(from hsl(0 100% 50% / 0.8) r g b / 0.5)'); |
| 56 | + |
| 57 | + assert(result.matched, 'Should match relative color syntax'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should match rgb(from hsl(0 100% 50%) calc(r/2) calc(g + 25) calc(b + 175) / calc(alpha - 0.1))', () => { |
| 61 | + const result = lexer.matchProperty('color', 'rgb(from hsl(0 100% 50%) calc(r/2) calc(g + 25) calc(b + 175) / calc(alpha - 0.1))'); |
| 62 | + |
| 63 | + assert(result.matched, 'Should match relative color syntax'); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + describe('rgba() with relative colors', () => { |
| 68 | + it('should match rgba(25 25 25)', () => { |
| 69 | + const result = lexer.matchProperty('color', 'rgba(25 25 25)'); |
| 70 | + |
| 71 | + assert(result.matched, 'Should match relative color syntax'); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should match rgba(25 25 25 / 50%)', () => { |
| 75 | + const result = lexer.matchProperty('color', 'rgba(25 25 25 / 50%)'); |
| 76 | + |
| 77 | + assert(result.matched, 'Should match relative color syntax'); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should match rgba(from hsl(0 100% 50%) r g b)', () => { |
| 81 | + const result = lexer.matchProperty('color', 'rgba(from hsl(0 100% 50%) r g b)'); |
| 82 | + |
| 83 | + assert(result.matched, 'Should match relative color syntax'); |
| 84 | + }); |
| 85 | + |
| 86 | + it('should match rgba(from hsl(0 100% 50%) 132 132 224)', () => { |
| 87 | + const result = lexer.matchProperty('color', 'rgba(from hsl(0 100% 50%) 132 132 224)'); |
| 88 | + |
| 89 | + assert(result.matched, 'Should match relative color syntax'); |
| 90 | + }); |
| 91 | + |
| 92 | + it('should match rgba(from #123456 calc(r + 40) calc(g + 40) b)', () => { |
| 93 | + const result = lexer.matchProperty('color', 'rgba(from #123456 calc(r + 40) calc(g + 40) b)'); |
| 94 | + |
| 95 | + assert(result.matched, 'Should match relative color with calc functions'); |
| 96 | + }); |
| 97 | + |
| 98 | + it('should match rgba(from hwb(120deg 10% 20%) r g calc(b + 200))', () => { |
| 99 | + const result = lexer.matchProperty('color', 'rgba(from hwb(120deg 10% 20%) r g calc(b + 200))'); |
| 100 | + |
| 101 | + assert(result.matched, 'Should match relative color with hwb and calc'); |
| 102 | + }); |
| 103 | + |
| 104 | + it('should match rgba(25 25 25 / 50%)', () => { |
| 105 | + const result = lexer.matchProperty('color', 'rgba(25 25 25 / 50%)'); |
| 106 | + |
| 107 | + assert(result.matched, 'Should match relative color syntax'); |
| 108 | + }); |
| 109 | + |
| 110 | + it('should match rgba(from hsl(0 100% 50%) r 80 80)', () => { |
| 111 | + const result = lexer.matchProperty('color', 'rgba(from hsl(0 100% 50%) r 80 80)'); |
| 112 | + |
| 113 | + assert(result.matched, 'Should match relative color syntax'); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should match rgba(from hsl(0 100% 50% / 0.8) r g b / alpha)', () => { |
| 117 | + const result = lexer.matchProperty('color', 'rgba(from hsl(0 100% 50% / 0.8) r g b / alpha)'); |
| 118 | + |
| 119 | + assert(result.matched, 'Should match relative color syntax'); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should match rgba(from hsl(0 100% 50% / 0.8) r g b / 0.5)', () => { |
| 123 | + const result = lexer.matchProperty('color', 'rgba(from hsl(0 100% 50% / 0.8) r g b / 0.5)'); |
| 124 | + |
| 125 | + assert(result.matched, 'Should match relative color syntax'); |
| 126 | + }); |
| 127 | + |
| 128 | + it('should match rgba(from hsl(0 100% 50%) calc(r/2) calc(g + 25) calc(b + 175) / calc(alpha - 0.1))', () => { |
| 129 | + const result = lexer.matchProperty('color', 'rgba(from hsl(0 100% 50%) calc(r/2) calc(g + 25) calc(b + 175) / calc(alpha - 0.1))'); |
| 130 | + |
| 131 | + assert(result.matched, 'Should match relative color syntax'); |
| 132 | + }); |
| 133 | + }); |
| 134 | +}); |
0 commit comments