Skip to content

Commit

Permalink
Add mods and mod without block and elem behvr
Browse files Browse the repository at this point in the history
  • Loading branch information
skad0 committed Jul 29, 2016
1 parent 56579af commit 6ac5700
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/normalize2.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function (decl) {
block = entity;
} else {
block = entity.block || null;
elem = entity.elem;
elem = entity.elem || null;
elems = entity.elems;
mod = getMod(entity);
mods = getMods(entity);
Expand Down Expand Up @@ -79,6 +79,10 @@ module.exports = function (decl) {
processMods({ block, mods: mods, tech });
}

if (!isNotActual(mod) && (!elems && !elem)) {
processMods({ block, mods: mod, tech });
}

if (elems) {
if (!Array.isArray(elems)) {
elems = [elems];
Expand Down
13 changes: 13 additions & 0 deletions test/normalize2/elem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ test('should support elem of elem as array', t => {
{ entity: { block: 'block', elem: 'elem2' }, tech: undefined }
]);
});

test('should support elem without block', t => {
const decl = {
elem: [
{ elem: ['elem1', 'elem2'] }
]
};

t.deepEqual(normalize(decl), [
{ entity: { block: null, elem: 'elem1' }, tech: undefined },
{ entity: { block: null, elem: 'elem2' }, tech: undefined }
]);
});
34 changes: 34 additions & 0 deletions test/normalize2/mod-mods-vals.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const test = require('ava');
const normalize = require('../../lib/normalize2');

test('should support mod and mods without block, elem', t => {
const decl = [
{ mod: 'mod', val: 'val' },
{ mods: { mod1: 'val1' } }
];

t.deepEqual(normalize(decl), [
{ entity: { block: null, modName: 'mod', modVal: 'val' }, tech: undefined },
{ entity: { block: null }, tech: undefined },
{ entity: { block: null, modName: 'mod1', modVal: 'val1' }, tech: undefined }
]);
});

test('should support mod without block & elem', t => {
const decl = { mod: 'mod', val: 'val' };

t.deepEqual(normalize(decl), [
{ entity: { block: null, modName: 'mod', modVal: 'val' }, tech: undefined }
]);
});

test('should support mods without block & elem', t => {
const decl = { mods: { mod: 'val' } };

t.deepEqual(normalize(decl), [
{ entity: { block: null }, tech: undefined },
{ entity: { block: null, modName: 'mod', modVal: 'val' }, tech: undefined }
]);
});

0 comments on commit 6ac5700

Please sign in to comment.