Skip to content

Commit

Permalink
Add non redundancy test on git icons
Browse files Browse the repository at this point in the history
  • Loading branch information
hpwxf committed Mar 23, 2021
1 parent dfc0754 commit 4556325
Showing 1 changed file with 54 additions and 7 deletions.
61 changes: 54 additions & 7 deletions src/flags/git_icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,21 @@ impl GitIcons {
.to_string()
}

// On each unicode icon, add its value in a comment like "\ue5fb" (cf https://www.nerdfonts.com/cheat-sheet)
// and then run the command below in vim:
// s#\\u[0-9a-f]\{4}#\=eval('"'.submatch(0).'"')#
fn get_icon(&self, status: &GitStatus) -> String {
match status {
GitStatus::Default => "_",
GitStatus::Unmodified => "_", // "\u{f00c}"
GitStatus::NewInIndex => "\u{f067}",
GitStatus::Unmodified => "_",
GitStatus::NewInIndex => "\u{f067}", // ""
GitStatus::NewInWorkdir => "?",
GitStatus::Deleted => "\u{f014}", // or f068
GitStatus::Modified => "\u{f8ea}",
GitStatus::Renamed => "\u{f8ea}",
GitStatus::Deleted => "\u{f014}", // ""
GitStatus::Modified => "\u{f8ea}", // ""
GitStatus::Renamed => "\u{f02b}", // ""
GitStatus::Ignored => "!",
GitStatus::Typechange => "\u{f0ec}",
GitStatus::Conflicted => "\u{f071}",
GitStatus::Typechange => "\u{f0ec}", // ""
GitStatus::Conflicted => "\u{f071}", // ""
}
.to_string()
}
Expand All @@ -54,3 +57,47 @@ impl GitIcons {
self.get_text(status)
}
}

#[cfg(test)]
mod test {
use super::Theme;
use crate::flags::git_icons::GitIcons;
use crate::git::GitStatus;
use std::collections::HashMap;
use strum::IntoEnumIterator;

fn test_non_duplicated(icons: &GitIcons) {
assert_eq!(
icons.get(&GitStatus::Default),
icons.get(&GitStatus::Unmodified)
);
let mut m = HashMap::new();
for status in GitStatus::iter() {
if status == GitStatus::Default {
continue;
}
assert_eq!(m.insert(icons.get(&status), status), None);
}
}

#[cfg(feature = "git")]
#[test]
fn test_non_duplicated_noicon() {
let icons = GitIcons::new(Theme::NoIcon);
test_non_duplicated(&icons);
}

#[cfg(feature = "git")]
#[test]
fn test_non_duplicated_unicode() {
let icons = GitIcons::new(Theme::Unicode);
test_non_duplicated(&icons);
}

#[cfg(feature = "git")]
#[test]
fn test_non_duplicated_fancy() {
let icons = GitIcons::new(Theme::Fancy);
test_non_duplicated(&icons);
}
}

0 comments on commit 4556325

Please sign in to comment.