Skip to content

Commit

Permalink
fix(assign): prevent mod-val pollution to block entities
Browse files Browse the repository at this point in the history
  • Loading branch information
qfox committed Aug 31, 2016
1 parent a1c0707 commit 2f12d87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/assign.js
Expand Up @@ -17,7 +17,7 @@ module.exports = function (file, scope) {
tech: file.tech || scope.tech || null
};

if (Object.keys(file).length === 1 && file.tech) {
if (Object.keys(file).length === 0 || Object.keys(file).length === 1 && file.tech) {
Object.assign(result.entity, sEntity);
return result;
}
Expand All @@ -40,7 +40,7 @@ module.exports = function (file, scope) {
if (fEntity.modName) {
result.entity.modName = fEntity.modName;
isValidVal(fEntity.modVal) && (result.entity.modVal = fEntity.modVal);
} else if (sEntity.modName && (isValidVal(fEntity.modVal) || (isValidVal(sEntity.modVal)))) {
} else if (sEntity.modName && isValidVal(fEntity.modVal)) {
result.entity.modName = sEntity.modName;
result.entity.modVal = isValidVal(fEntity.modVal) ? fEntity.modVal : sEntity.modVal;
}
Expand Down
21 changes: 21 additions & 0 deletions test/assign.test.js
Expand Up @@ -45,6 +45,27 @@ test('entity modVal should dominate scope’s one for block and elem', t => {
{ entity: { block: 'b', elem: 'e', modName: 'm', modVal: 'v' }, tech: null });
});

test('entity with block should not be filled with scope\'s modName/modVal', t => {
t.deepEqual(assign(
{ entity: { block: 'b' } },
{ entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }),
{ entity: { block: 'b' }, tech: null });
});

test('entity with block and elem should not be filled with scope\'s modName/modVal', t => {
t.deepEqual(assign(
{ entity: { block: 'b', elem: 'e' } },
{ entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }),
{ entity: { block: 'b', elem: 'e' }, tech: null });
});

test('entity with elem should be filled with block only', t => {
t.deepEqual(assign(
{ entity: { elem: 'e' } },
{ entity: { block: 'sb', elem: 'se', modName: 'sm', modVal: 'sv' } }),
{ entity: { block: 'sb', elem: 'e' }, tech: null });
});

test('entity elem should use scope’s block', t => {
t.deepEqual(assign(
{ entity: { elem: 'e' } },
Expand Down

0 comments on commit 2f12d87

Please sign in to comment.