Refactor, units, tests

This commit is contained in:
Bán Dénes 2021-01-01 00:50:04 +01:00
parent 519c34bc60
commit cd90705ba1
24 changed files with 1221 additions and 1222 deletions

28
test/complex/index.js Normal file
View file

@ -0,0 +1,28 @@
const fs = require('fs-extra')
const path = require('path')
const yaml = require('js-yaml')
const glob = require('glob')
const u = require('../../src/utils')
const ergogen = require('../../src/ergogen')
const cap = s => s.charAt(0).toUpperCase() + s.slice(1)
for (const part of ['points', 'outlines', 'cases', 'pcbs']) {
describe(cap(part), function() {
const dir = path.join(__dirname, part)
for (const input_path of glob.sync(path.join(dir, '*.yaml'))) {
const basename = path.basename(input_path, '.yaml')
const title = basename.split('_').join(' ')
it(title, function() {
const dirname = path.dirname(input_path)
const input = yaml.load(fs.readFileSync(input_path).toString())
const actual = ergogen.process(input, true)
for (const expected_path of glob.sync(path.join(dirname, basename + '___*'))) {
const expected = JSON.parse(fs.readFileSync(expected_path).toString())
const comp_path = expected_path.split('___')[1].split('.')[0].split('_').join('.')
u.deep(actual, comp_path).should.deep.equal(expected)
}
})
}
})
}

View file

@ -0,0 +1,24 @@
points:
zones:
matrix:
columns:
left.key.bind: [,10,,]
right.key.bind: [,,,10]
rows:
bottom.key.bind: [10,,,]
top.key.bind: [,,10,]
key:
bind: [0, 0, 0, 0]
outlines:
exports:
outline:
main:
type: keys
side: left
size: 20
min:
type: keys
side: left
bound: false
size: 14
operation: subtract

View file

@ -0,0 +1,506 @@
{
"outline": {
"models": {
"a": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {
"a": {
"models": {
"a": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {
"a": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
-10,
-10
],
"end": [
29,
-10
]
},
"ShapeLine4": {
"type": "line",
"origin": [
-10,
-10
],
"end": [
-10,
29
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {
"a": {
"paths": {
"ShapeLine3": {
"type": "line",
"origin": [
-10,
29
],
"end": [
29,
29
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {
"a": {
"paths": {
"ShapeLine2": {
"type": "line",
"origin": [
29,
-10
],
"end": [
29,
29
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {
"a": {
"paths": {},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"models": {
"a": {
"models": {
"a": {
"models": {
"a": {
"models": {
"a": {
"models": {},
"origin": [
0,
0
]
},
"b": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
-7,
-7
],
"end": [
7,
-7
]
},
"ShapeLine2": {
"type": "line",
"origin": [
7,
-7
],
"end": [
7,
7
]
},
"ShapeLine3": {
"type": "line",
"origin": [
7,
7
],
"end": [
-7,
7
]
},
"ShapeLine4": {
"type": "line",
"origin": [
-7,
7
],
"end": [
-7,
-7
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
-7,
12
],
"end": [
7,
12
]
},
"ShapeLine2": {
"type": "line",
"origin": [
7,
12
],
"end": [
7,
26
]
},
"ShapeLine3": {
"type": "line",
"origin": [
7,
26
],
"end": [
-7,
26
]
},
"ShapeLine4": {
"type": "line",
"origin": [
-7,
26
],
"end": [
-7,
12
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
12,
-7
],
"end": [
26,
-7
]
},
"ShapeLine2": {
"type": "line",
"origin": [
26,
-7
],
"end": [
26,
7
]
},
"ShapeLine3": {
"type": "line",
"origin": [
26,
7
],
"end": [
12,
7
]
},
"ShapeLine4": {
"type": "line",
"origin": [
12,
7
],
"end": [
12,
-7
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
},
"b": {
"paths": {
"ShapeLine1": {
"type": "line",
"origin": [
12,
12
],
"end": [
26,
12
]
},
"ShapeLine2": {
"type": "line",
"origin": [
26,
12
],
"end": [
26,
26
]
},
"ShapeLine3": {
"type": "line",
"origin": [
26,
26
],
"end": [
12,
26
]
},
"ShapeLine4": {
"type": "line",
"origin": [
12,
26
],
"end": [
12,
12
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
},
"origin": [
0,
0
]
}
}

View file

@ -0,0 +1,44 @@
points:
zones:
matrix:
columns:
left.key.bind: [,10,,]
right.key.bind: [,,,10]
rows:
bottom.key.bind: [10,,,]
top.key.bind: [,,10,]
key:
bind: [0, 0, 0, 0]
rotate: -20
mirror:
ref: matrix_right_top
distance: 30
outlines:
glue:
default:
top:
left:
ref: matrix_right_top
shift: [,sy / 2]
right:
ref: mirror_matrix_right_top
shift: [,sy / 2]
bottom:
left:
ref: matrix_right_bottom
shift: [,sy / -2]
right:
ref: mirror_matrix_right_bottom
shift: [,sy / -2]
exports:
outline:
main:
type: keys
side: both
size: 20
min:
type: keys
side: both
bound: false
size: 14
operation: subtract

View file

@ -0,0 +1,9 @@
points:
zones:
matrix:
columns:
left:
right:
rows:
bottom:
top:

View file

@ -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": 19,
"y": 0,
"r": 0,
"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": 0,
"spread": 19,
"rotate": 0,
"origin": [
0,
0
],
"rows": {},
"key": {},
"name": "right"
},
"row": "bottom"
}
},
"matrix_right_top": {
"x": 19,
"y": 19,
"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": 0,
"spread": 19,
"rotate": 0,
"origin": [
0,
0
],
"rows": {},
"key": {},
"name": "right"
},
"row": "top"
}
}
}

View file

@ -0,0 +1,13 @@
points:
zones:
matrix:
columns:
left:
right:
stagger: 5
spread: 25
rotate: 5
origin: [-9, -9]
rows:
bottom:
top: