Skip to content

Commit

Permalink
feat: support simple mods as an array
Browse files Browse the repository at this point in the history
  • Loading branch information
qfox committed Oct 1, 2016
1 parent d9e6b2d commit 721620d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/normalize2.js
Expand Up @@ -167,8 +167,14 @@ module.exports = function (decl) {
return mods;
}

for (let modName in entity.mods) {
mods[modName] = entity.mods[modName];
if (Array.isArray(entity.mods)) {
entity.mods.forEach(modName => {
mods[modName] = true;
});
} else {
for (let modName in entity.mods) {
mods[modName] = entity.mods[modName];
}
}

return mods;
Expand Down
15 changes: 14 additions & 1 deletion test/normalize2/block-mods.test.js
Expand Up @@ -52,7 +52,7 @@ test('should support several mods', t => {
]);
});

test('should support array of mod values', t => {
test('should support array of mod values in object', t => {
const decl = {
block: 'block',
mods: {
Expand All @@ -67,3 +67,16 @@ test('should support array of mod values', t => {
{ entity: { block: 'block', modName: 'm1', modVal: 'v2' }, tech: undefined }
]);
});

test('should support array of mod values', t => {
const decl = {
block: 'block',
mods: ['m1', 'm2']
};

t.deepEqual(normalize(decl), [
{ entity: { block: 'block' }, tech: undefined },
{ entity: { block: 'block', modName: 'm1', modVal: true }, tech: undefined },
{ entity: { block: 'block', modName: 'm2', modVal: true }, tech: undefined }
]);
});
14 changes: 14 additions & 0 deletions test/normalize2/elem-mods.test.js
Expand Up @@ -42,3 +42,17 @@ test('should support elem of elem as array mods', t => {
{ entity: { block: 'block', elem: 'elem2', modName: 'm1', modVal: 'v1' }, tech: undefined }
]);
});

test('should support array of mod values', t => {
const decl = {
block: 'block',
elem: 'elem',
mods: ['m1', 'm2']
};

t.deepEqual(normalize(decl), [
{ entity: { block: 'block', elem: 'elem' }, tech: undefined },
{ entity: { block: 'block', elem: 'elem', modName: 'm1', modVal: true }, tech: undefined },
{ entity: { block: 'block', elem: 'elem', modName: 'm2', modVal: true }, tech: undefined }
]);
});

0 comments on commit 721620d

Please sign in to comment.