Skip to content

Commit

Permalink
fix: leading zero non-oct numbers (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
mallachari authored Mar 18, 2020
1 parent 6301660 commit 4ef7cff
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/type/int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,15 @@ function resolveYamlInteger(data) {
ch = data[index];
if (ch === '_') { continue; }
if (!isOctCode(data.charCodeAt(index))) {
return false;
// if it's not oct number then treat is as possibly decimal and do not return yet
hasDigits = false;
break;
}
hasDigits = true;
}
return hasDigits;
if (hasDigits) {
return hasDigits;
}
}

// base 10 (except 0) or base 60
Expand Down
18 changes: 18 additions & 0 deletions test/dumper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,22 @@ b:
`)
});
});

suite('int schema', () => {
test('binary number', () => {
expect(safeDump({ value: '0b10101' })).to.equal(`value: '0b10101'\n`);
});
test('hex number', () => {
expect(safeDump({ value: '0x25DC' })).to.equal(`value: '0x25DC'\n`);
});
test('oct number', () => {
expect(safeDump({ value: '01234567' })).to.equal(`value: '01234567'\n`);
});
test('dec number', () => {
expect(safeDump({ value: '1234567890' })).to.equal(`value: '1234567890'\n`);
});
test('leading zero dec number', () => {
expect(safeDump({ value: '0123456789' })).to.equal(`value: '0123456789'\n`);
});
});
});

0 comments on commit 4ef7cff

Please sign in to comment.