forked from nodeca/js-yaml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse numbers according to YAML 1.2 instead of YAML 1.1
- Loading branch information
Showing
9 changed files
with
73 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
'use strict'; | ||
|
||
|
||
var assert = require('assert'); | ||
var yaml = require('../../'); | ||
|
||
|
||
describe('Should load numbers in YAML 1.2 format', function () { | ||
it('should not parse base60', function () { | ||
// previously parsed as int | ||
assert.strictEqual(yaml.load('1:23'), '1:23'); | ||
// previously parsed as float | ||
assert.strictEqual(yaml.load('1:23.45'), '1:23.45'); | ||
}); | ||
|
||
it('should allow leading zero in int and float', function () { | ||
assert.strictEqual(yaml.load('01234'), 1234); | ||
assert.strictEqual(yaml.load('00999'), 999); | ||
assert.strictEqual(yaml.load('-00999'), -999); | ||
assert.strictEqual(yaml.load('001234.56'), 1234.56); | ||
assert.strictEqual(yaml.load('001234e4'), 12340000); | ||
assert.strictEqual(yaml.load('-001234.56'), -1234.56); | ||
assert.strictEqual(yaml.load('-001234e4'), -12340000); | ||
}); | ||
|
||
it('should parse 0o prefix as octal', function () { | ||
assert.strictEqual(yaml.load('0o1234'), 668); | ||
// not valid octal | ||
assert.strictEqual(yaml.load('0o1289'), '0o1289'); | ||
}); | ||
}); | ||
|
||
|
||
describe('Should dump numbers in YAML 1.2 format', function () { | ||
it('should dump in different styles', function () { | ||
assert.strictEqual(yaml.dump(123, { styles: { '!!int': 'binary' } }), '0b1111011\n'); | ||
assert.strictEqual(yaml.dump(123, { styles: { '!!int': 'octal' } }), '0o173\n'); | ||
assert.strictEqual(yaml.dump(123, { styles: { '!!int': 'hex' } }), '0x7B\n'); | ||
}); | ||
|
||
it('should quote all potential numbers', function () { | ||
var tests = '1:23 1:23.45 01234 0999 -01234 01234e4 01234.56 -01234.56 0x123 0o123'; | ||
|
||
tests.split(' ').forEach(function (sample) { | ||
assert.strictEqual(yaml.dump(sample, { noCompatMode: false }), "'" + sample + "'\n"); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
canonical: 6.8523015e+5 | ||
exponential: 685.230_15e+03 | ||
fixed: 685_230.15 | ||
sexagesimal: 190:20:30.15 | ||
negative infinity: -.inf | ||
not a number: .NaN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
canonical: 685230 | ||
decimal: +685_230 | ||
octal: 02472256 | ||
octal: 0o2472256 | ||
hexadecimal: 0x_0A_74_AE | ||
binary: 0b1010_0111_0100_1010_1110 | ||
sexagesimal: 190:20:30 |