Skip to content

Commit 85ccb98

Browse files
committed
Adding test to verify code block idempotency in Configurations.md
1 parent 91a3324 commit 85ccb98

File tree

5 files changed

+288
-20
lines changed

5 files changed

+288
-20
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ getopts = "0.2"
4545
derive-new = "0.5"
4646
cargo_metadata = "0.4"
4747

48+
[dev-dependencies]
49+
lazy_static = "1.0.0"
50+
4851
[target.'cfg(unix)'.dependencies]
4952
libc = "0.2.11"
5053

Configurations.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,12 +511,12 @@ Maximum length of comments. No effect unless`wrap_comments = true`.
511511

512512
**Note:** A value of `0` results in [`wrap_comments`](#wrap_comments) being applied regardless of a line's width.
513513

514-
#### Comments shorter than `comment_width`:
514+
#### `80` (default; comments shorter than `comment_width`):
515515
```rust
516516
// Lorem ipsum dolor sit amet, consectetur adipiscing elit.
517517
```
518518

519-
#### Comments longer than `comment_width`:
519+
#### `60` (comments longer than `comment_width`):
520520
```rust
521521
// Lorem ipsum dolor sit amet,
522522
// consectetur adipiscing elit.

src/rustfmt_diff.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,28 @@ pub fn make_diff(expected: &str, actual: &str, context_size: usize) -> Vec<Misma
9797
results
9898
}
9999

100+
// A representation of how to write output.
101+
pub enum PrintType {
102+
Fancy, // want to output color and the terminal supports it
103+
Basic, // do not want to output color or the terminal does not support color
104+
}
105+
106+
impl PrintType {
107+
pub fn get(color: Color) -> Self {
108+
match term::stdout() {
109+
Some(ref t) if use_colored_tty(color) && t.supports_color() => PrintType::Fancy,
110+
_ => PrintType::Basic,
111+
}
112+
}
113+
}
114+
100115
pub fn print_diff<F>(diff: Vec<Mismatch>, get_section_title: F, color: Color)
101116
where
102117
F: Fn(u32) -> String,
103118
{
104-
match term::stdout() {
105-
Some(ref t) if use_colored_tty(color) && t.supports_color() => {
106-
print_diff_fancy(diff, get_section_title, term::stdout().unwrap())
107-
}
108-
_ => print_diff_basic(diff, get_section_title),
119+
match PrintType::get(color) {
120+
PrintType::Fancy => print_diff_fancy(diff, get_section_title, term::stdout().unwrap()),
121+
PrintType::Basic => print_diff_basic(diff, get_section_title),
109122
}
110123
}
111124

0 commit comments

Comments
 (0)