-
Notifications
You must be signed in to change notification settings - Fork 4
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
45 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
import Stylesheet from '../src/stylesheet' | ||
import Node from '../src/node' | ||
import { parseSelector } from '../src/selectors' | ||
|
||
const s = new Stylesheet() | ||
|
||
const appNode = new Node('App', {}, undefined, s) | ||
const appViewNode = new Node('AppView', {}, appNode, s) | ||
const elemNode = new Node('Elem', {variant: ['selected']}, appViewNode, s) | ||
const itemNode = new Node('Item', {}, elemNode, s) | ||
const textNode = new Node('Text', {prop1: 1}, itemNode, s) | ||
|
||
function createBenchFunc (sel, node, expected) { | ||
return function () { | ||
const actual = sel.matchContext(node) | ||
if (actual !== expected) { | ||
throw new Error(`expected ${expected} but got ${actual}`) | ||
} | ||
} | ||
} | ||
|
||
export default [ | ||
{ | ||
name: 'selectors: simple match', | ||
fn: createBenchFunc(parseSelector('Text'), textNode, true) | ||
}, | ||
{ | ||
name: 'selectors: simple not match', | ||
fn: createBenchFunc(parseSelector('NotExists'), textNode, false) | ||
}, | ||
{ | ||
name: 'selectors: complex match', | ||
fn: createBenchFunc(parseSelector('AppView Elem.selected Text'), textNode, true) | ||
}, | ||
{ | ||
name: 'selectors: complex not match', | ||
fn: createBenchFunc(parseSelector('NotExists Elem Text'), textNode, false) | ||
} | ||
] |
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