diff options
| author | Akshay Nair <phenax5@gmail.com> | 2023-08-13 12:05:41 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2023-08-13 12:05:41 +0530 |
| commit | 1e8135bf0e24e39f4dc3f8b0a13241ddf0cf475c (patch) | |
| tree | ffc8cfa72e60b29921916607b352ba5139b34eee /tests | |
| parent | a61f5ec92a9382b0c25fae9a344da0d7eb21b702 (diff) | |
| download | css-everything-1e8135bf0e24e39f4dc3f8b0a13241ddf0cf475c.tar.gz css-everything-1e8135bf0e24e39f4dc3f8b0a13241ddf0cf475c.zip | |
feat: selector parser + pair parser implemented
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/parser.spec.ts | 63 |
1 files changed, 57 insertions, 6 deletions
diff --git a/tests/parser.spec.ts b/tests/parser.spec.ts index 41fafa3..b03e073 100644 --- a/tests/parser.spec.ts +++ b/tests/parser.spec.ts @@ -1,4 +1,4 @@ -import { Expr, parse } from '../src/parser' +import { Expr, SelectorComp, parse } from '../src/parser' describe('parser', () => { it('should parse function call', () => { @@ -44,13 +44,13 @@ describe('parser', () => { }) it('should parse string literal', () => { - expect(parse(`"hello world toodles \' nice single quote there"`)).toEqual([ - Expr.LiteralString(`hello world toodles \' nice single quote there`), + expect(parse(`"hello world toodles ' nice single quote there"`)).toEqual([ + Expr.LiteralString(`hello world toodles ' nice single quote there`), ]) - expect(parse(` 'hello world toodles \" nice double quote there' `)).toEqual( - [Expr.LiteralString(`hello world toodles \" nice double quote there`)], - ) + expect(parse(` 'hello world toodles " nice double quote there' `)).toEqual([ + Expr.LiteralString(`hello world toodles " nice double quote there`), + ]) }) it('should parse var identifiers', () => { @@ -124,4 +124,55 @@ describe('parser', () => { Expr.LiteralNumber({ value: -3.82, unit: 'ms' }), ]) }) + + it('should parse pair and map expressions', () => { + expect(parse(`--hello: "foobar is here"`)).toEqual([ + Expr.Pair({ + key: '--hello', + value: Expr.LiteralString('foobar is here'), + }), + ]) + + expect( + parse(`map(--hello: "foobar is here", --test-var : var(--other-var))`), + ).toEqual([ + Expr.Call({ + name: 'map', + args: [ + Expr.Pair({ + key: '--hello', + value: Expr.LiteralString('foobar is here'), + }), + Expr.Pair({ + key: '--test-var', + value: Expr.Call({ + name: 'var', + args: [Expr.VarIdentifier('--other-var')], + }), + }), + ], + }), + ]) + }) + + 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']), + ], + }), + ]) + + expect(parse(`#something[data-testid="hello world"]`)).toEqual([ + Expr.Selector({ + tag: undefined, + id: 'something', + selectors: [SelectorComp.Attr(['data-testid', 'hello world'])], + }), + ]) + }) }) |
