Skip to content

Commit a4f7434

Browse files
committed
strip down tests and move them to ruff_db
1 parent 3031673 commit a4f7434

File tree

5 files changed

+93
-129
lines changed

5 files changed

+93
-129
lines changed

crates/ruff_db/src/diagnostic/render.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2587,7 +2587,7 @@ watermelon
25872587
}
25882588

25892589
/// Returns a builder for tersely constructing diagnostics.
2590-
fn builder(
2590+
pub(super) fn builder(
25912591
&mut self,
25922592
identifier: &'static str,
25932593
severity: Severity,
@@ -2654,7 +2654,7 @@ watermelon
26542654
///
26552655
/// See the docs on `TestEnvironment::span` for the meaning of
26562656
/// `path`, `line_offset_start` and `line_offset_end`.
2657-
fn primary(
2657+
pub(super) fn primary(
26582658
mut self,
26592659
path: &str,
26602660
line_offset_start: &str,
@@ -2694,7 +2694,7 @@ watermelon
26942694
}
26952695

26962696
/// Set the secondary code on the diagnostic.
2697-
fn secondary_code(mut self, secondary_code: &str) -> DiagnosticBuilder<'e> {
2697+
pub(super) fn secondary_code(mut self, secondary_code: &str) -> DiagnosticBuilder<'e> {
26982698
self.diag
26992699
.set_secondary_code(SecondaryCode::new(secondary_code.to_string()));
27002700
self

crates/ruff_db/src/diagnostic/render/full.rs

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[cfg(test)]
22
mod tests {
33
use crate::diagnostic::{
4-
DiagnosticFormat,
5-
render::tests::{create_diagnostics, create_syntax_error_diagnostics},
4+
DiagnosticFormat, Severity,
5+
render::tests::{TestEnvironment, create_diagnostics, create_syntax_error_diagnostics},
66
};
77

88
#[test]
@@ -63,4 +63,92 @@ mod tests {
6363
|
6464
");
6565
}
66+
67+
/// Check that the new `full` rendering code in `ruff_db` handles cases fixed by commit c9b99e4.
68+
///
69+
/// For example, without the fix, we get diagnostics like this:
70+
///
71+
/// ```
72+
/// 0 │+error[no-indented-block]: Expected an indented block
73+
/// 1 │+ --> E11.py:9:1
74+
/// 2 │+ |
75+
/// 3 │+ 7 | #: E112
76+
/// 4 │+ 8 | if False:
77+
/// 5 │+ | ^
78+
/// 6 │+ 9 | print()
79+
/// 7 │+10 | #: E113
80+
/// 8 │+11 | print()
81+
/// 9 │+ |
82+
/// ```
83+
///
84+
/// where the caret points to the end of the previous line instead of the start of the next.
85+
#[test]
86+
fn empty_span_after_line_terminator() {
87+
let mut env = TestEnvironment::new();
88+
env.add(
89+
"example.py",
90+
r#"
91+
if False:
92+
print()
93+
"#,
94+
);
95+
env.format(DiagnosticFormat::Full);
96+
97+
let diagnostic = env
98+
.builder(
99+
"no-indented-block",
100+
Severity::Error,
101+
"Expected an indented block",
102+
)
103+
.primary("example.py", "3:0", "3:0", "")
104+
.secondary_code("E112")
105+
.build();
106+
107+
insta::assert_snapshot!(env.render(&diagnostic), @r"
108+
error[no-indented-block]: Expected an indented block
109+
--> example.py:3:1
110+
|
111+
2 | if False:
112+
3 | print()
113+
| ^
114+
|
115+
");
116+
}
117+
118+
/// Check that the new `full` rendering code in `ruff_db` handles cases fixed by commit 2922490.
119+
///
120+
/// For example, without the fix, we get diagnostics like this:
121+
///
122+
/// ```
123+
/// 55 | nested_fstrings = f'␈{f'^Z{f'␛'}'}'
124+
/// | ^ PLE2512
125+
/// ```
126+
///
127+
/// where the caret points to the `f` in the f-string instead of the start of the invalid
128+
/// character (`^Z`).
129+
#[test]
130+
fn unprintable_characters() {
131+
let mut env = TestEnvironment::new();
132+
env.add("example.py", "nested_fstrings = f'{f'{f''}'}'");
133+
env.format(DiagnosticFormat::Full);
134+
135+
let diagnostic = env
136+
.builder(
137+
"invalid-character-sub",
138+
Severity::Error,
139+
r#"Invalid unescaped character SUB, use "\x1A" instead"#,
140+
)
141+
.primary("example.py", "1:24", "1:24", "")
142+
.secondary_code("PLE2512")
143+
.build();
144+
145+
insta::assert_snapshot!(env.render(&diagnostic), @r#"
146+
error[invalid-character-sub]: Invalid unescaped character SUB, use "\x1A" instead
147+
--> example.py:1:25
148+
|
149+
1 | nested_fstrings = f'␈{f'{f'␛'}'}'
150+
| ^
151+
|
152+
"#);
153+
}
66154
}

crates/ruff_linter/src/message/snapshots/ruff_linter__message__text__tests__empty_span_after_line_terminator.snap

Lines changed: 0 additions & 69 deletions
This file was deleted.

crates/ruff_linter/src/message/text.rs

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -447,59 +447,4 @@ mod tests {
447447

448448
assert_snapshot!(content);
449449
}
450-
451-
/// Check that the new `full` rendering code in `ruff_db` handles cases fixed by commit c9b99e4.
452-
///
453-
/// For example, without the fix, we get diagnostics like this:
454-
///
455-
/// ```
456-
/// 0 │+error[no-indented-block]: Expected an indented block
457-
/// 1 │+ --> E11.py:9:1
458-
/// 2 │+ |
459-
/// 3 │+ 7 | #: E112
460-
/// 4 │+ 8 | if False:
461-
/// 5 │+ | ^
462-
/// 6 │+ 9 | print()
463-
/// 7 │+10 | #: E113
464-
/// 8 │+11 | print()
465-
/// 9 │+ |
466-
/// ```
467-
///
468-
/// where the caret points to the end of the previous line instead of the start of the next.
469-
#[test]
470-
fn empty_span_after_line_terminator() -> anyhow::Result<()> {
471-
let path = Path::new("pycodestyle").join("E11.py");
472-
let settings = LinterSettings::for_rule(Rule::NoIndentedBlock);
473-
let diagnostics = test_path(path, &settings)?;
474-
let config = DisplayDiagnosticConfig::default().format(DiagnosticFormat::Full);
475-
let notebook_indexes = FxHashMap::default();
476-
let context = EmitterContext::new(&notebook_indexes);
477-
let value = DisplayDiagnostics::new(&context, &config, &diagnostics);
478-
insta::assert_snapshot!(value.to_string());
479-
Ok(())
480-
}
481-
482-
/// Check that the new `full` rendering code in `ruff_db` handles cases fixed by commit 2922490.
483-
///
484-
/// For example, without the fix, we get diagnostics like this:
485-
///
486-
/// ```
487-
/// 55 | nested_fstrings = f'␈{f'^Z{f'␛'}'}'
488-
/// | ^ PLE2512
489-
/// ```
490-
///
491-
/// where the caret points to the `f` in the f-string instead of the start of the invalid
492-
/// character (`^Z`).
493-
#[test]
494-
fn unprintable_characters() -> anyhow::Result<()> {
495-
let path = Path::new("pylint").join("invalid_characters.py");
496-
let settings = LinterSettings::for_rule(Rule::InvalidCharacterSub);
497-
let diagnostics = test_path(path, &settings)?;
498-
let config = DisplayDiagnosticConfig::default().format(DiagnosticFormat::Full);
499-
let notebook_indexes = FxHashMap::default();
500-
let context = EmitterContext::new(&notebook_indexes);
501-
let value = DisplayDiagnostics::new(&context, &config, &diagnostics);
502-
insta::assert_snapshot!(value.to_string());
503-
Ok(())
504-
}
505450
}

0 commit comments

Comments
 (0)