Add failing tests for outstanding bugs

This commit is contained in:
Rebecca Turner
2018-06-18 10:36:25 -07:00
parent d65db7faf0
commit ef23ebc9f7
5 changed files with 57 additions and 44 deletions

View File

@@ -1,30 +0,0 @@
# Known Bugs:
* Current string literals are supported as key names. This is not valid per TOML 0.4:
> Quoted keys follow the exact same rules as basic strings and allow you to use a much broader set of key names.
* Accessing a higher level table after accessing a deeper attribute is valid. The following should not crash:
```toml
[a.b]
c = 1
[a]
d = 2
```
* Invalid unicode should crash. Currently we catch `String.fromCodePoint` errors and rethrow them, but other
sequences are invalid like \uD800 which becomes the Unicode Replacement Char, but probably should crash instead.
* Empty bare keys are errors, eg [.abc] or [abc.] or [abc..def] or [] should
crash. Versus ["".abc] or [abc.""] or [abc."".def], or [""] which are all valid. That is, `value` should not
return an empty string if it didn't match anything. Possibly should stop initializing this.state.buf to ''.
* Multiline \ trimming nees to support CRs
* Multline post opener trimming needs to support CRs
* Strings MAY NOT contain: the control characters (U+0000 to U+001F
* toml-j0.4 and toml both think that keys in inline tables may not be quoted. The spec doesn't say much:
> Key/value pairs take the same form as key/value pairs in standard tables.
But keys in standard tables can be double quoted, and the ABNF definitely
thinks they can be quoted. I think the others are _wrong_ here.

View File

@@ -134,12 +134,37 @@ const prettyError = require('./parse-pretty-error.js')
const newErr = prettyError(err, sourceString)
```
## What's Missing
## What's Different
For the most part, this module is stricter than the `toml` module and about
as strict as `toml-j0.4`. Adherence to the spec is needed if your TOML is
going to be compatible between implementations. The `toml` module also has
some extensions that are not yet standardized into a TOML release, but
likely will be in the future.
Additionally:
* The `toml-j0.4` and `toml` modules both think that keys in inline tables
may not be quoted. I believe they are in error and I allow quotes. The
spec says this:
> Key/value pairs take the same form as key/value pairs in standard tables.
Standard tables allow quoted keys and further, the ABNF from the standard
allows them to be quoted.
However, be aware that if you use quoted keys in inline tables you won't
be able to parse your file with the `toml-j0.4` or `toml` modules.
## Improvements to make
* In stringify:
* Any way to produce comments. As a JSON stand-in I'm not too worried about this.
* Stringification could use some work on its error reporting. It reports
_what's_ wrong, but not where in your data structure it was.
* Further optimize the parser:
* There are some debugging assertions left in the main parser, these should be moved to a subclass.
* Make the whole debugging parser thing work as a mixin instead of as a superclass.
## Benchmarks

View File

@@ -1,3 +1,8 @@
# Optimize Parser
* There are some debugging assertions left in the main parser, these should be moved to a subclass.
* Make the whole debugging parser thing work as a mixin instead of as a superclass.
# To support TOML 1.0 (when it comes)
While there has been no updated spec since 0.4, there have been changes to

View File

@@ -90,7 +90,18 @@ and here"
'mixed int str int': 'a = [ 1, "foo", 2 ]',
'mixed str float': 'a = [ "foo", 2e1 ]',
'mixed date bool': 'a = [ 2018-01-01T00:00:00Z, false ]',
'mixed obj arr': 'a = [ [23], {a=42} ]'
'mixed obj arr': 'a = [ [23], {a=42} ]',
'multiline str as keyname': '"""a""" = 1',
'string literal as keyname': "'a' = 1",
'invalid unicode': 'a = "\\uD800"',
'empty pre-dot': '[.abc]',
'empty post-dot': '[abc.]',
'empty mid-dot': '[abc..def]',
'empty obj name': '[]',
'no control chars': 'a = "\u001f"',
'no control chars2': 'a = "\u0000"',
'no multi control chars': 'a = """\u0000"""',
'no control in keys': '"a\u0000" = 1',
}
test('should be errors', t => {

View File

@@ -19,23 +19,25 @@ const tests = {
exponentUnderscore: {toml: `a = 1e1_0`, data: {a: 10000000000}},
splitlistwithcomment: {toml: `a = [ 123 #test\n,456]`, data: {a: [123, 456]}},
decimalListNoSpace: {toml: `a = [1.0,3.2]`, data: {a: [1, 3.2]}},
expListNoSpace: {toml: `a = [1e1,2e1]`, data: {a: [10, 20]}}
expListNoSpace: {toml: `a = [1e1,2e1]`, data: {a: [10, 20]}},
emptyQuotedPre: {toml: `["".abc]`, data: {"": {abc: {}}}},
emptyQuotedPost: {toml: `[abc.""]`, data: {"abc": {"": {}}}},
emptyQuotedMid: {toml: `[abc."".def]`, data: {"abc": {"": {def: {}}}}},
emptyKey: {toml: `[""]`, data: {"": {}}},
multiTrimCR: {toml: `a = """\r\nabc"""`, data: {a: 'abc'}},
multiLiteralTrimCR: {toml: `a = '''\r\nabc'''`, data: {a: 'abc'}},
multiSlashTrimCR: {toml: `a = """\r\nzed\\\r\n abc"""`, data: {a: 'zedabc'}},
deepThenShallow: {toml: `[a.b]\nc=1\n[a]\nd=2`, data: {a: {b: {c: 1}, d: 2}}},
}
test('spec', t => {
Object.keys(tests).forEach(name => {
try {
t.isDeeply(TOML.parse(tests[name].toml), tests[name].data, name)
} catch (ex) {
t.comment(ex.message)
t.fail(name)
}
try {
t.doesNotThrow(() => {
t.isDeeply(TOML.parse(tests[name].toml), tests[name].data, name + ' parsed correctly')
}, name + 'parse did not throw')
t.doesNotThrow(() => {
t.isDeeply(TOML.parse(TOML.stringify(tests[name].data)), tests[name].data, name + ' roundtrip')
} catch (ex) {
t.comment(ex.message)
t.fail(name + ' roundtrip')
}
}, name + ' roundtrip did not throw')
})
t.end()
})