-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
192 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,167 @@ | ||
import parse, { Combinator, Component } from '../src/parser'; | ||
|
||
describe('parsing of CSS syntax', () => { | ||
it('combinators', () => { | ||
expect(parse('something another-thing [ ] [ ] && | ||')).toMatchObject([ | ||
describe('parsing', () => { | ||
it('parses combinators', () => { | ||
expect(parse('something | another-thing')).toMatchObject([{}, { combinator: Combinator.SingleBar }, {}]); | ||
expect(parse('something || another-thing')).toMatchObject([{}, { combinator: Combinator.DoubleBar }, {}]); | ||
expect(parse('something && another-thing')).toMatchObject([{}, { combinator: Combinator.DoubleAmpersand }, {}]); | ||
expect(parse('something another-thing')).toMatchObject([{}, { combinator: Combinator.Juxtaposition }, {}]); | ||
}); | ||
|
||
it('parses components', () => { | ||
expect(parse('something <something> [ something <something> ]')).toMatchObject([ | ||
{ component: Component.Keyword }, | ||
{}, | ||
{ combinator: Combinator.Juxtaposition }, | ||
{ component: Component.DataType }, | ||
{}, | ||
{ combinator: Combinator.Juxtaposition }, | ||
{ | ||
component: Component.Group, | ||
entities: [{ component: Component.Keyword }, {}, { component: Component.DataType }], | ||
}, | ||
]); | ||
}); | ||
|
||
it('groups by combinator precedence', () => { | ||
expect(parse('something | something || something && something something')).toMatchObject([ | ||
{}, | ||
{ combinator: Combinator.SingleBar }, | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{}, | ||
{ combinator: Combinator.DoubleBar }, | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{}, | ||
{ combinator: Combinator.DoubleAmpersand }, | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.Juxtaposition }, {}], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
]); | ||
|
||
expect(parse('something something && something || something | something')).toMatchObject([ | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.Juxtaposition }, {}], | ||
}, | ||
{ combinator: Combinator.DoubleAmpersand }, | ||
{}, | ||
], | ||
}, | ||
{ combinator: Combinator.DoubleBar }, | ||
{}, | ||
], | ||
}, | ||
{ combinator: Combinator.SingleBar }, | ||
{}, | ||
]); | ||
|
||
expect(parse('[ something | something || something && something ] something')).toMatchObject([ | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{}, | ||
{ combinator: Combinator.SingleBar }, | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{}, | ||
{ combinator: Combinator.DoubleBar }, | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.DoubleAmpersand }, {}], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ combinator: Combinator.Juxtaposition }, | ||
{}, | ||
{ combinator: Combinator.DoubleAmpersand }, | ||
{ combinator: Combinator.SingleBar }, | ||
]); | ||
|
||
expect(parse('something [ something && something || something | something ]')).toMatchObject([ | ||
{}, | ||
{ combinator: Combinator.Juxtaposition }, | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.DoubleAmpersand }, {}], | ||
}, | ||
{ combinator: Combinator.DoubleBar }, | ||
{}, | ||
], | ||
}, | ||
{ combinator: Combinator.SingleBar }, | ||
{}, | ||
], | ||
}, | ||
]); | ||
|
||
expect(parse('something && something something || something')).toMatchObject([ | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{}, | ||
{ combinator: Combinator.DoubleAmpersand }, | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.Juxtaposition }, {}], | ||
}, | ||
], | ||
}, | ||
{ combinator: Combinator.DoubleBar }, | ||
{}, | ||
]); | ||
}); | ||
|
||
it('components', () => { | ||
expect(parse('something <color> [ ]')).toMatchObject([ | ||
{ component: Component.Keyword }, | ||
expect(parse('something || something something && something')).toMatchObject([ | ||
{}, | ||
{ component: Component.DataType }, | ||
{ combinator: Combinator.DoubleBar }, | ||
{ | ||
component: Component.Group, | ||
entities: [ | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.Juxtaposition }, {}], | ||
}, | ||
{ combinator: Combinator.DoubleAmpersand }, | ||
{}, | ||
], | ||
}, | ||
]); | ||
|
||
expect(parse('something | something something something')).toMatchObject([ | ||
{}, | ||
{ component: Component.Group }, | ||
{ combinator: Combinator.SingleBar }, | ||
{ | ||
component: Component.Group, | ||
entities: [{}, { combinator: Combinator.Juxtaposition }, {}, { combinator: Combinator.Juxtaposition }, {}], | ||
}, | ||
]); | ||
}); | ||
|
||
it('group components', () => { | ||
expect(parse('[ something | <color> ]')).toMatchObject([ | ||
expect(parse('something something something | something')).toMatchObject([ | ||
{ | ||
component: Component.Group, | ||
entities: [{ component: Component.Keyword }, {}, { component: Component.DataType }], | ||
entities: [{}, { combinator: Combinator.Juxtaposition }, {}, { combinator: Combinator.Juxtaposition }, {}], | ||
}, | ||
{ combinator: Combinator.SingleBar }, | ||
{}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters