Skip to content

Commit

Permalink
Add tests for getVersionAdded in consistency test
Browse files Browse the repository at this point in the history
  • Loading branch information
ddbeck committed Oct 1, 2021
1 parent 9056e94 commit 5525c22
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"scripts": {
"confluence": "node ./node_modules/mdn-confluence/main/generate.es6.js --output-dir=. --bcd-module=./index.js",
"mocha": "mocha \"*/**.test.js\"",
"mocha": "mocha \"**/*.test.js\"",
"lint": "node test/lint",
"fix": "node scripts/fix",
"mirror": "node scripts/mirror",
Expand Down
2 changes: 1 addition & 1 deletion test/linter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const testRealValues = require('./test-real-values.js');
const testSchema = require('./test-schema.js');
const testStyle = require('./test-style.js');
const testVersions = require('./test-versions.js');
const testConsistency = require('./test-consistency.js');
const { testConsistency } = require('./test-consistency.js');
const testDescriptions = require('./test-descriptions.js');

module.exports = {
Expand Down
2 changes: 1 addition & 1 deletion test/linter/test-consistency.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,4 @@ function testConsistency(filename) {
return false;
}

module.exports = testConsistency;
module.exports = { ConsistencyChecker, testConsistency };
52 changes: 52 additions & 0 deletions test/linter/test-consistency.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const assert = require('assert').strict;

const { ConsistencyChecker } = require('./test-consistency');

const check = new ConsistencyChecker();

describe('ConsistencyChecker.getVersionAdded()', function () {
it('returns null for non-real values', () => {
assert.equal(check.getVersionAdded({ version_added: null }), null);
});

it('returns null for "preview" values', () => {
assert.equal(check.getVersionAdded({ version_added: 'preview' }), null);
});

it('returns the value for real and ranged values', () => {
assert.equal(check.getVersionAdded({ version_added: '12' }), '12');
assert.equal(check.getVersionAdded({ version_added: '≤11' }), '≤11');
});

it('returns the earliest real value for an array support statement', () => {
assert.equal(
check.getVersionAdded([
{ version_added: '≤11' },
{ version_added: '101' },
]),
'≤11',
);
assert.equal(
check.getVersionAdded([
{ version_added: 'preview' },
{ version_added: '≤11', flags: [] },
]),
null,
);
assert.equal(
check.getVersionAdded([
{ version_added: true },
{ version_added: '≤11', flags: [] },
]),
null,
);

assert.equal(
check.getVersionAdded([
{ version_added: '87' },
{ version_added: true, flags: [] },
]),
null,
);
});
});

0 comments on commit 5525c22

Please sign in to comment.