toml: fix unbalanced quoted tests (#12006)

pull/12016/head
Larpon 2021-09-29 09:19:49 +02:00 committed by GitHub
parent 24c1d552d7
commit d39fec3479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -22,11 +22,14 @@ pub fn (c Checker) check(n &ast.Value) ? {
fn (c Checker) visit(value &ast.Value) ? {
match value {
ast.Bool {
c.check_boolean(value) ?
}
ast.Number {
c.check_number(value) ?
}
ast.Bool {
c.check_boolean(value) ?
ast.Quoted {
c.check_quoted(value) ?
}
else {
// TODO add more checks to make BurntSushi/toml-test invalid TOML pass
@ -168,3 +171,13 @@ fn (c Checker) check_boolean(b ast.Bool) ? {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' boolean values like "$lit" can only be `true` or `false` literals, not `$lit` in ...${c.excerpt(b.pos)}...')
}
fn (c Checker) check_quoted(b ast.Quoted) ? {
lit := b.text
quote := b.quote.ascii_str()
triple_quote := quote + quote + quote
if b.is_multiline && lit.ends_with(triple_quote) {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' string values like "$lit" is has unbalanced quote literals `b.quote` in ...${c.excerpt(b.pos)}...')
}
}

View File

@ -18,14 +18,10 @@ const (
'string/basic-byte-escapes.toml',
'string/multiline-escape-space.toml',
'string/bad-codepoint.toml',
'string/literal-multiline-quotes-1.toml',
'string/literal-multiline-quotes-2.toml',
'string/multiline-quotes-1.toml',
'string/basic-multiline-out-of-range-unicode-escape-2.toml',
'string/bad-slash-escape.toml',
'string/basic-out-of-range-unicode-escape-1.toml',
'string/basic-out-of-range-unicode-escape-2.toml',
'string/multiline-quotes-2.toml',
'string/bad-uni-esc.toml',
'string/bad-escape.toml',
'string/basic-multiline-unknown-escape.toml',