From 4556325a7baa36b56ce7f15726e212e722cb962e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pascal=20HAV=C3=89?= Date: Mon, 22 Mar 2021 23:09:36 +0100 Subject: [PATCH] Add non redundancy test on git icons --- src/flags/git_icons.rs | 61 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/flags/git_icons.rs b/src/flags/git_icons.rs index a898b42fa..3f5b4c4f4 100644 --- a/src/flags/git_icons.rs +++ b/src/flags/git_icons.rs @@ -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() } @@ -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); + } +}