Skip to content

Commit

Permalink
fix and tests for 4-digit vte version strings
Browse files Browse the repository at this point in the history
  • Loading branch information
substack committed Jul 16, 2019
1 parent 49a52c1 commit b041787
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ const supportsColor = require('supports-color');
const hasFlag = require('has-flag');

function parseVersion(versionString) {
if (/^\d{3,4}$/.test(versionString)) {
// Env var doesn't always use dots. example: 4601 => 46.1.0
const m = /(\d{1,2})(\d{2})/.exec(versionString);
return {
major: 0,
minor: parseInt(m[1], 10),
patch: parseInt(m[2], 10)
};
}
const versions = (versionString || '').split('.').map(n => parseInt(n, 10));
return {
major: versions[0],
Expand Down
16 changes: 16 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,22 @@ test('supported in VTE 1.0.0', t => {
}));
});

test('not supported in VTE 4601 (0.46.1)', t => {
t.false(isSupported({
env: {
VTE_VERSION: '4601'
}
}));
});

test('supported in VTE 5105 (0.51.5)', t => {
t.true(isSupported({
env: {
VTE_VERSION: '5105'
}
}));
});

test('no-color flag disables support', t => {
t.false(isSupported({
argv: ['--no-color'],
Expand Down

0 comments on commit b041787

Please sign in to comment.