Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bc76cd1

Browse files
committedJul 19, 2019
fix 'long_and_detailed' test for cfg!(windows)
- customize expected pretty-print output for windows platforms - work-around for unexpected trailing commas on windows platforms (see <rust-lang/rust#62794>)
1 parent bcb89a2 commit bc76cd1

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed
 

‎Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ features = ["consoleapi", "errhandlingapi", "fileapi", "handleapi", "processenv"
2727

2828
[dev-dependencies]
2929
doc-comment = "0.3"
30+
regex = "1.1.9"
3031

3132
[dev-dependencies.serde_json]
3233
version = "1.0.39"

‎src/debug.rs

+28-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::fmt;
22

33
use style::Style;
44

5-
65
/// Styles have a special `Debug` implementation that only shows the fields that
76
/// are set. Fields that haven’t been touched aren’t included in the output.
87
///
@@ -103,20 +102,33 @@ mod test {
103102

104103
#[test]
105104
fn long_and_detailed() {
106-
let debug = r##"Style {
107-
foreground: Some(
108-
Blue,
109-
),
110-
background: None,
111-
blink: false,
112-
bold: true,
113-
dimmed: false,
114-
hidden: false,
115-
italic: false,
116-
reverse: false,
117-
strikethrough: false,
118-
underline: false,
119-
}"##;
120-
assert_eq!(debug, format!("{:#?}", Blue.bold()));
105+
extern crate regex;
106+
let expected_debug = "Style { fg(Blue), bold }";
107+
let expected_pretty_repat = r##"(?x)
108+
Style\s+\{\s+
109+
foreground:\s+Some\(\s+
110+
Blue,?\s+
111+
\),\s+
112+
background:\s+None,\s+
113+
blink:\s+false,\s+
114+
bold:\s+true,\s+
115+
dimmed:\s+false,\s+
116+
hidden:\s+false,\s+
117+
italic:\s+false,\s+
118+
reverse:\s+false,\s+
119+
strikethrough:\s+
120+
false,\s+
121+
underline:\s+false,?\s+
122+
\}"##;
123+
let re = regex::Regex::new(expected_pretty_repat).unwrap();
124+
125+
let style = Blue.bold();
126+
let style_fmt_debug = format!("{:?}", style);
127+
let style_fmt_pretty = format!("{:#?}", style);
128+
println!("style_fmt_debug:\n{}", style_fmt_debug);
129+
println!("style_fmt_pretty:\n{}", style_fmt_pretty);
130+
131+
assert_eq!(expected_debug, style_fmt_debug);
132+
assert!(re.is_match(&style_fmt_pretty));
121133
}
122134
}

0 commit comments

Comments
 (0)
Please sign in to comment.