Parametric declarations
This commit is contained in:
parent
29503614cc
commit
e515f51c0e
10 changed files with 128 additions and 36 deletions
|
@ -2,12 +2,21 @@ 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 u = require('../src/utils')
|
||||
const ergogen = require('../src/ergogen')
|
||||
|
||||
let what = process.env.npm_config_what
|
||||
what = what ? what.split(',') : false
|
||||
for (const unit of glob.sync(path.join(__dirname, 'unit', '*.js'))) {
|
||||
const base = path.basename(unit, '.js')
|
||||
if (what && !what.includes(base)) continue
|
||||
require(`./unit/${base}.js`)
|
||||
}
|
||||
|
||||
const cap = s => s.charAt(0).toUpperCase() + s.slice(1)
|
||||
|
||||
for (const part of ['points', 'outlines', 'cases', 'pcbs']) {
|
||||
if (what && !what.includes(part)) continue
|
||||
describe(cap(part), function() {
|
||||
const dir = path.join(__dirname, part)
|
||||
for (const input_path of glob.sync(path.join(dir, '*.yaml'))) {
|
|
@ -11,12 +11,12 @@ describe('Prepare', function() {
|
|||
|
||||
it('extend', function() {
|
||||
p.extend('something', undefined).should.equal('something')
|
||||
should.equal(p.extend('something', '!!unset'), undefined)
|
||||
should.equal(p.extend('something', '$unset'), undefined)
|
||||
p.extend(undefined, 'something').should.equal('something')
|
||||
p.extend(28, 'something').should.equal('something')
|
||||
p.extend('something', 28).should.equal(28)
|
||||
p.extend(27, 28).should.equal(28)
|
||||
p.extend({a: 1, c: 1, d: 1}, {b: 2, c: 2, d: '!!unset'}).should.deep.equal({a: 1, b: 2, c: 2})
|
||||
p.extend({a: 1, c: 1, d: 1}, {b: 2, c: 2, d: '$unset'}).should.deep.equal({a: 1, b: 2, c: 2})
|
||||
p.extend([3, 2, 1], [null, 4, 5]).should.deep.equal([3, 4, 5])
|
||||
})
|
||||
|
||||
|
@ -27,11 +27,11 @@ describe('Prepare', function() {
|
|||
y: 2
|
||||
},
|
||||
b: {
|
||||
extends: 'a',
|
||||
$extends: 'a',
|
||||
z: 3
|
||||
},
|
||||
c: {
|
||||
extends: 'b',
|
||||
$extends: ['b'],
|
||||
w: 4
|
||||
}
|
||||
}).c.should.deep.equal({
|
||||
|
@ -41,4 +41,48 @@ describe('Prepare', function() {
|
|||
w: 4
|
||||
})
|
||||
})
|
||||
|
||||
it('parameterize', function() {
|
||||
p.parameterize(1).should.equal(1)
|
||||
|
||||
p.parameterize({
|
||||
unused: {
|
||||
$params: ['PAR']
|
||||
},
|
||||
skip: {
|
||||
$skip: true
|
||||
}
|
||||
}).should.deep.equal({})
|
||||
|
||||
p.parameterize({
|
||||
decl: {
|
||||
a: 'PAR',
|
||||
$params: ['PAR'],
|
||||
$args: [1]
|
||||
}
|
||||
}).decl.should.deep.equal({
|
||||
a: 1
|
||||
})
|
||||
|
||||
p.parameterize.bind(this, {
|
||||
decl: {
|
||||
$args: [1]
|
||||
}
|
||||
}).should.throw('missing')
|
||||
|
||||
p.parameterize.bind(this, {
|
||||
decl: {
|
||||
$params: ['PAR1', 'PAR2'],
|
||||
$args: [1]
|
||||
}
|
||||
}).should.throw('match')
|
||||
|
||||
p.parameterize.bind(this, {
|
||||
decl: {
|
||||
a: 'PAR',
|
||||
$params: ['PAR'],
|
||||
$args: [undefined]
|
||||
}
|
||||
}).should.throw('valid')
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue