mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-24 22:09:42 +00:00
Allow passing ParseOptions to inline tests (#16357)
## Summary
This PR adds support for a pragma-style header for inline parser tests
containing JSON-serialized `ParseOptions`. For example,
```python
# parse_options: { "target-version": "3.9" }
match 2:
case 1:
pass
```
The line must start with `# parse_options: ` and then the rest of the
(trimmed) line is deserialized into `ParseOptions` used for parsing the
the test.
## Test Plan
Existing inline tests, plus two new inline tests for
`match-before-py310`.
---------
Co-authored-by: Alex Waygood <alex.waygood@gmail.com>
This commit is contained in:
parent
568cf88c6c
commit
764aa0e6a1
8 changed files with 238 additions and 7 deletions
|
|
@ -2265,6 +2265,18 @@ impl<'src> Parser<'src> {
|
|||
|
||||
let cases = self.parse_match_body();
|
||||
|
||||
// test_err match_before_py310
|
||||
// # parse_options: { "target-version": "3.9" }
|
||||
// match 2:
|
||||
// case 1:
|
||||
// pass
|
||||
|
||||
// test_ok match_after_py310
|
||||
// # parse_options: { "target-version": "3.10" }
|
||||
// match 2:
|
||||
// case 1:
|
||||
// pass
|
||||
|
||||
if self.options.target_version < PythonVersion::PY310 {
|
||||
self.unsupported_syntax_errors.push(UnsupportedSyntaxError {
|
||||
kind: UnsupportedSyntaxErrorKind::MatchBeforePy310,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue