Skip to content

Commit

Permalink
fixup! fixup! fixup! fixup! feat: add fulfill method
Browse files Browse the repository at this point in the history
  • Loading branch information
qfox committed Jul 26, 2016
1 parent b10b663 commit 0554ebf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
4 changes: 2 additions & 2 deletions lib/fulfill.js → lib/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};
54 changes: 27 additions & 27 deletions test/fulfill.test.js → test/assign.test.js
Original file line number Diff line number Diff line change
@@ -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 });
Expand All @@ -111,58 +111,58 @@ 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 });
});

// 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' });
Expand Down

0 comments on commit 0554ebf

Please sign in to comment.