From 72d8b8555c63460651f5473bfad9968fb87f0622 Mon Sep 17 00:00:00 2001 From: Anton Krichevskii Date: Mon, 3 Oct 2016 16:46:13 +0300 Subject: [PATCH] Normalize arrangement --- lib/index.js | 16 +--- lib/normalize.js | 92 ++----------------- .../harmony.js} | 0 lib/normalize/v1.js | 80 ++++++++++++++++ lib/{normalize2.js => normalize/v2.js} | 0 lib/parse.js | 24 ++--- test/index.test.js | 35 ------- test/normalize-harmony/block.test.js | 2 +- test/normalize-harmony/common.test.js | 2 +- test/normalize-harmony/elem.test.js | 2 +- test/normalize-harmony/elems.test.js | 2 +- test/normalize-harmony/mix.test.js | 2 +- test/normalize-harmony/mods.test.js | 2 +- test/normalize-harmony/scope.test.js | 2 +- test/normalize/common.test.js | 2 +- test/normalize/elems.test.js | 2 +- test/normalize/mods.test.js | 2 +- test/normalize2/block-mod.test.js | 2 +- test/normalize2/block-mods.test.js | 2 +- test/normalize2/block.test.js | 2 +- test/normalize2/common.test.js | 2 +- test/normalize2/elem-mod.test.js | 2 +- test/normalize2/elem-mods.test.js | 2 +- test/normalize2/elem.test.js | 2 +- test/normalize2/elems-mod.test.js | 2 +- test/normalize2/elems-mods.test.js | 2 +- test/normalize2/elems.test.js | 2 +- test/normalize2/iterable.test.js | 2 +- test/normalize2/mod-mods-vals.test.js | 2 +- test/normalize2/unusual.test.js | 2 +- test/parse/common.test.js | 4 +- test/parse/enb.test.js | 8 +- test/parse/harmony.test.js | 8 +- test/parse/v1.test.js | 8 +- test/parse/v2.test.js | 8 +- 35 files changed, 145 insertions(+), 184 deletions(-) rename lib/{normalize-harmony.js => normalize/harmony.js} (100%) create mode 100644 lib/normalize/v1.js rename lib/{normalize2.js => normalize/v2.js} (100%) diff --git a/lib/index.js b/lib/index.js index 1ab8d4b..8db5184 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,24 +1,12 @@ 'use strict'; -const normalize = { - v1: require('./normalize'), - v2: require('./normalize2'), - harmony: require('./normalize-harmony'), - enb: require('./normalize2') -}; - module.exports = { - normalize: (decl, opts) => { - opts || (opts = {}); - - return opts.format ? normalize[opts.format](decl) : normalize.v2(decl); - }, + normalize: require('./normalize'), merge: require('./merge'), subtract: require('./subtract'), intersect: require('./intersect'), parse: require('./parse'), assign: require('./assign'), load: require('./load'), - stringify: require('./stringify'), - normalizer: format => (normalize[format] || normalize.v2) + stringify: require('./stringify') }; diff --git a/lib/normalize.js b/lib/normalize.js index 2ad99a6..e31a9fa 100644 --- a/lib/normalize.js +++ b/lib/normalize.js @@ -1,88 +1,16 @@ 'use strict'; -const naming = require('bem-naming'); - -module.exports = function (decl) { - const res = []; - const hash = {}; - - function add(entity) { - const str = naming.stringify(entity); - - if (!hash[str]) { - res.push({ entity: entity, tech: null }); - } - - hash[str] = true; - } - - if (!decl) { return []; } - if (!Array.isArray(decl)) { decl = [decl]; } - - for (let i = 0; i < decl.length; ++i) { - const entity = decl[i]; - const block = entity.name; - const mods = entity.mods; - const elems = entity.elems; - - add({ block: block }); - - if (mods) { - normalizeMods(block, mods); - } - - if (elems) { - for (let j = 0; j < elems.length; ++j) { - const elem = elems[j]; - const elemName = elem.name; - const elemMods = elem.mods; - - add({ block: block, elem: elemName }); - - if (elemMods) { - normalizeMods(block, elemName, elemMods); - } - } - } - } - - function normalizeMods(block, elem, mods) { - const isElem = arguments.length === 3; - - if (!isElem) { - mods = elem; - } - - for (let i = 0; i < mods.length; ++i) { - const mod = mods[i]; - const vals = mod.vals; - const l = vals && vals.length; - - let resItem; - - if (l) { - for (let j = 0; j < l; ++j) { - resItem = { - block: block, - modName: mod.name, modVal: vals[j].name - }; - - isElem && (resItem.elem = elem); - - add(resItem); - } - } else { - resItem = { - block: block, - modName: mod.name, modVal: true - }; +const normalizer = { + v1: require('./normalize/v1'), + v2: require('./normalize/v2'), + harmony: require('./normalize/harmony'), + enb: require('./normalize/v2') +}; - isElem && (resItem.elem = elem); +module.exports = (decl, opts) => { + opts || (opts = {}); - add(resItem); - } - } - } + const format = opts.format || 'v2'; - return res; + return normalizer[format](decl); }; diff --git a/lib/normalize-harmony.js b/lib/normalize/harmony.js similarity index 100% rename from lib/normalize-harmony.js rename to lib/normalize/harmony.js diff --git a/lib/normalize/v1.js b/lib/normalize/v1.js new file mode 100644 index 0000000..ff600fe --- /dev/null +++ b/lib/normalize/v1.js @@ -0,0 +1,80 @@ +'use strict'; + +const naming = require('bem-naming'); + +module.exports = function (decl) { + const res = []; + const hash = {}; + + function add(entity) { + const str = naming.stringify(entity); + + if (!hash[str]) { + res.push({ entity: entity, tech: null }); + } + + hash[str] = true; + } + + if (!decl) { return []; } + if (!Array.isArray(decl)) { decl = [decl]; } + + for (let i = 0; i < decl.length; ++i) { + const entity = decl[i]; + const block = entity.name; + const mods = entity.mods; + const elems = entity.elems; + + add({ block: block }); + + if (mods) { + normalizeMods(block, mods); + } + + if (elems) { + for (let j = 0; j < elems.length; ++j) { + const elem = elems[j]; + const elemName = elem.name; + const elemMods = elem.mods; + + add({ block: block, elem: elemName }); + + if (elemMods) { + normalizeMods(block, elemName, elemMods); + } + } + } + } + + function normalizeMods(block, elem, mods) { + const isElem = arguments.length === 3; + + if (!isElem) { + mods = elem; + } + + for (let i = 0; i < mods.length; ++i) { + const mod = mods[i]; + const vals = mod.vals; + const hasVals = vals && vals.length; + + let resItem; + let j = 0; + + do { + resItem = { + block: block, + modName: mod.name, + modVal: hasVals ? vals[j].name : true + }; + + isElem && (resItem.elem = elem); + + add(resItem); + ++j; + } while (j < hasVals); + } + } + + return res; +}; diff --git a/lib/normalize2.js b/lib/normalize/v2.js similarity index 100% rename from lib/normalize2.js rename to lib/normalize/v2.js diff --git a/lib/parse.js b/lib/parse.js index 0e7f48a..f3f7617 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -5,15 +5,6 @@ const assert = require('assert'); const nodeEval = require('node-eval'); const detect = require('./detect'); -const normalize = require('./normalize'); -const normalize2 = require('./normalize2'); -const normalizeHarmony = require('./normalize-harmony'); - -const normalizers = { - v1: normalize, - v2: normalize2, - harmony: normalizeHarmony -}; /** * Parses BEMDECL file data @@ -24,22 +15,31 @@ const normalizers = { module.exports = function parse(bemdecl) { assert(typeof bemdecl === 'object' || typeof bemdecl === 'string', 'Bemdecl must be String or Object'); + const normalize = require('.').normalize; + const declaration = (typeof bemdecl === 'string') ? nodeEval(bemdecl) : bemdecl; const hasOwn = Object.prototype.hasOwnProperty.bind(Object(declaration)); const format = declaration.format || detect(declaration); + let decl; + switch (format) { case 'v1': assert(hasOwn('blocks'), 'Invalid declaration format'); - return normalizers.v1(declaration.blocks); + decl = declaration.blocks; + break; case 'v2': case 'enb': assert(hasOwn('decl') || hasOwn('deps'), 'Invalid format of declaration.'); - return normalizers.v2(declaration.decl || declaration.deps); + decl = declaration.decl || declaration.deps; + break; case 'harmony': assert(hasOwn('decl'), 'Invalid format of declaration.'); - return normalizers.harmony(declaration.decl); + decl = declaration.decl; + break; default: throw new Error('Unknown BEMDECL format.'); } + + return normalize(decl, { format: format }); }; diff --git a/test/index.test.js b/test/index.test.js index 3255852..4a2be7d 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -31,41 +31,6 @@ test('should support `BEMDECL 2.0` format', t => { t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); }); -test('should have `normalizer` method', t => { - t.truthy(typeof bemDecl.normalizer === 'function'); -}); - -test('normalizer should support default value as `normalize`', t => { - var decl = bemDecl.normalizer('v1')(decls.v1); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - -test('should support `BEMDECL 1.0` format through normalizer', t => { - var decl = bemDecl.normalizer('v1')(decls.v1); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - -// TODO: define name of format -test('should have support `BEMDECL x.0` format through normalizer', t => { - var decl = bemDecl.normalizer('v2')(decls.v2); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}) - -test('should support `BEMDECL 2.0` format through normalizer', t => { - var decl = bemDecl.normalizer('harmony')(decls.v2); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - -test('should support uncorrect normalizer arg with default result', t => { - var decl = bemDecl.normalizer('levoe')(decls.v2); - - t.deepEqual(decl, [{ entity: decls.normalized, tech: null }]); -}); - test('should have `merge` method', t => { t.truthy(typeof bemDecl.merge === 'function'); }); diff --git a/test/normalize-harmony/block.test.js b/test/normalize-harmony/block.test.js index d969b89..d5fad5c 100644 --- a/test/normalize-harmony/block.test.js +++ b/test/normalize-harmony/block.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support block', t => { var block = { block: 'block' }; diff --git a/test/normalize-harmony/common.test.js b/test/normalize-harmony/common.test.js index 9f9eb0e..3ce526e 100644 --- a/test/normalize-harmony/common.test.js +++ b/test/normalize-harmony/common.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support undefined', t => { t.deepEqual(normalize(), []); diff --git a/test/normalize-harmony/elem.test.js b/test/normalize-harmony/elem.test.js index f340c2d..c16b51b 100644 --- a/test/normalize-harmony/elem.test.js +++ b/test/normalize-harmony/elem.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support elem', t => { const decl = { block: 'block', elem: 'elem' }; diff --git a/test/normalize-harmony/elems.test.js b/test/normalize-harmony/elems.test.js index eafb2f8..d95d9c4 100644 --- a/test/normalize-harmony/elems.test.js +++ b/test/normalize-harmony/elems.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support strings', t => { const decl = { diff --git a/test/normalize-harmony/mix.test.js b/test/normalize-harmony/mix.test.js index 434330a..8d22f6b 100644 --- a/test/normalize-harmony/mix.test.js +++ b/test/normalize-harmony/mix.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support mix', t => { const decl = { diff --git a/test/normalize-harmony/mods.test.js b/test/normalize-harmony/mods.test.js index 33e0974..3a7434c 100644 --- a/test/normalize-harmony/mods.test.js +++ b/test/normalize-harmony/mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support shortcut for bool mod', t => { const decl = { block: 'block', modName: 'mod' }; diff --git a/test/normalize-harmony/scope.test.js b/test/normalize-harmony/scope.test.js index b216835..903ab22 100644 --- a/test/normalize-harmony/scope.test.js +++ b/test/normalize-harmony/scope.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize-harmony'); +const normalize = require('../../lib/normalize/harmony'); test('should support mod in block scope', t => { const decl = { diff --git a/test/normalize/common.test.js b/test/normalize/common.test.js index f3dcdd3..c772d6b 100644 --- a/test/normalize/common.test.js +++ b/test/normalize/common.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize'); +const normalize = require('../../lib/normalize/v1'); test('should support undefined', t => { t.deepEqual(normalize(), []); diff --git a/test/normalize/elems.test.js b/test/normalize/elems.test.js index cd25200..54c3a84 100644 --- a/test/normalize/elems.test.js +++ b/test/normalize/elems.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize'); +const normalize = require('../../lib/normalize/v1'); test('should support arrays', t => { const decl = { diff --git a/test/normalize/mods.test.js b/test/normalize/mods.test.js index 289c443..2c85a7b 100644 --- a/test/normalize/mods.test.js +++ b/test/normalize/mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize'); +const normalize = require('../../lib/normalize/v1'); test('should support objects', t => { const decl = { name: 'block', mods: [{ name: 'mod', vals: [{ name: 'val' }] }] }; diff --git a/test/normalize2/block-mod.test.js b/test/normalize2/block-mod.test.js index 489d91f..f82787c 100644 --- a/test/normalize2/block-mod.test.js +++ b/test/normalize2/block-mod.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support mod', t => { const decl = { diff --git a/test/normalize2/block-mods.test.js b/test/normalize2/block-mods.test.js index b452743..f28c185 100644 --- a/test/normalize2/block-mods.test.js +++ b/test/normalize2/block-mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('sould support mods', t => { const decl = { diff --git a/test/normalize2/block.test.js b/test/normalize2/block.test.js index 433b7b3..b0746de 100644 --- a/test/normalize2/block.test.js +++ b/test/normalize2/block.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support block', t => { t.deepEqual(normalize({ block: 'block' }), [ diff --git a/test/normalize2/common.test.js b/test/normalize2/common.test.js index 868fc04..f3dee38 100644 --- a/test/normalize2/common.test.js +++ b/test/normalize2/common.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support undefined', t => { t.deepEqual(normalize(), []); diff --git a/test/normalize2/elem-mod.test.js b/test/normalize2/elem-mod.test.js index 34c42f6..6342bdd 100644 --- a/test/normalize2/elem-mod.test.js +++ b/test/normalize2/elem-mod.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support shortcut for bool mod of elem', t => { const decl = { block: 'block', elem: 'elem', mod: 'mod' }; diff --git a/test/normalize2/elem-mods.test.js b/test/normalize2/elem-mods.test.js index 127708c..9b411f2 100644 --- a/test/normalize2/elem-mods.test.js +++ b/test/normalize2/elem-mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support elem as object and mod', t => { const decl = { diff --git a/test/normalize2/elem.test.js b/test/normalize2/elem.test.js index 831041c..dac7171 100644 --- a/test/normalize2/elem.test.js +++ b/test/normalize2/elem.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support elem', t => { const decl = { block: 'block', elem: 'elem' }; diff --git a/test/normalize2/elems-mod.test.js b/test/normalize2/elems-mod.test.js index 84c4677..65f5098 100644 --- a/test/normalize2/elems-mod.test.js +++ b/test/normalize2/elems-mod.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support shortcut for bool mod of elem', t => { const decl = { block: 'block', elems: 'elem', mod: 'mod' }; diff --git a/test/normalize2/elems-mods.test.js b/test/normalize2/elems-mods.test.js index 396dbf6..644dd82 100644 --- a/test/normalize2/elems-mods.test.js +++ b/test/normalize2/elems-mods.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support elem as object and mod', t => { const decl = { diff --git a/test/normalize2/elems.test.js b/test/normalize2/elems.test.js index e94666e..8d0d6f3 100644 --- a/test/normalize2/elems.test.js +++ b/test/normalize2/elems.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support elems', t => { const decl = { block: 'block', elems: 'elem' }; diff --git a/test/normalize2/iterable.test.js b/test/normalize2/iterable.test.js index 8de0d8e..c2c3fa8 100644 --- a/test/normalize2/iterable.test.js +++ b/test/normalize2/iterable.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support iterable set', t => { const decl = new Set(); diff --git a/test/normalize2/mod-mods-vals.test.js b/test/normalize2/mod-mods-vals.test.js index 1b169a2..e6577f6 100644 --- a/test/normalize2/mod-mods-vals.test.js +++ b/test/normalize2/mod-mods-vals.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support mod and mods without block, elem', t => { const decl = [ diff --git a/test/normalize2/unusual.test.js b/test/normalize2/unusual.test.js index 956fdac..7b2703b 100644 --- a/test/normalize2/unusual.test.js +++ b/test/normalize2/unusual.test.js @@ -1,7 +1,7 @@ 'use strict'; const test = require('ava'); -const normalize = require('../../lib/normalize2'); +const normalize = require('../../lib/normalize/v2'); test('should support both mod and mods', t => { const decl = { diff --git a/test/parse/common.test.js b/test/parse/common.test.js index e7158a7..1b9f491 100644 --- a/test/parse/common.test.js +++ b/test/parse/common.test.js @@ -8,9 +8,9 @@ test('should throw if undefined', t => { }); test('should throw if unsupported', t => { - t.throws(() => parse('({ version: \'unknown\', components: [] })'), /Unknown BEMDECL format/); + t.throws(() => parse('({ format: \'unknown\', components: [] })'), /Unknown BEMDECL format/); }); test('should throw if unsupported in object', t => { - t.throws(() => parse({ version: 'unknown', components: [] }), /Unknown BEMDECL format/); + t.throws(() => parse({ format: 'unknown', components: [] }), /Unknown BEMDECL format/); }); diff --git a/test/parse/enb.test.js b/test/parse/enb.test.js index b9c0312..064f5e9 100644 --- a/test/parse/enb.test.js +++ b/test/parse/enb.test.js @@ -4,22 +4,22 @@ const test = require('ava'); const parse = require('../../lib/parse'); -test('should throw error while parsing empty deps property if version not given', t => { +test('should throw error while parsing empty deps property if format not given', t => { t.deepEqual(parse('({ deps: [] })'), []); }); test('should parse blocks property with single entity', t => { - t.deepEqual(parse('({ version: \'enb\', deps: [{ block: \'doesnt-matter\', elems: [\'elem\'] }] })'), + t.deepEqual(parse('({ format: \'enb\', deps: [{ block: \'doesnt-matter\', elems: [\'elem\'] }] })'), [{ entity: { block: 'doesnt-matter' }, tech: null }, { entity: { block: 'doesnt-matter', elem: 'elem' }, tech: null }]); }); test('should parse empty legacy blocks property of object', t => { - t.deepEqual(parse({ version: 'enb', deps: [] }), []); + t.deepEqual(parse({ format: 'enb', deps: [] }), []); }); test('should parse blocks property with single entity of object', t => { - t.deepEqual(parse({ version: 'enb', deps: [{ block: 'doesnt-matter', elems: ['elem'] }] }), + t.deepEqual(parse({ format: 'enb', deps: [{ block: 'doesnt-matter', elems: ['elem'] }] }), [{ entity: { block: 'doesnt-matter' }, tech: null }, { entity: { block: 'doesnt-matter', elem: 'elem' }, tech: null }]); }); diff --git a/test/parse/harmony.test.js b/test/parse/harmony.test.js index b9af812..41a745b 100644 --- a/test/parse/harmony.test.js +++ b/test/parse/harmony.test.js @@ -4,21 +4,21 @@ const test = require('ava'); const parse = require('../..').parse; test('should parse empty legacy blocks property', t => { - t.deepEqual(parse('({ version: \'harmony\', decl: [] })'), []); + t.deepEqual(parse('({ format: \'harmony\', decl: [] })'), []); }); test('should parse blocks property with single entity', t => { - t.deepEqual(parse('({ version: \'harmony\', decl: [{ block: \'doesnt-matter\', elems: [\'elem\'] }] })'), + t.deepEqual(parse('({ format: \'harmony\', decl: [{ block: \'doesnt-matter\', elems: [\'elem\'] }] })'), [{ entity: { block: 'doesnt-matter' }, tech: null }, { entity: { block: 'doesnt-matter', elem: 'elem' }, tech: null }]); }); test('should parse empty legacy blocks property of object', t => { - t.deepEqual(parse({ version: 'harmony', decl: [] }), []); + t.deepEqual(parse({ format: 'harmony', decl: [] }), []); }); test('should parse blocks property with single entity of object', t => { - t.deepEqual(parse({ version: 'harmony', decl: [{ block: 'doesnt-matter', elems: ['elem'] }] }), + t.deepEqual(parse({ format: 'harmony', decl: [{ block: 'doesnt-matter', elems: ['elem'] }] }), [{ entity: { block: 'doesnt-matter' }, tech: null }, { entity: { block: 'doesnt-matter', elem: 'elem' }, tech: null }]); }); diff --git a/test/parse/v1.test.js b/test/parse/v1.test.js index f30e112..070f949 100644 --- a/test/parse/v1.test.js +++ b/test/parse/v1.test.js @@ -4,19 +4,19 @@ const test = require('ava'); const parse = require('../..').parse; test('should parse empty legacy blocks property', t => { - t.deepEqual(parse('({ version: \'v1\', blocks: [] })'), []); + t.deepEqual(parse('({ format: \'v1\', blocks: [] })'), []); }); test('should parse blocks property with single entity', t => { - t.deepEqual(parse('({ version: \'v1\', blocks: [{ name: \'doesnt-matter\' }] })'), + t.deepEqual(parse('({ format: \'v1\', blocks: [{ name: \'doesnt-matter\' }] })'), [{ entity: { block: 'doesnt-matter' }, tech: null }]); }); test('should parse empty legacy blocks property of object', t => { - t.deepEqual(parse({ version: 'v1', blocks: [] }), []); + t.deepEqual(parse({ format: 'v1', blocks: [] }), []); }); test('should parse blocks property with single entity of object', t => { - t.deepEqual(parse({ version: 'v1', blocks: [{ name: 'doesnt-matter' }] }), + t.deepEqual(parse({ format: 'v1', blocks: [{ name: 'doesnt-matter' }] }), [{ entity: { block: 'doesnt-matter' }, tech: null }]); }); diff --git a/test/parse/v2.test.js b/test/parse/v2.test.js index 931b1e0..a77ef66 100644 --- a/test/parse/v2.test.js +++ b/test/parse/v2.test.js @@ -4,21 +4,21 @@ const test = require('ava'); const parse = require('../..').parse; test('should parse empty legacy blocks property', t => { - t.deepEqual(parse('({ version: \'v2\', decl: [] })'), []); + t.deepEqual(parse('({ format: \'v2\', decl: [] })'), []); }); test('should parse blocks property with single entity', t => { - t.deepEqual(parse('({ version: \'v2\', decl: [{ block: \'doesnt-matter\', elems: [\'elem\'] }] })'), + t.deepEqual(parse('({ format: \'v2\', decl: [{ block: \'doesnt-matter\', elems: [\'elem\'] }] })'), [{ entity: { block: 'doesnt-matter' }, tech: null }, { entity: { block: 'doesnt-matter', elem: 'elem' }, tech: null }]); }); test('should parse empty legacy blocks property of object', t => { - t.deepEqual(parse({ version: 'v2', decl: [] }), []); + t.deepEqual(parse({ format: 'v2', decl: [] }), []); }); test('should parse blocks property with single entity of object', t => { - t.deepEqual(parse({ version: 'v2', decl: [{ block: 'doesnt-matter', elems: ['elem'] }] }), + t.deepEqual(parse({ format: 'v2', decl: [{ block: 'doesnt-matter', elems: ['elem'] }] }), [{ entity: { block: 'doesnt-matter' }, tech: null }, { entity: { block: 'doesnt-matter', elem: 'elem' }, tech: null }]); });