Skip to content

Commit

Permalink
adjusted exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Apr 28, 2024
1 parent 5d4b9d8 commit d035c40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/Neon/TokenStream.php
Expand Up @@ -90,6 +90,6 @@ public function error(?string $message = null, ?int $pos = null): void
$message ??= 'Unexpected ' . ($token === null
? 'end'
: "'" . str_replace("\n", '<new line>', 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");
}
}
40 changes: 20 additions & 20 deletions tests/Neon/Decoder.errors.phpt
Expand Up @@ -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',
);


Expand All @@ -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',
);


Expand All @@ -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',
);


Expand All @@ -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',
);


Expand All @@ -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',
);


Expand All @@ -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",
);


Expand All @@ -145,7 +145,7 @@ Assert::exception(
XX,
),
Nette\Neon\Exception::class,
"Unexpected '<new line>' on line 3, column 4.",
"Unexpected '<new line>' on line 3 at column 4",
);


Expand All @@ -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",
);

0 comments on commit d035c40

Please sign in to comment.