Skip to content

Commit

Permalink
Merge pull request pierrechevalier83#56 from pierrechevalier83/issue_…
Browse files Browse the repository at this point in the history
…50_test

Add test for issue pierrechevalier83#50
  • Loading branch information
pierrechevalier83 authored Apr 15, 2023
2 parents 4952d50 + 876095d commit 8bde72d
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ impl Config {
}
}

#[cfg(test)]
pub(crate) fn from_str(s: &str) -> Result<Self> {
toml::from_str(s).context("Failed to parse config as toml")
}

pub fn fallback_icon(&self) -> &str {
self.other
.fallback_icon
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
extern crate log;

mod config;
#[cfg(test)]
mod tests;
mod window_manager;

use std::collections::HashSet;
Expand Down
105 changes: 105 additions & 0 deletions src/tests/issue_50.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
use crate::config::Config;
use crate::pretty_window;
use crate::window_manager::Window;

const CONFIG_ISSUE_50: &str = "# Config for workstyle
#
# Format:
# \"pattern\" = \"icon\"
#
# The pattern will be used to match against the application name, class_id or WM_CLASS.
# The icon will be used to represent that application.
#
# Note if multiple patterns are present in the same application name,
# precedence is given in order of apparition in this file.
## partials
'/GitHub/' = ''
'/GitLab/' = ''
'/NVIM ?\\w*/' = ''
'/npm/' = ''
'/node/' = ''
'/yarn/' = ''
'/Stack Overflow/' = ''
## browsers
'google-chrome' = ''
'Google-chrome' = ''
'Google-chrome-unstable' = ''
'google-chrome-unstable' = ''
'Google-chrome-beta' = ''
'google-chrome-beta' = ''
'chromium' = ''
'firefox' = ''
'firefoxdeveloperedition' = ''
## default applications
'foot' = ''
'/foot/' = ''
'floating_shell' = ''
'pcmanfm' = ''
'nemo' = ''
'pamac-manager' = ''
'/Bluetooth/' = ''
'file-roller' = ''
'swappy' = ''
'org.kde.okular' = ''
'evince' = ''
## email
'Thunderbird' = ''
'thunderbird' = ''
'evolution' = ''
'kmail' = ''
## ide
'code' = '﬏'
'Code' = '﬏'
'/- Visual Studio Code/' = '﬏'
'/IntelliJ/' = ''
'code-url-handler' = '﬏'
'sublime_text' = ''
# messenger
'whatsapp-for-linux' = ''
'Slack' = ''
'/Telegram/' = ''
'/Microsoft Teams/' = ''
'Signal' = ''
## auth
'polkit-gnome-authentication-agent-1' = ''
'Keybase' = ''
## additional applications
'balena-etcher' = ''
'Steam' = ''
'vlc' = '嗢'
'org.qbittorrent.qBittorrent' = ''
'transmission-gtk' = ''
'Insomnia' = ''
'Bitwarden' = ''
'Spotify' = ''
'YouTube Music' = 'ﱘ'
'alacritty' = ''
'kitty' = ''
'font-manager' = ''
'lutris' = ''
'/Wine/' = ''
'Arctype' = ''
'Around' = ''
[other]
fallback_icon = ''
deduplicate_icons = true";

#[test]
fn test_pretty_window() {
let w = Window {
name: Some("Icons Icon | Font Awesome - Chromium".to_string()),
app_id: None,
window_properties_class: Some("chromium".to_string()),
};
let c = Config::from_str(CONFIG_ISSUE_50).unwrap();
assert_eq!("", pretty_window(&c, &w));
}
2 changes: 2 additions & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#[cfg(test)]
mod issue_50;
6 changes: 3 additions & 3 deletions src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ impl NodeExt for Node {

#[derive(Debug)]
pub struct Window {
name: Option<String>,
app_id: Option<String>,
window_properties_class: Option<String>,
pub(crate) name: Option<String>,
pub(crate) app_id: Option<String>,
pub(crate) window_properties_class: Option<String>,
}

impl Window {
Expand Down

0 comments on commit 8bde72d

Please sign in to comment.