From b159cfa9f790268194b808dd062258f0e2b1b20b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1n=20D=C3=A9nes?= Date: Sun, 18 Jul 2021 00:39:33 +0200 Subject: [PATCH] Further testing --- src/ergogen.js | 5 +- src/points.js | 7 +- ...{002_adjustments.yaml => adjustments.yaml} | 0 test/points/adjustments___points.json | 130 +++++++++ .../{001_basic_2x2.yaml => basic_2x2.yaml} | 0 ...___points.json => basic_2x2___points.json} | 0 test/points/default.yaml | 3 + test/points/default___points.json | 34 +++ test/points/overrides.yaml | 16 ++ test/points/overrides___points.json | 246 ++++++++++++++++++ test/points/{000_units.yaml => units.yaml} | 0 ..._units___units.json => units___units.json} | 0 test/unit/interface.js | 3 +- 13 files changed, 440 insertions(+), 4 deletions(-) rename test/points/{002_adjustments.yaml => adjustments.yaml} (100%) create mode 100644 test/points/adjustments___points.json rename test/points/{001_basic_2x2.yaml => basic_2x2.yaml} (100%) rename test/points/{001_basic_2x2___points.json => basic_2x2___points.json} (100%) create mode 100644 test/points/default.yaml create mode 100644 test/points/default___points.json create mode 100644 test/points/overrides.yaml create mode 100644 test/points/overrides___points.json rename test/points/{000_units.yaml => units.yaml} (100%) rename test/points/{000_units___units.json => units___units.json} (100%) diff --git a/src/ergogen.js b/src/ergogen.js index c77919b..b2c8690 100644 --- a/src/ergogen.js +++ b/src/ergogen.js @@ -37,9 +37,12 @@ const process = async (raw, debug=false, logger=()=>{}) => { logger('Parsing points...') if (!config.points) { - throw new Error('Input does not contain any points!') + throw new Error('Input does not contain a points clause!') } const points = points_lib.parse(config.points, units) + if (!Object.keys(points).length) { + throw new Error('Input does not contain any points!') + } if (debug) { results.points = points results.demo = io.twodee(points_lib.visualize(points), debug) diff --git a/src/points.js b/src/points.js index fcc5168..cd44c44 100644 --- a/src/points.js +++ b/src/points.js @@ -40,6 +40,9 @@ const render_zone = exports._render_zone = (zone_name, zone, anchor, global_key, // column layout + if (!Object.keys(cols).length) { + cols.default = {} + } let first_col = true for (let [col_name, col] of Object.entries(cols)) { @@ -218,8 +221,8 @@ const perform_mirror = exports._perform_mirror = (point, axis) => { exports.parse = (config, units) => { // config sanitization - a.unexpected(config, 'points', ['units', 'zones', 'key', 'rotate', 'mirror']) - const zones = a.sane(config.zones || {}, 'points.zones', 'object')() + a.unexpected(config, 'points', ['zones', 'key', 'rotate', 'mirror']) + const zones = a.sane(config.zones, 'points.zones', 'object')() const global_key = a.sane(config.key || {}, 'points.key', 'object')() const global_rotate = a.sane(config.rotate || 0, 'points.rotate', 'number')(units) const global_mirror = config.mirror diff --git a/test/points/002_adjustments.yaml b/test/points/adjustments.yaml similarity index 100% rename from test/points/002_adjustments.yaml rename to test/points/adjustments.yaml diff --git a/test/points/adjustments___points.json b/test/points/adjustments___points.json new file mode 100644 index 0000000..82b843b --- /dev/null +++ b/test/points/adjustments___points.json @@ -0,0 +1,130 @@ +{ + "matrix_left_bottom": { + "x": 0, + "y": 0, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_left_bottom", + "colrow": "left_bottom", + "col": { + "stagger": 0, + "spread": 0, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": {}, + "key": {}, + "name": "left" + }, + "row": "bottom" + } + }, + "matrix_left_top": { + "x": 0, + "y": 19, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_left_top", + "colrow": "left_top", + "col": { + "stagger": 0, + "spread": 0, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": {}, + "key": {}, + "name": "left" + }, + "row": "top" + } + }, + "matrix_right_bottom": { + "x": 24.181350600000002, + "y": 5.750154, + "r": 5, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_right_bottom", + "colrow": "right_bottom", + "col": { + "stagger": 5, + "spread": 25, + "rotate": 5, + "origin": [ + -9, + -9 + ], + "rows": {}, + "key": {}, + "name": "right" + }, + "row": "bottom" + } + }, + "matrix_right_top": { + "x": 22.525391499999998, + "y": 24.6778532, + "r": 5, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_right_top", + "colrow": "right_top", + "col": { + "stagger": 5, + "spread": 25, + "rotate": 5, + "origin": [ + -9, + -9 + ], + "rows": {}, + "key": {}, + "name": "right" + }, + "row": "top" + } + } +} diff --git a/test/points/001_basic_2x2.yaml b/test/points/basic_2x2.yaml similarity index 100% rename from test/points/001_basic_2x2.yaml rename to test/points/basic_2x2.yaml diff --git a/test/points/001_basic_2x2___points.json b/test/points/basic_2x2___points.json similarity index 100% rename from test/points/001_basic_2x2___points.json rename to test/points/basic_2x2___points.json diff --git a/test/points/default.yaml b/test/points/default.yaml new file mode 100644 index 0000000..0e806d6 --- /dev/null +++ b/test/points/default.yaml @@ -0,0 +1,3 @@ +points: + zones: + matrix: {} \ No newline at end of file diff --git a/test/points/default___points.json b/test/points/default___points.json new file mode 100644 index 0000000..c13be2e --- /dev/null +++ b/test/points/default___points.json @@ -0,0 +1,34 @@ +{ + "matrix_default_default": { + "x": 0, + "y": 0, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_default_default", + "colrow": "default_default", + "col": { + "stagger": 0, + "spread": 0, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": {}, + "key": {}, + "name": "default" + }, + "row": "default" + } + } +} diff --git a/test/points/overrides.yaml b/test/points/overrides.yaml new file mode 100644 index 0000000..5c14031 --- /dev/null +++ b/test/points/overrides.yaml @@ -0,0 +1,16 @@ +points: + zones: + matrix: + columns: + left: + middle: + rows: + top: + right: + stagger: u + row_overrides: + home: + top: + rows: + bottom: + home: \ No newline at end of file diff --git a/test/points/overrides___points.json b/test/points/overrides___points.json new file mode 100644 index 0000000..aeff7d0 --- /dev/null +++ b/test/points/overrides___points.json @@ -0,0 +1,246 @@ +{ + "matrix_left_bottom": { + "x": 0, + "y": 0, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_left_bottom", + "colrow": "left_bottom", + "col": { + "stagger": 0, + "spread": 0, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": {}, + "key": {}, + "name": "left" + }, + "row": "bottom" + } + }, + "matrix_left_home": { + "x": 0, + "y": 19, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_left_home", + "colrow": "left_home", + "col": { + "stagger": 0, + "spread": 0, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": {}, + "key": {}, + "name": "left" + }, + "row": "home" + } + }, + "matrix_middle_bottom": { + "x": 19, + "y": 0, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_middle_bottom", + "colrow": "middle_bottom", + "col": { + "rows": { + "top": {} + }, + "stagger": 0, + "spread": 19, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "key": {}, + "name": "middle" + }, + "row": "bottom" + } + }, + "matrix_middle_home": { + "x": 19, + "y": 19, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_middle_home", + "colrow": "middle_home", + "col": { + "rows": { + "top": {} + }, + "stagger": 0, + "spread": 19, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "key": {}, + "name": "middle" + }, + "row": "home" + } + }, + "matrix_middle_top": { + "x": 19, + "y": 38, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_middle_top", + "colrow": "middle_top", + "col": { + "rows": { + "top": {} + }, + "stagger": 0, + "spread": 19, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "key": {}, + "name": "middle" + }, + "row": "top" + } + }, + "matrix_right_home": { + "x": 38, + "y": 19, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_right_home", + "colrow": "right_home", + "col": { + "stagger": 19, + "row_overrides": { + "home": {}, + "top": {} + }, + "spread": 19, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": { + "home": {}, + "top": {} + }, + "key": {}, + "name": "right" + }, + "row": "home" + } + }, + "matrix_right_top": { + "x": 38, + "y": 38, + "r": 0, + "meta": { + "shift": [ + 0, + 0 + ], + "rotate": 0, + "padding": 19, + "width": 1, + "height": 1, + "skip": false, + "asym": "both", + "name": "matrix_right_top", + "colrow": "right_top", + "col": { + "stagger": 19, + "row_overrides": { + "home": {}, + "top": {} + }, + "spread": 19, + "rotate": 0, + "origin": [ + 0, + 0 + ], + "rows": { + "home": {}, + "top": {} + }, + "key": {}, + "name": "right" + }, + "row": "top" + } + } +} diff --git a/test/points/000_units.yaml b/test/points/units.yaml similarity index 100% rename from test/points/000_units.yaml rename to test/points/units.yaml diff --git a/test/points/000_units___units.json b/test/points/units___units.json similarity index 100% rename from test/points/000_units___units.json rename to test/points/units___units.json diff --git a/test/unit/interface.js b/test/unit/interface.js index 2cfb3e4..9cad04a 100644 --- a/test/unit/interface.js +++ b/test/unit/interface.js @@ -51,7 +51,8 @@ describe('Interface', function() { ergogen.process(kle, true, logger).should.be.rejectedWith('KLE'), ergogen.process('not an object', true, logger).should.be.rejectedWith('object'), ergogen.process({}, true, logger).should.be.rejectedWith('empty'), - ergogen.process({not_points: {}}, true, () => {}).should.be.rejectedWith('any points') + ergogen.process({not_points: {}}, true, () => {}).should.be.rejectedWith('points clause'), + ergogen.process({points: {zones: {}}}, true, () => {}).should.be.rejectedWith('any points') ]) })