From d035c40209762624c194f0b8132ff8a2efa362c2 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 27 Sep 2023 14:16:53 +0200 Subject: [PATCH] adjusted exception message --- src/Neon/TokenStream.php | 2 +- tests/Neon/Decoder.errors.phpt | 40 +++++++++++++++++----------------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/Neon/TokenStream.php b/src/Neon/TokenStream.php index 061edd5..cff4783 100644 --- a/src/Neon/TokenStream.php +++ b/src/Neon/TokenStream.php @@ -90,6 +90,6 @@ public function error(?string $message = null, ?int $pos = null): void $message ??= 'Unexpected ' . ($token === null ? 'end' : "'" . str_replace("\n", '', substr($this->tokens[$pos]->value, 0, 40)) . "'"); - throw new Exception("$message on line $line, column $col."); + throw new Exception("$message on line $line at column $col"); } } diff --git a/tests/Neon/Decoder.errors.phpt b/tests/Neon/Decoder.errors.phpt index 8b9d5cb..84a7030 100644 --- a/tests/Neon/Decoder.errors.phpt +++ b/tests/Neon/Decoder.errors.phpt @@ -16,63 +16,63 @@ require __DIR__ . '/../bootstrap.php'; Assert::exception( fn() => Neon::decode("Hello\nWorld"), Nette\Neon\Exception::class, - "Unexpected 'World' on line 2, column 1.", + "Unexpected 'World' on line 2 at column 1", ); Assert::exception( fn() => Neon::decode('"\uD801"'), Nette\Neon\Exception::class, - 'Invalid UTF-8 sequence \\uD801 on line 1, column 1.', + 'Invalid UTF-8 sequence \\uD801 on line 1 at column 1', ); Assert::exception( fn() => Neon::decode("- Dave,\n- Rimmer,\n- Kryten,\n"), Nette\Neon\Exception::class, - "Unexpected ',' on line 1, column 7.", + "Unexpected ',' on line 1 at column 7", ); Assert::exception( fn() => Neon::decode('item [a, b]'), Nette\Neon\Exception::class, - "Unexpected ',' on line 1, column 8.", + "Unexpected ',' on line 1 at column 8", ); Assert::exception( fn() => Neon::decode('{,}'), Nette\Neon\Exception::class, - "Unexpected ',' on line 1, column 2.", + "Unexpected ',' on line 1 at column 2", ); Assert::exception( fn() => Neon::decode('{a, ,}'), Nette\Neon\Exception::class, - "Unexpected ',' on line 1, column 5.", + "Unexpected ',' on line 1 at column 5", ); Assert::exception( fn() => Neon::decode('"'), Nette\Neon\Exception::class, - "Unexpected '\"' on line 1, column 1.", + "Unexpected '\"' on line 1 at column 1", ); Assert::exception( fn() => Neon::decode("\ta:\n b:"), Nette\Neon\Exception::class, - 'Invalid combination of tabs and spaces on line 2, column 2.', + 'Invalid combination of tabs and spaces on line 2 at column 2', ); Assert::exception( fn() => Neon::decode("- x: 20\n - a: 10\n\tb: 10"), Nette\Neon\Exception::class, - 'Invalid combination of tabs and spaces on line 3, column 2.', + 'Invalid combination of tabs and spaces on line 3 at column 2', ); @@ -84,7 +84,7 @@ Assert::exception( XX), Nette\Neon\Exception::class, - 'Bad indentation on line 3, column 2.', + 'Bad indentation on line 3 at column 2', ); @@ -94,7 +94,7 @@ Assert::exception( b: XX), Nette\Neon\Exception::class, - 'Bad indentation on line 2, column 3.', + 'Bad indentation on line 2 at column 3', ); @@ -104,7 +104,7 @@ Assert::exception( a: 10 XX), Nette\Neon\Exception::class, - 'Bad indentation on line 2, column 2.', + 'Bad indentation on line 2 at column 2', ); @@ -114,7 +114,7 @@ Assert::exception( a: 10 XX), Nette\Neon\Exception::class, - 'Bad indentation on line 2, column 4.', + 'Bad indentation on line 2 at column 4', ); @@ -124,14 +124,14 @@ Assert::exception( a: 10 XX), Nette\Neon\Exception::class, - 'Bad indentation on line 2, column 2.', + 'Bad indentation on line 2 at column 2', ); Assert::exception( fn() => Neon::decode('- x: y:'), Nette\Neon\Exception::class, - "Unexpected ':' on line 1, column 7.", + "Unexpected ':' on line 1 at column 7", ); @@ -145,7 +145,7 @@ Assert::exception( XX, ), Nette\Neon\Exception::class, - "Unexpected '' on line 3, column 4.", + "Unexpected '' on line 3 at column 4", ); @@ -155,26 +155,26 @@ Assert::exception( a: 2 XX), Nette\Neon\Exception::class, - "Duplicated key 'a' on line 2, column 1.", + "Duplicated key 'a' on line 2 at column 1", ); Assert::exception( fn() => Neon::decode('{ []: foo }'), Nette\Neon\Exception::class, - 'Unacceptable key on line 1, column 3.', + 'Unacceptable key on line 1 at column 3', ); Assert::exception( fn() => Neon::decode('[]: foo'), Nette\Neon\Exception::class, - 'Unacceptable key on line 1, column 1.', + 'Unacceptable key on line 1 at column 1', ); Assert::exception( fn() => Neon::decode('{ - 1}'), Nette\Neon\Exception::class, - "Unexpected '-' on line 1, column 3.", + "Unexpected '-' on line 1 at column 3", );