mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-19 18:10:30 +00:00
Use snapshots for remaining lexer tests (#7264)
## Summary This PR updates the remaining lexer test cases to use the snapshots. This is mainly a mechanical refactor. ## Motivation The main motivation is so that when we add the token range values to the test case output, it's easier to update the test cases. The reason they were not using the snapshots before was because of the usage of `test_case` macro. The macros is mainly used for different EOL test cases. If we just generate the snapshots directly, then the snapshot name would be suffixed with `-1`, `-2`, etc. as the test function is still the same. So, we'll create the snapshot ourselves with the platform name for the respective EOL test cases. ## Test Plan `cargo test`
This commit is contained in:
parent
ff0feb191c
commit
f5701fcc63
35 changed files with 845 additions and 272 deletions
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 123,
|
||||
},
|
||||
Comment(
|
||||
"# Foo",
|
||||
),
|
||||
Newline,
|
||||
Int {
|
||||
value: 456,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 123,
|
||||
},
|
||||
Comment(
|
||||
"# Foo",
|
||||
),
|
||||
Newline,
|
||||
Int {
|
||||
value: 456,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 123,
|
||||
},
|
||||
Comment(
|
||||
"# Foo",
|
||||
),
|
||||
Newline,
|
||||
Int {
|
||||
value: 456,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
If,
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Colon,
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
If,
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Colon,
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
If,
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Colon,
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
If,
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Colon,
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
If,
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Colon,
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
If,
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Colon,
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "\\N{EN SPACE}",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Def,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Lpar,
|
||||
Rpar,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
Return,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Newline,
|
||||
NonLogicalNewline,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(&source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib --inline",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(&source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib --inline",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(&source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib --inline",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(&source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib ",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(&source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib ",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(&source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib ",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 99232,
|
||||
},
|
||||
Comment(
|
||||
"#",
|
||||
),
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 99232,
|
||||
},
|
||||
Comment(
|
||||
"# foo",
|
||||
),
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 99232,
|
||||
},
|
||||
Comment(
|
||||
"# ",
|
||||
),
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 99232,
|
||||
},
|
||||
Comment(
|
||||
"# ",
|
||||
),
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Equal,
|
||||
Lsqb,
|
||||
NonLogicalNewline,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 1,
|
||||
},
|
||||
Comma,
|
||||
Int {
|
||||
value: 2,
|
||||
},
|
||||
NonLogicalNewline,
|
||||
Comma,
|
||||
Lpar,
|
||||
Int {
|
||||
value: 3,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 4,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Rpar,
|
||||
Comma,
|
||||
Lbrace,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 5,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 6,
|
||||
},
|
||||
Comma,
|
||||
Int {
|
||||
value: 7,
|
||||
},
|
||||
Rbrace,
|
||||
Rsqb,
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Equal,
|
||||
Lsqb,
|
||||
NonLogicalNewline,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 1,
|
||||
},
|
||||
Comma,
|
||||
Int {
|
||||
value: 2,
|
||||
},
|
||||
NonLogicalNewline,
|
||||
Comma,
|
||||
Lpar,
|
||||
Int {
|
||||
value: 3,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 4,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Rpar,
|
||||
Comma,
|
||||
Lbrace,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 5,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 6,
|
||||
},
|
||||
Comma,
|
||||
Int {
|
||||
value: 7,
|
||||
},
|
||||
Rbrace,
|
||||
Rsqb,
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
Name {
|
||||
name: "x",
|
||||
},
|
||||
Equal,
|
||||
Lsqb,
|
||||
NonLogicalNewline,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 1,
|
||||
},
|
||||
Comma,
|
||||
Int {
|
||||
value: 2,
|
||||
},
|
||||
NonLogicalNewline,
|
||||
Comma,
|
||||
Lpar,
|
||||
Int {
|
||||
value: 3,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 4,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Rpar,
|
||||
Comma,
|
||||
Lbrace,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 5,
|
||||
},
|
||||
Comma,
|
||||
NonLogicalNewline,
|
||||
Int {
|
||||
value: 6,
|
||||
},
|
||||
Comma,
|
||||
Int {
|
||||
value: 7,
|
||||
},
|
||||
Rbrace,
|
||||
Rsqb,
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "abc\\\rdef",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "abc\\\ndef",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "abc\\\r\ndef",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "\r test string\r ",
|
||||
kind: String,
|
||||
triple_quoted: true,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "\n test string\n ",
|
||||
kind: String,
|
||||
triple_quoted: true,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(&source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "\r\n test string\r\n ",
|
||||
kind: String,
|
||||
triple_quoted: true,
|
||||
},
|
||||
Newline,
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue