mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
Update lexer tests to use snapshots (#6658)
## Summary This PR updates the lexer tests to use the snapshot testing framework. It also makes the following changes: * Remove the use of macros in the lexer tests * Use `test_case` for EOL tests ## Test Plan ``` cargo test --package ruff_python_parser --lib --all-features -- lexer::tests --no-capture ```
This commit is contained in:
parent
e53bf25616
commit
fb7caf43c8
14 changed files with 666 additions and 667 deletions
|
@ -31,6 +31,7 @@ static_assertions = "1.1.0"
|
|||
|
||||
[dev-dependencies]
|
||||
insta = { workspace = true }
|
||||
test-case = { workspace = true }
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = { workspace = true }
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
Name {
|
||||
name: "a_variable",
|
||||
},
|
||||
Equal,
|
||||
Int {
|
||||
value: 99,
|
||||
},
|
||||
Plus,
|
||||
Int {
|
||||
value: 2,
|
||||
},
|
||||
Minus,
|
||||
Int {
|
||||
value: 0,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,51 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Magic2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Shell,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: ShCap,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Paren,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Quote,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "",
|
||||
kind: Quote2,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "timeit a = b",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "timeit a % 3",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib --inline",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "pwd && ls -a | sed 's/^/\\\\ /'",
|
||||
kind: Shell,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "cd /Users/foo/Library/Application\\ Support/",
|
||||
kind: ShCap,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo 1 2",
|
||||
kind: Paren,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo 1 2",
|
||||
kind: Quote,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo 1 2",
|
||||
kind: Quote2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "ls",
|
||||
kind: Shell,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(source)
|
||||
---
|
||||
[
|
||||
Name {
|
||||
name: "pwd",
|
||||
},
|
||||
Equal,
|
||||
IpyEscapeCommand {
|
||||
value: "pwd",
|
||||
kind: Shell,
|
||||
},
|
||||
Newline,
|
||||
Name {
|
||||
name: "foo",
|
||||
},
|
||||
Equal,
|
||||
IpyEscapeCommand {
|
||||
value: "timeit a = b",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
Name {
|
||||
name: "bar",
|
||||
},
|
||||
Equal,
|
||||
IpyEscapeCommand {
|
||||
value: "timeit a % 3",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
Name {
|
||||
name: "baz",
|
||||
},
|
||||
Equal,
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib inline",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(source)
|
||||
---
|
||||
[
|
||||
If,
|
||||
True,
|
||||
Colon,
|
||||
Newline,
|
||||
Indent,
|
||||
IpyEscapeCommand {
|
||||
value: "matplotlib --inline",
|
||||
kind: Magic,
|
||||
},
|
||||
Newline,
|
||||
Dedent,
|
||||
]
|
|
@ -0,0 +1,86 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_jupyter_source(source)
|
||||
---
|
||||
[
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: " foo ?",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo???",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "?foo???",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: " ?",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "??",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "%foo",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "%foo",
|
||||
kind: Help2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "foo???",
|
||||
kind: Magic2,
|
||||
},
|
||||
Newline,
|
||||
IpyEscapeCommand {
|
||||
value: "pwd",
|
||||
kind: Help,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
Comment(
|
||||
"#Hello",
|
||||
),
|
||||
NonLogicalNewline,
|
||||
Comment(
|
||||
"#World",
|
||||
),
|
||||
NonLogicalNewline,
|
||||
]
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
Lpar,
|
||||
NonLogicalNewline,
|
||||
String {
|
||||
value: "a",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
NonLogicalNewline,
|
||||
String {
|
||||
value: "b",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
NonLogicalNewline,
|
||||
NonLogicalNewline,
|
||||
String {
|
||||
value: "c",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "d",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
NonLogicalNewline,
|
||||
Rpar,
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,42 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
Int {
|
||||
value: 47,
|
||||
},
|
||||
Int {
|
||||
value: 10,
|
||||
},
|
||||
Int {
|
||||
value: 13,
|
||||
},
|
||||
Int {
|
||||
value: 0,
|
||||
},
|
||||
Int {
|
||||
value: 123,
|
||||
},
|
||||
Int {
|
||||
value: 1234567890,
|
||||
},
|
||||
Float {
|
||||
value: 0.2,
|
||||
},
|
||||
Float {
|
||||
value: 100.0,
|
||||
},
|
||||
Float {
|
||||
value: 2100.0,
|
||||
},
|
||||
Complex {
|
||||
real: 0.0,
|
||||
imag: 2.0,
|
||||
},
|
||||
Complex {
|
||||
real: 0.0,
|
||||
imag: 2.2,
|
||||
},
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
DoubleSlash,
|
||||
DoubleSlash,
|
||||
DoubleSlashEqual,
|
||||
Slash,
|
||||
Slash,
|
||||
Newline,
|
||||
]
|
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
source: crates/ruff_python_parser/src/lexer.rs
|
||||
expression: lex_source(source)
|
||||
---
|
||||
[
|
||||
String {
|
||||
value: "double",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "single",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "can\\'t",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "\\\\\\\"",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "\\t\\r\\n",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "\\g",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "raw\\'",
|
||||
kind: RawString,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "\\420",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
String {
|
||||
value: "\\200\\0a",
|
||||
kind: String,
|
||||
triple_quoted: false,
|
||||
},
|
||||
Newline,
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue