diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-13 13:56:15 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-13 13:56:15 +0530 |
| commit | 48455e6caaa7ad98316bbb4896b59f4487ad8650 (patch) | |
| tree | eb08b3ab0e9d2f8c453170588470a2445ebdf63c /tests/parser.spec.ts | |
| parent | 78429320ec4ce52f3cf01627987232ad67dd46a3 (diff) | |
| download | css-everything-48455e6caaa7ad98316bbb4896b59f4487ad8650.tar.gz css-everything-48455e6caaa7ad98316bbb4896b59f4487ad8650.zip | |
feat: adds declaration parser
Diffstat (limited to 'tests/parser.spec.ts')
| -rw-r--r-- | tests/parser.spec.ts | 83 |
1 files changed, 64 insertions, 19 deletions
diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts index b03e073..825200e 100644 --- a/tests/parser.spec.ts +++ b/tests/parser.spec.ts @@ -1,4 +1,4 @@ -import { Expr, SelectorComp, parse } from '../src/parser' +import { Expr, SelectorComp, parse, parseDeclarations } from '../src/parser' describe('parser', () => { it('should parse function call', () => { @@ -155,24 +155,69 @@ describe('parser', () => { ]) }) - it('should parse complex selectors', () => { - expect(parse(`button#something.my-class[hello=world]`)).toEqual([ - Expr.Selector({ - tag: 'button', - id: 'something', - selectors: [ - SelectorComp.ClassName('my-class'), - SelectorComp.Attr(['hello', 'world']), - ], - }), - ]) + describe('parseDeclarations', () => { + it('should parse complex selectors', () => { + expect( + parseDeclarations(`button#something.my-class[hello=world]`), + ).toEqual([ + Expr.Selector({ + tag: 'button', + id: 'something', + selectors: [ + SelectorComp.ClassName('my-class'), + SelectorComp.Attr(['hello', 'world']), + ], + }), + ]) - expect(parse(`#something[data-testid="hello world"]`)).toEqual([ - Expr.Selector({ - tag: undefined, - id: 'something', - selectors: [SelectorComp.Attr(['data-testid', 'hello world'])], - }), - ]) + expect( + parseDeclarations( + `#something[data-testid="hello world"].wow input#password[type=password][placeholder="Password: ***"]`, + ), + ).toEqual([ + Expr.Selector({ + tag: undefined, + id: 'something', + selectors: [ + SelectorComp.Attr(['data-testid', 'hello world']), + SelectorComp.ClassName('wow'), + ], + }), + Expr.Selector({ + tag: 'input', + id: 'password', + selectors: [ + SelectorComp.Attr(['type', 'password']), + SelectorComp.Attr(['placeholder', 'Password: ***']), + ], + }), + ]) + }) + + it('should parse declarations', () => { + expect( + parseDeclarations( + `instance(button#something, map(--text: "wow", --color: red))`, + ), + ).toEqual([ + Expr.Call({ + name: 'instance', + args: [ + Expr.Selector({ + tag: 'button', + id: 'something', + selectors: [], + }), + Expr.Call({ + name: 'map', + args: [ + Expr.Pair({ key: '--text', value: Expr.LiteralString('wow') }), + Expr.Pair({ key: '--color', value: Expr.Identifier('red') }), + ], + }), + ], + }), + ]) + }) }) }) |
