diff --git a/src/type/int.ts b/src/type/int.ts index 104ebf0..38af290 100644 --- a/src/type/int.ts +++ b/src/type/int.ts @@ -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 diff --git a/test/dumper.test.ts b/test/dumper.test.ts index 36d4af7..212484d 100644 --- a/test/dumper.test.ts +++ b/test/dumper.test.ts @@ -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`); + }); + }); });