toml: fix unbalanced quoted tests (#12006)
							parent
							
								
									24c1d552d7
								
							
						
					
					
						commit
						d39fec3479
					
				| 
						 | 
				
			
			@ -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)}...')
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue