mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-10 10:35:16 +03:00
Put some tests behind #[cfg(test)] (#1459)
It was missing in a few places.
This commit is contained in:
parent
939261fc07
commit
05e5520ec0
@ -20,14 +20,18 @@ pub struct LspConfig {
|
||||
pub display_messages: bool,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parsing_keymaps_config_file() {
|
||||
use crate::keymap;
|
||||
use crate::keymap::Keymap;
|
||||
use helix_core::hashmap;
|
||||
use helix_view::document::Mode;
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
let sample_keymaps = r#"
|
||||
#[test]
|
||||
fn parsing_keymaps_config_file() {
|
||||
use crate::keymap;
|
||||
use crate::keymap::Keymap;
|
||||
use helix_core::hashmap;
|
||||
use helix_view::document::Mode;
|
||||
|
||||
let sample_keymaps = r#"
|
||||
[keys.insert]
|
||||
y = "move_line_down"
|
||||
S-C-a = "delete_selection"
|
||||
@ -36,19 +40,20 @@ fn parsing_keymaps_config_file() {
|
||||
A-F12 = "move_next_word_end"
|
||||
"#;
|
||||
|
||||
assert_eq!(
|
||||
toml::from_str::<Config>(sample_keymaps).unwrap(),
|
||||
Config {
|
||||
keys: Keymaps(hashmap! {
|
||||
Mode::Insert => Keymap::new(keymap!({ "Insert mode"
|
||||
"y" => move_line_down,
|
||||
"S-C-a" => delete_selection,
|
||||
})),
|
||||
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
|
||||
"A-F12" => move_next_word_end,
|
||||
})),
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
toml::from_str::<Config>(sample_keymaps).unwrap(),
|
||||
Config {
|
||||
keys: Keymaps(hashmap! {
|
||||
Mode::Insert => Keymap::new(keymap!({ "Insert mode"
|
||||
"y" => move_line_down,
|
||||
"S-C-a" => delete_selection,
|
||||
})),
|
||||
Mode::Normal => Keymap::new(keymap!({ "Normal mode"
|
||||
"A-F12" => move_next_word_end,
|
||||
})),
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -296,53 +296,58 @@ impl TryFrom<Value> for ThemePalette {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_style_string() {
|
||||
let fg = Value::String("#ffffff".to_string());
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
let mut style = Style::default();
|
||||
let palette = ThemePalette::default();
|
||||
palette.parse_style(&mut style, fg).unwrap();
|
||||
#[test]
|
||||
fn test_parse_style_string() {
|
||||
let fg = Value::String("#ffffff".to_string());
|
||||
|
||||
assert_eq!(style, Style::default().fg(Color::Rgb(255, 255, 255)));
|
||||
}
|
||||
let mut style = Style::default();
|
||||
let palette = ThemePalette::default();
|
||||
palette.parse_style(&mut style, fg).unwrap();
|
||||
|
||||
#[test]
|
||||
fn test_palette() {
|
||||
use helix_core::hashmap;
|
||||
let fg = Value::String("my_color".to_string());
|
||||
|
||||
let mut style = Style::default();
|
||||
let palette =
|
||||
ThemePalette::new(hashmap! { "my_color".to_string() => Color::Rgb(255, 255, 255) });
|
||||
palette.parse_style(&mut style, fg).unwrap();
|
||||
|
||||
assert_eq!(style, Style::default().fg(Color::Rgb(255, 255, 255)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_style_table() {
|
||||
let table = toml::toml! {
|
||||
"keyword" = {
|
||||
fg = "#ffffff",
|
||||
bg = "#000000",
|
||||
modifiers = ["bold"],
|
||||
}
|
||||
};
|
||||
|
||||
let mut style = Style::default();
|
||||
let palette = ThemePalette::default();
|
||||
if let Value::Table(entries) = table {
|
||||
for (_name, value) in entries {
|
||||
palette.parse_style(&mut style, value).unwrap();
|
||||
}
|
||||
assert_eq!(style, Style::default().fg(Color::Rgb(255, 255, 255)));
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
style,
|
||||
Style::default()
|
||||
.fg(Color::Rgb(255, 255, 255))
|
||||
.bg(Color::Rgb(0, 0, 0))
|
||||
.add_modifier(Modifier::BOLD)
|
||||
);
|
||||
#[test]
|
||||
fn test_palette() {
|
||||
use helix_core::hashmap;
|
||||
let fg = Value::String("my_color".to_string());
|
||||
|
||||
let mut style = Style::default();
|
||||
let palette =
|
||||
ThemePalette::new(hashmap! { "my_color".to_string() => Color::Rgb(255, 255, 255) });
|
||||
palette.parse_style(&mut style, fg).unwrap();
|
||||
|
||||
assert_eq!(style, Style::default().fg(Color::Rgb(255, 255, 255)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_style_table() {
|
||||
let table = toml::toml! {
|
||||
"keyword" = {
|
||||
fg = "#ffffff",
|
||||
bg = "#000000",
|
||||
modifiers = ["bold"],
|
||||
}
|
||||
};
|
||||
|
||||
let mut style = Style::default();
|
||||
let palette = ThemePalette::default();
|
||||
if let Value::Table(entries) = table {
|
||||
for (_name, value) in entries {
|
||||
palette.parse_style(&mut style, value).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
assert_eq!(
|
||||
style,
|
||||
Style::default()
|
||||
.fg(Color::Rgb(255, 255, 255))
|
||||
.bg(Color::Rgb(0, 0, 0))
|
||||
.add_modifier(Modifier::BOLD)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user