summaryrefslogtreecommitdiffstats
path: root/src/features
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-07-10 15:34:18 -0400
committerDan Davison <dandavison7@gmail.com>2020-07-10 15:41:38 -0400
commit36bf3df81495989f74ecfef252d94e53b834a552 (patch)
treeaacd90f1bb15b7cafacd4cc5eaec1acba97fc9c3 /src/features
parent8e6a149f1e5a089099698812f427c969c89effbb (diff)
Fix test: support line-number formats without a placeholder
Diffstat (limited to 'src/features')
-rw-r--r--src/features/line_numbers.rs35
1 files changed, 23 insertions, 12 deletions
diff --git a/src/features/line_numbers.rs b/src/features/line_numbers.rs
index bf70c467..0ed56bf4 100644
--- a/src/features/line_numbers.rs
+++ b/src/features/line_numbers.rs
@@ -151,7 +151,7 @@ pub type LineNumberFormatData<'a> = Vec<LineNumberPlaceholderData<'a>>;
#[derive(Debug, Default, PartialEq)]
pub struct LineNumberPlaceholderData<'a> {
pub prefix: &'a str,
- pub placeholder: &'a str,
+ pub placeholder: Option<&'a str>,
pub alignment_spec: Option<&'a str>,
pub width: Option<usize>,
pub suffix: &'a str,
@@ -188,7 +188,7 @@ fn parse_line_number_format<'a>(format_string: &'a str) -> LineNumberFormatData<
let _match = captures.get(0).unwrap();
format_data.push(LineNumberPlaceholderData {
prefix: &format_string[offset.._match.start()],
- placeholder: captures.get(1).map(|m| m.as_str()).unwrap(),
+ placeholder: captures.get(1).map(|m| m.as_str()),
alignment_spec: captures.get(3).map(|m| m.as_str()),
width: captures.get(4).map(|m| {
m.as_str()
@@ -199,6 +199,16 @@ fn parse_line_number_format<'a>(format_string: &'a str) -> LineNumberFormatData<
});
offset = _match.end();
}
+ if offset == 0 {
+ // No placeholders
+ format_data.push(LineNumberPlaceholderData {
+ prefix: &format_string[..0],
+ placeholder: None,
+ alignment_spec: None,
+ width: None,
+ suffix: &format_string[0..],
+ })
+ }
format_data
}
@@ -224,17 +234,18 @@ fn format_and_paint_line_number_field<'a>(
};
match placeholder.placeholder {
- "nm" => ansi_strings.push(minus_number_style.paint(format_line_number(
+ Some("nm") => ansi_strings.push(minus_number_style.paint(format_line_number(
minus_number,
alignment_spec,
width,
))),
- "np" => ansi_strings.push(plus_number_style.paint(format_line_number(
+ Some("np") => ansi_strings.push(plus_number_style.paint(format_line_number(
plus_number,
alignment_spec,
width,
))),
- _ => unreachable!(),
+ None => {}
+ Some(_) => unreachable!(),
}
suffix = placeholder.suffix;
}
@@ -270,7 +281,7 @@ pub mod tests {
parse_line_number_format("{nm}"),
vec![LineNumberPlaceholderData {
prefix: "",
- placeholder: "nm",
+ placeholder: Some("nm"),
alignment_spec: None,
width: None,
suffix: "",
@@ -284,7 +295,7 @@ pub mod tests {
parse_line_number_format("{np:4}"),
vec![LineNumberPlaceholderData {
prefix: "",
- placeholder: "np",
+ placeholder: Some("np"),
alignment_spec: None,
width: Some(4),
suffix: "",
@@ -298,7 +309,7 @@ pub mod tests {
parse_line_number_format("{np:>4}"),
vec![LineNumberPlaceholderData {
prefix: "",
- placeholder: "np",
+ placeholder: Some("np"),
alignment_spec: Some(">"),
width: Some(4),
suffix: "",
@@ -312,7 +323,7 @@ pub mod tests {
parse_line_number_format("{np:_>4}"),
vec![LineNumberPlaceholderData {
prefix: "",
- placeholder: "np",
+ placeholder: Some("np"),
alignment_spec: Some(">"),
width: Some(4),
suffix: "",
@@ -326,7 +337,7 @@ pub mod tests {
parse_line_number_format("__{np:_>4}@@"),
vec![LineNumberPlaceholderData {
prefix: "__",
- placeholder: "np",
+ placeholder: Some("np"),
alignment_spec: Some(">"),
width: Some(4),
suffix: "@@",
@@ -341,14 +352,14 @@ pub mod tests {
vec![
LineNumberPlaceholderData {
prefix: "__",
- placeholder: "nm",
+ placeholder: Some("nm"),
alignment_spec: Some("<"),
width: Some(3),
suffix: "@@---{np:_>4}**",
},
LineNumberPlaceholderData {
prefix: "@@---",
- placeholder: "np",
+ placeholder: Some("np"),
alignment_spec: Some(">"),
width: Some(4),
suffix: "**",