Skip to content

Commit 8cbf2b6

Browse files
committed
Change tokens to optional #110
1 parent 6892d2d commit 8cbf2b6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/colorize.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct Line {
2121
#[serde(with = "colors_serde")]
2222
pub colors: Vec<String>,
2323

24+
#[serde(default)]
2425
pub tokens: Vec<Token>,
2526
}
2627

@@ -206,6 +207,12 @@ mod tests {
206207
tokens = []
207208
"#;
208209

210+
pub static TEST_CONFIG3: &'static str = r#"
211+
[[lines]]
212+
pat = "A(.*) (.*) (.*) .*"
213+
colors = ["xxx", "Blue", "Cyan", "Default"]
214+
"#;
215+
209216
#[test]
210217
fn test_colorize() {
211218
let config: Config = toml::from_str(TEST_CONFIG).unwrap();
@@ -235,8 +242,14 @@ mod tests {
235242
let config: Config = toml::from_str(TEST_CONFIG2).unwrap();
236243
let ret = colorize(String::from("A123 456 789 xyz"), &config);
237244
assert_eq!(
238-
&format!("{:?}", ret)[0..50],
239-
"Err(Error(Msg(\"failed to parse color name \'xxx\'\"),"
245+
&format!("{:?}", ret)[0..37],
246+
"Err(failed to parse color name \'xxx\')"
240247
);
241248
}
249+
250+
#[test]
251+
fn test_omit_token() {
252+
let config = toml::from_str::<Config>(TEST_CONFIG3);
253+
assert!(config.is_ok());
254+
}
242255
}

0 commit comments

Comments
 (0)