-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #161 from bem-sdk/yeti-or.react-preset
Add react preset
- Loading branch information
Showing
6 changed files
with
208 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
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
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
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,9 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
delims: { | ||
elem: '-', | ||
mod: { name: '_', val: '_' } | ||
}, | ||
wordPattern: '[a-zA-Z0-9]+' | ||
}; |
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,70 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
const naming = require('../../../index')('react'); | ||
const parse = naming.parse; | ||
|
||
test('should not parse not valid string', t => { | ||
const obj = parse('(*)(*)'); | ||
|
||
t.is(obj, undefined); | ||
}); | ||
|
||
test('should parse block', t => { | ||
const obj = parse('Block'); | ||
|
||
t.is(obj.block, 'Block'); | ||
}); | ||
|
||
test('should parse mod of block', t => { | ||
t.plan(3); | ||
|
||
const obj = parse('Block_mod_val'); | ||
|
||
t.is(obj.block, 'Block'); | ||
t.is(obj.mod && obj.mod.name, 'mod'); | ||
t.is(obj.mod && obj.mod.val, 'val'); | ||
}); | ||
|
||
test('should parse boolean mod of block', t => { | ||
t.plan(3); | ||
|
||
const obj = parse('block_mod'); | ||
|
||
t.is(obj.block, 'block'); | ||
t.is(obj.mod && obj.mod.name, 'mod'); | ||
|
||
t.true(obj.mod && obj.mod.val); | ||
}); | ||
|
||
test('should parse elem', t => { | ||
t.plan(2); | ||
|
||
const obj = parse('Block-Elem'); | ||
|
||
t.is(obj.block, 'Block'); | ||
t.is(obj.elem, 'Elem'); | ||
}); | ||
|
||
test('should parse mod of elem', t => { | ||
t.plan(4); | ||
|
||
const obj = parse('block-elem_mod_val'); | ||
|
||
t.is(obj.block, 'block'); | ||
t.is(obj.elem, 'elem'); | ||
t.is(obj.mod && obj.mod.name, 'mod'); | ||
t.is(obj.mod && obj.mod.val, 'val'); | ||
}); | ||
|
||
test('should parse boolean mod of elem', t => { | ||
t.plan(4); | ||
|
||
const obj = parse('block-elem_mod'); | ||
|
||
t.is(obj.block, 'block'); | ||
t.is(obj.elem, 'elem'); | ||
t.is(obj.mod && obj.mod.name, 'mod'); | ||
|
||
t.true(obj.mod && obj.mod.val); | ||
}); |
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,96 @@ | ||
'use strict'; | ||
|
||
const test = require('ava'); | ||
const naming = require('../../../index')('react'); | ||
const stringify = naming.stringify; | ||
|
||
test('should stringify block', t => { | ||
const str = stringify({ block: 'Block' }); | ||
|
||
t.is(str, 'Block'); | ||
}); | ||
|
||
test('should stringify modifier of block', t => { | ||
const str = stringify({ | ||
block: 'Block', | ||
mod: { name: 'mod', val: 'val' } | ||
}); | ||
|
||
t.is(str, 'Block_mod_val'); | ||
}); | ||
|
||
test('should stringify simple modifier of block', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
mod: 'mod' | ||
}); | ||
|
||
t.is(str, 'block_mod'); | ||
}); | ||
|
||
test('should stringify boolean modifier of block', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
mod: { name: 'mod', val: true }, | ||
}); | ||
|
||
t.is(str, 'block_mod'); | ||
}); | ||
|
||
test('should stringify block if modifier value is `undefined`', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
mod: { name: 'mod', val: undefined } | ||
}); | ||
|
||
t.is(str, 'block'); | ||
}); | ||
|
||
test('should stringify element', t => { | ||
const str = stringify({ | ||
block: 'Block', | ||
elem: 'Elem' | ||
}); | ||
|
||
t.is(str, 'Block-Elem'); | ||
}); | ||
|
||
test('should stringify modifier of element', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
elem: 'elem', | ||
mod: { name: 'mod', val: 'val' } | ||
}); | ||
|
||
t.is(str, 'block-elem_mod_val'); | ||
}); | ||
|
||
test('should stringify simple modifier of element', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
elem: 'elem', | ||
mod: 'mod' | ||
}); | ||
|
||
t.is(str, 'block-elem_mod'); | ||
}); | ||
|
||
test('should stringify boolean modifier of element', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
elem: 'elem', | ||
mod: { name: 'mod', val: true } | ||
}); | ||
|
||
t.is(str, 'block-elem_mod'); | ||
}); | ||
|
||
test('should stringify element if modifier value is `undefined`', t => { | ||
const str = stringify({ | ||
block: 'block', | ||
elem: 'elem', | ||
mod: { name: 'mod', val: undefined } | ||
}); | ||
|
||
t.is(str, 'block-elem'); | ||
}); |