diff --git a/lib/fulfill.js b/lib/assign.js similarity index 93% rename from lib/fulfill.js rename to lib/assign.js index a6e8b24..fa683b1 100644 --- a/lib/fulfill.js +++ b/lib/assign.js @@ -3,11 +3,11 @@ const isValidVal = v => Boolean(v || v === 0); /** - * Fulfills entity fields with the scope ones. + * Fills entity fields with the scope ones. * * @param {BemFile} file - incoming entity and tech * @param {BemFile} scope - context, the processing entity usually - * @returns {BemFile} - fulfilled entity and tech + * @returns {BemFile} - Filled entity and tech */ module.exports = function (file, scope) { const fEntity = file.entity || {}; diff --git a/lib/index.js b/lib/index.js index caf8c88..3d3fa53 100644 --- a/lib/index.js +++ b/lib/index.js @@ -24,6 +24,6 @@ module.exports = { subtract: require('./subtract'), intersect: require('./intersect'), parse: require('./parse'), - fulfill: require('./fulfill'), + assign: require('./assign'), normalizer: (version) => (normalize[version] || normalize.default) }; diff --git a/test/fulfill.test.js b/test/assign.test.js similarity index 86% rename from test/fulfill.test.js rename to test/assign.test.js index fc8cc03..191ebd3 100644 --- a/test/fulfill.test.js +++ b/test/assign.test.js @@ -1,108 +1,108 @@ 'use strict'; const test = require('ava'); -const fulfill = require('..').fulfill; +const assign = require('..').assign; test('entity block should dominate scope’s one', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b' } }, { entity: { block: 'sb' } }), { entity: { block: 'b' }, tech: null }); }); test('entity elem should dominate scope’s one', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b', elem: 'e' } }, { entity: { block: 'sb', elem: 'sb' } }), { entity: { block: 'b', elem: 'e' }, tech: null }); }); test('entity modName should dominate scope’s one for block', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b', modName: 'm' } }, { entity: { block: 'sb', modName: 'sm' } }), { entity: { block: 'b', modName: 'm' }, tech: null }); }); test('entity modVal should dominate scope’s one for block', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b', modName: 'm', modVal: 'v' } }, { entity: { block: 'sb', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'b', modName: 'm', modVal: 'v' }, tech: null }); }); test('entity modName should dominate scope’s one for block and elem', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b', elem: 'e', modName: 'm' } }, { entity: { block: 'sb', elem: 'se', modName: 'sm' } }), { entity: { block: 'b', elem: 'e', modName: 'm' }, tech: null }); }); test('entity modVal should dominate scope’s one for block and elem', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b', elem: 'e', modName: 'm', modVal: 'v' } }, { entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'b', elem: 'e', modName: 'm', modVal: 'v' }, tech: null }); }); test('entity elem should use scope’s block', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { elem: 'e' } }, { entity: { block: 'sb', elem: 'se' } }), { entity: { block: 'sb', elem: 'e' }, tech: null }); }); test('entity modName should use scope’s block', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { modName: 'm' } }, { entity: { block: 'sb', modName: 'sm' } }), { entity: { block: 'sb', modName: 'm' }, tech: null }); }); test('entity modName should use scope’s elem', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { modName: 'm' } }, { entity: { block: 'sb', elem: 'se', modName: 'sm' } }), { entity: { block: 'sb', elem: 'se', modName: 'm' }, tech: null }); }); test('entity modVal should use scope’s block and modName', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { modVal: 'v' } }, { entity: { block: 'sb', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'sb', modName: 'sm', modVal: 'v' }, tech: null }); }); test('entity modVal should use scope’s block, elem and modName', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { modVal: 'v' } }, { entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'v' }, tech: null }); }); -test('should fulfill entity for mod and val for block', t => { - t.deepEqual(fulfill( +test('should assign entity for mod and val for block', t => { + t.deepEqual(assign( { entity: { modName: 'm', modVal: 'v' } }, { entity: { block: 'sb' } }), { entity: { block: 'sb', modName: 'm', modVal: 'v' }, tech: null }); }); -test('should fulfill entity for mod and val for block and elem', t => { - t.deepEqual(fulfill( +test('should assign entity for mod and val for block and elem', t => { + t.deepEqual(assign( { entity: { modName: 'm', modVal: 'v' } }, { entity: { block: 'sb', elem: 'se' } }), { entity: { block: 'sb', elem: 'se', modName: 'm', modVal: 'v' }, tech: null }); }); test('should cut modName and modVal from scope for elem', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { elem: 'e' } }, { entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'sb', elem: 'e' }, tech: null }); }); test('should cut modVal from scope for modName', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { modName: 'm' } }, { entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'sb', elem: 'se', modName: 'm' }, tech: null }); @@ -111,28 +111,28 @@ test('should cut modVal from scope for modName', t => { // Edge cases test('should allow 0 as mod value', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { modVal: 0 } }, { entity: { block: 'sb', modName: 'sm' } }), { entity: { block: 'sb', modName: 'sm', modVal: 0 }, tech: null }); }); test('should use block for nothing', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { } }, { entity: { block: 'sb' } }), { entity: { block: 'sb' }, tech: null }); }); test('should return empty without scope', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { } }, { entity: { } }), { entity: { }, tech: null }); }); test('should use modVal from scope if nothing given', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { }, { entity: { block: 'sb', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'sb', modName: 'sm', modVal: 'sv' }, tech: null }); @@ -140,29 +140,29 @@ test('should use modVal from scope if nothing given', t => { // Tech related specs -test('fulfill should support tech grabbing from scope', t => { - t.deepEqual(fulfill( +test('assign should support tech grabbing from scope', t => { + t.deepEqual(assign( { entity: { block: 'b' } }, { entity: { }, tech: 'js' }), { entity: { block: 'b' }, tech: 'js' }); }); test('entity tech should dominate the scope’s one', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { entity: { block: 'b' }, tech: 'bemhtml' }, { entity: { }, tech: 'js' }), { entity: { block: 'b' }, tech: 'bemhtml' }); }); test('should merge with scope if only tech given', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { tech: 'bemhtml' }, { entity: { block: 'sb', elem: 'se' } }), { entity: { block: 'sb', elem: 'se' }, tech: 'bemhtml' }); }); test('should use modVal with scope if only tech given', t => { - t.deepEqual(fulfill( + t.deepEqual(assign( { tech: 'bemhtml' }, { entity: { block: 'sb', modName: 'sm', modVal: 'sv' } }), { entity: { block: 'sb', modName: 'sm', modVal: 'sv' }, tech: 'bemhtml' });