Skip to content

Commit 6cff3e0

Browse files
danjl1100djc
authored andcommitted
document current panic in Style::from_dotted_str via test cases
1 parent dd4334f commit 6cff3e0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/utils.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,3 +1195,31 @@ fn test_attributes_many() {
11951195
assert_eq!(&attrs.attrs().collect::<Vec<_>>(), test_attrs);
11961196
}
11971197
}
1198+
1199+
#[test]
1200+
// NOTE: Documenting the current panic message. Ideally this input should be silently ignored
1201+
#[should_panic = "end byte index 3 is not a char boundary; it is inside '€' (bytes 1..4 of string)"]
1202+
fn test_style_from_non_ascii_fg() {
1203+
// len() == 7, starts_with('#'), but slices [1..3] land mid-€ (3 bytes)
1204+
let fg = "#€€";
1205+
assert_eq!(fg.len(), 7);
1206+
1207+
let parsed_style = Style::from_dotted_str(fg);
1208+
1209+
// silently ignores non-ascii
1210+
assert_eq!(parsed_style, Style::default());
1211+
}
1212+
1213+
#[test]
1214+
// NOTE: Documenting the current panic message. Ideally this input should be silently ignored
1215+
#[should_panic = "end byte index 6 is not a char boundary; it is inside '€' (bytes 4..7 of string)"]
1216+
fn test_style_from_non_ascii_bg() {
1217+
// len() == 10, starts_with("on_#"), but slices [4..6] land mid-€
1218+
let bg = "on_#€€";
1219+
assert_eq!(bg.len(), 10);
1220+
1221+
let parsed_style = Style::from_dotted_str(bg);
1222+
1223+
// silently ignores non-ascii
1224+
assert_eq!(parsed_style, Style::default());
1225+
}

0 commit comments

Comments
 (0)