summaryrefslogtreecommitdiff
path: root/tests/parser.spec.ts
diff options
context:
space:
mode:
Diffstat (limited to 'tests/parser.spec.ts')
-rw-r--r--tests/parser.spec.ts63
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'])],
+ }),
+ ])
+ })
})