mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-24 20:34:31 +00:00
Add range to lexer test snapshots (#7265)
## Summary This PR updates the lexer test snapshots to include the range value as well. This is mainly a mechanical refactor. ### Motivation The main motivation is so that we can verify that the ranges are valid and do not overlap. ## Test Plan `cargo test`
This commit is contained in:
parent
24b848a4ea
commit
a41bb2733f
44 changed files with 2197 additions and 871 deletions
|
@ -1273,17 +1273,20 @@ mod tests {
|
|||
const MAC_EOL: &str = "\r";
|
||||
const UNIX_EOL: &str = "\n";
|
||||
|
||||
fn lex_source(source: &str) -> Vec<Tok> {
|
||||
let lexer = lex(source, Mode::Module);
|
||||
lexer.map(|result| result.unwrap().0).collect()
|
||||
fn lex_source_with_mode(source: &str, mode: Mode) -> Vec<Spanned> {
|
||||
let lexer = lex(source, mode);
|
||||
lexer.map(std::result::Result::unwrap).collect()
|
||||
}
|
||||
|
||||
fn lex_jupyter_source(source: &str) -> Vec<Tok> {
|
||||
let lexer = lex(source, Mode::Ipython);
|
||||
lexer.map(|x| x.unwrap().0).collect()
|
||||
fn lex_source(source: &str) -> Vec<Spanned> {
|
||||
lex_source_with_mode(source, Mode::Module)
|
||||
}
|
||||
|
||||
fn ipython_escape_command_line_continuation_eol(eol: &str) -> Vec<Tok> {
|
||||
fn lex_jupyter_source(source: &str) -> Vec<Spanned> {
|
||||
lex_source_with_mode(source, Mode::Ipython)
|
||||
}
|
||||
|
||||
fn ipython_escape_command_line_continuation_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("%matplotlib \\{eol} --inline");
|
||||
lex_jupyter_source(&source)
|
||||
}
|
||||
|
@ -1303,7 +1306,7 @@ mod tests {
|
|||
assert_debug_snapshot!(ipython_escape_command_line_continuation_eol(WINDOWS_EOL));
|
||||
}
|
||||
|
||||
fn ipython_escape_command_line_continuation_with_eol_and_eof(eol: &str) -> Vec<Tok> {
|
||||
fn ipython_escape_command_line_continuation_with_eol_and_eof(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("%matplotlib \\{eol}");
|
||||
lex_jupyter_source(&source)
|
||||
}
|
||||
|
@ -1403,8 +1406,8 @@ baz = %matplotlib \
|
|||
assert_debug_snapshot!(lex_jupyter_source(source));
|
||||
}
|
||||
|
||||
fn assert_no_ipython_escape_command(tokens: &[Tok]) {
|
||||
for tok in tokens {
|
||||
fn assert_no_ipython_escape_command(tokens: &[Spanned]) {
|
||||
for (tok, _) in tokens {
|
||||
if let Tok::IpyEscapeCommand { .. } = tok {
|
||||
panic!("Unexpected escape command token: {tok:?}")
|
||||
}
|
||||
|
@ -1458,7 +1461,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(lex_source(&source));
|
||||
}
|
||||
|
||||
fn comment_until_eol(eol: &str) -> Vec<Tok> {
|
||||
fn comment_until_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("123 # Foo{eol}456");
|
||||
lex_source(&source)
|
||||
}
|
||||
|
@ -1484,7 +1487,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(lex_source(source));
|
||||
}
|
||||
|
||||
fn indentation_with_eol(eol: &str) -> Vec<Tok> {
|
||||
fn indentation_with_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("def foo():{eol} return 99{eol}{eol}");
|
||||
lex_source(&source)
|
||||
}
|
||||
|
@ -1504,7 +1507,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(indentation_with_eol(WINDOWS_EOL));
|
||||
}
|
||||
|
||||
fn double_dedent_with_eol(eol: &str) -> Vec<Tok> {
|
||||
fn double_dedent_with_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("def foo():{eol} if x:{eol}{eol} return 99{eol}{eol}");
|
||||
lex_source(&source)
|
||||
}
|
||||
|
@ -1524,7 +1527,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(double_dedent_with_eol(WINDOWS_EOL));
|
||||
}
|
||||
|
||||
fn double_dedent_with_tabs_eol(eol: &str) -> Vec<Tok> {
|
||||
fn double_dedent_with_tabs_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("def foo():{eol}\tif x:{eol}{eol}\t\t return 99{eol}{eol}");
|
||||
lex_source(&source)
|
||||
}
|
||||
|
@ -1544,7 +1547,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(double_dedent_with_tabs_eol(WINDOWS_EOL));
|
||||
}
|
||||
|
||||
fn newline_in_brackets_eol(eol: &str) -> Vec<Tok> {
|
||||
fn newline_in_brackets_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = r"x = [
|
||||
|
||||
1,2
|
||||
|
@ -1604,7 +1607,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(lex_source(source));
|
||||
}
|
||||
|
||||
fn string_continuation_with_eol(eol: &str) -> Vec<Tok> {
|
||||
fn string_continuation_with_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("\"abc\\{eol}def\"");
|
||||
lex_source(&source)
|
||||
}
|
||||
|
@ -1630,7 +1633,7 @@ def f(arg=%timeit a = b):
|
|||
assert_debug_snapshot!(lex_source(source));
|
||||
}
|
||||
|
||||
fn triple_quoted_eol(eol: &str) -> Vec<Tok> {
|
||||
fn triple_quoted_eol(eol: &str) -> Vec<Spanned> {
|
||||
let source = format!("\"\"\"{eol} test string{eol} \"\"\"");
|
||||
lex_source(&source)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue