mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:23:11 +00:00
Add missing unit tests for # noqa:
-like cases (#16659)
This commit is contained in:
parent
8bd140c99d
commit
c236be4320
10 changed files with 135 additions and 0 deletions
|
@ -1250,6 +1250,30 @@ mod tests {
|
|||
assert_lexed_ranges_match_slices(directive, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noqa_no_code() {
|
||||
let source = "# noqa:";
|
||||
let directive = lex_inline_noqa(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(directive);
|
||||
assert_lexed_ranges_match_slices(directive, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noqa_no_code_invalid_suffix() {
|
||||
let source = "# noqa: foo";
|
||||
let directive = lex_inline_noqa(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(directive);
|
||||
assert_lexed_ranges_match_slices(directive, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noqa_no_code_trailing_content() {
|
||||
let source = "# noqa: # Foo";
|
||||
let directive = lex_inline_noqa(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(directive);
|
||||
assert_lexed_ranges_match_slices(directive, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn noqa_code() {
|
||||
let source = "# noqa: F401";
|
||||
|
@ -1482,6 +1506,30 @@ mod tests {
|
|||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flake8_noqa_no_code() {
|
||||
let source = "# flake8: noqa:";
|
||||
let exemption = lex_file_exemption(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(exemption);
|
||||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flake8_noqa_no_code_invalid_suffix() {
|
||||
let source = "# flake8: noqa: foo";
|
||||
let exemption = lex_file_exemption(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(exemption);
|
||||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flake8_noqa_no_code_trailing_content() {
|
||||
let source = "# flake8: noqa: # Foo";
|
||||
let exemption = lex_file_exemption(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(exemption);
|
||||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruff_exemption_all() {
|
||||
let source = "# ruff: noqa";
|
||||
|
@ -1490,6 +1538,30 @@ mod tests {
|
|||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruff_noqa_no_code() {
|
||||
let source = "# ruff: noqa:";
|
||||
let exemption = lex_file_exemption(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(exemption);
|
||||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruff_noqa_no_code_invalid_suffix() {
|
||||
let source = "# ruff: noqa: foo";
|
||||
let exemption = lex_file_exemption(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(exemption);
|
||||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruff_noqa_no_code_trailing_content() {
|
||||
let source = "# ruff: noqa: # Foo";
|
||||
let exemption = lex_file_exemption(TextRange::up_to(source.text_len()), source);
|
||||
assert_debug_snapshot!(exemption);
|
||||
assert_lexed_ranges_match_slices(exemption, source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flake8_exemption_all_no_space() {
|
||||
let source = "#flake8:noqa";
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: exemption
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: exemption
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: exemption
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: "Directive::try_extract(source, TextSize::default())"
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: "Directive::try_extract(source, TextSize::default())"
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: "Directive::try_extract(source, TextSize::default())"
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: exemption
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: exemption
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/noqa.rs
|
||||
expression: exemption
|
||||
---
|
||||
Err(
|
||||
MissingCodes,
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue