diff options
-rw-r--r-- | example/multiple_tabs_layout.yaml | 1 | ||||
-rw-r--r-- | zellij-utils/src/input/config.rs | 92 | ||||
-rw-r--r-- | zellij-utils/src/input/layout.rs | 51 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/fixtures/layouts/multiple-tabs-should-not-error.yaml (renamed from zellij-utils/src/input/unit/fixtures/layouts/multiple-tabs-should-panic.yaml) | 0 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/fixtures/layouts/no-tabs-should-error.yaml (renamed from zellij-utils/src/input/unit/fixtures/layouts/no-tabs-should-panic.yaml) | 0 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-error.yaml | 17 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-panic.yaml | 25 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/fixtures/layouts/three-tabs-merged-correctly.yaml | 25 | ||||
-rw-r--r-- | zellij-utils/src/input/unit/layout_test.rs | 215 | ||||
-rw-r--r-- | zellij-utils/src/setup.rs | 12 |
10 files changed, 354 insertions, 84 deletions
diff --git a/example/multiple_tabs_layout.yaml b/example/multiple_tabs_layout.yaml index 40689a969..6c4d15980 100644 --- a/example/multiple_tabs_layout.yaml +++ b/example/multiple_tabs_layout.yaml @@ -17,6 +17,7 @@ parts: split_size: Percent: 50 - direction: Vertical + - direction: Vertical parts: - direction: Vertical split_size: diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index 6a65109a7..930fe07af 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -45,6 +45,9 @@ pub enum ConfigError { IoPath(io::Error, PathBuf), // Internal Deserialization Error FromUtf8(std::string::FromUtf8Error), + // Missing the tab section in the layout. + Layout(LayoutMissingTabSectionError), + LayoutPartAndTab(LayoutPartAndTabError), } impl Default for Config { @@ -129,6 +132,75 @@ impl Config { } } +// TODO: Split errors up into separate modules +#[derive(Debug, Clone)] +pub struct LayoutMissingTabSectionError; +#[derive(Debug, Clone)] +pub struct LayoutPartAndTabError; + +impl fmt::Display for LayoutMissingTabSectionError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "MissingTabSectionError: +There needs to be exactly one `tabs` section specified in the layout file, for example: +--- +direction: Horizontal +parts: + - direction: Vertical + - direction: Vertical + tabs: + - direction: Vertical + - direction: Vertical + - direction: Vertical +" + ) + } +} + +impl std::error::Error for LayoutMissingTabSectionError { + fn description(&self) -> &str { + "One tab must be specified per Layout." + } +} + +impl fmt::Display for LayoutPartAndTabError { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!( + f, + "LayoutPartAndTabError: +The `tabs` and `parts` section should not be specified on the same level in the layout file, for example: +--- +direction: Horizontal +parts: + - direction: Vertical + - direction: Vertical +tabs: + - direction: Vertical + - direction: Vertical + - direction: Vertical + +should rather be specified as: +--- +direction: Horizontal +parts: + - direction: Vertical + - direction: Vertical + tabs: + - direction: Vertical + - direction: Vertical + - direction: Vertical +" + ) + } +} + +impl std::error::Error for LayoutPartAndTabError { + fn description(&self) -> &str { + "The `tabs` and parts section should not be specified on the same level." + } +} + impl Display for ConfigError { fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result { match self { @@ -138,6 +210,12 @@ impl Display for ConfigError { } ConfigError::Serde(ref err) => write!(formatter, "Deserialization error: {}", err), ConfigError::FromUtf8(ref err) => write!(formatter, "FromUtf8Error: {}", err), + ConfigError::Layout(ref err) => { + write!(formatter, "There was an error in the layout file, {}", err) + } + ConfigError::LayoutPartAndTab(ref err) => { + write!(formatter, "There was an error in the layout file, {}", err) + } } } } @@ -149,6 +227,8 @@ impl std::error::Error for ConfigError { ConfigError::IoPath(ref err, _) => Some(err), ConfigError::Serde(ref err) => Some(err), ConfigError::FromUtf8(ref err) => Some(err), + ConfigError::Layout(ref err) => Some(err), + ConfigError::LayoutPartAndTab(ref err) => Some(err), } } } @@ -171,6 +251,18 @@ impl From<std::string::FromUtf8Error> for ConfigError { } } +impl From<LayoutMissingTabSectionError> for ConfigError { + fn from(err: LayoutMissingTabSectionError) -> ConfigError { + ConfigError::Layout(err) + } +} + +impl From<LayoutPartAndTabError> for ConfigError { + fn from(err: LayoutPartAndTabError) -> ConfigError { + ConfigError::LayoutPartAndTab(err) + } +} + // The unit test location. #[cfg(test)] mod config_test { diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 887350fb0..c795cb55b 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -20,6 +20,8 @@ use std::path::{Path, PathBuf}; use std::vec::Vec; use std::{fs::File, io::prelude::*}; +use super::config::{LayoutMissingTabSectionError, LayoutPartAndTabError}; + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] pub enum Direction { @@ -43,7 +45,7 @@ pub enum Run { Command(RunCommand), } -// The layout struct that is ultimately used to build the layouts +// The layout struct ultimately used to build the layouts. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] pub struct Layout { @@ -56,6 +58,7 @@ pub struct Layout { pub run: Option<Run>, } +// The tab-layout struct used to specify each individual tab. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] pub struct TabLayout { @@ -66,8 +69,8 @@ pub struct TabLayout { pub run: Option<Run>, } -// Main layout struct, that carries information based on -// position of tabs +// Main layout struct, that carries information based on position of tabs +// in relation to the whole layout. #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)] #[serde(crate = "self::serde")] pub struct MainLayout { @@ -205,7 +208,9 @@ impl Layout { // Split the layout into parts that can be reassebled per tab // returns the layout pre tab, the parts post tab and the tab layouts - pub fn split_main_and_tab_layout(&self) -> (Layout, Vec<Layout>, Vec<TabLayout>) { + pub fn split_main_and_tab_layout( + &self, + ) -> Result<(Layout, Vec<Layout>, Vec<TabLayout>), LayoutPartAndTabError> { let mut main_layout = self.clone(); let mut pre_tab_layout = self.clone(); let mut post_tab_layout = vec![]; @@ -220,23 +225,21 @@ impl Layout { post_tab = true; } + if !main_layout.tabs.is_empty() && !main_layout.parts.is_empty() { + return Err(LayoutPartAndTabError); + } + for part in main_layout.parts.drain(..) { let (curr_pre_layout, mut curr_post_layout, mut curr_tabs) = - part.split_main_and_tab_layout(); + part.split_main_and_tab_layout()?; // Leaf if !post_tab && part.tabs.is_empty() { pre_tab_layout.parts.push(curr_pre_layout); } - // Todo: Convert into actual Error, or use the future logging system. if !part.tabs.is_empty() && !part.parts.is_empty() { - panic!("Tabs and Parts need to be specified separately."); - } - - // Todo: Convert into actual Error, or use the future logging system. - if (!part.tabs.is_empty() || !curr_tabs.is_empty()) && post_tab { - panic!("Only one tab section should be specified."); + return Err(LayoutPartAndTabError); } // Node @@ -259,7 +262,7 @@ impl Layout { } } } - (pre_tab_layout, post_tab_layout, tabs) + Ok((pre_tab_layout, post_tab_layout, tabs)) } pub fn merge_tab_layout(&mut self, tab: TabLayout) { @@ -271,33 +274,31 @@ impl Layout { } pub fn construct_full_layout(&self, tab_layout: Option<TabLayout>) -> Self { + // The `split_main_and_tab_layout()` error should have returned + // already from deserialisation, so we can assume it is `Ok()`. + let (mut pre_tab_layout, post_tab_layout, _) = self.split_main_and_tab_layout().unwrap(); if let Some(tab_layout) = tab_layout { - let (mut pre_tab_layout, post_tab_layout, _) = self.split_main_and_tab_layout(); pre_tab_layout.merge_tab_layout(tab_layout); - pre_tab_layout.merge_layout_parts(post_tab_layout); - pre_tab_layout } else { - let (mut pre_tab_layout, post_tab_layout, _) = self.split_main_and_tab_layout(); let default_tab_layout = TabLayout::default(); pre_tab_layout.merge_tab_layout(default_tab_layout); - pre_tab_layout.merge_layout_parts(post_tab_layout); - pre_tab_layout } + pre_tab_layout.merge_layout_parts(post_tab_layout); + pre_tab_layout } - pub fn construct_main_layout(&self) -> MainLayout { - let (pre_tab, post_tab, tabs) = self.split_main_and_tab_layout(); + pub fn construct_main_layout(&self) -> Result<MainLayout, ConfigError> { + let (pre_tab, post_tab, tabs) = self.split_main_and_tab_layout()?; - // Todo: A proper LayoutError if tabs.is_empty() { - panic!("The layout file should have a [`tabs`] section specified"); + return Err(ConfigError::Layout(LayoutMissingTabSectionError)); } - MainLayout { + Ok(MainLayout { pre_tab, post_tab, tabs, - } + }) } fn from_vec_tab_layout(tab_layout: Vec<TabLayout>) -> Vec<Self> { diff --git a/zellij-utils/src/input/unit/fixtures/layouts/multiple-tabs-should-panic.yaml b/zellij-utils/src/input/unit/fixtures/layouts/multiple-tabs-should-not-error.yaml index 653787591..653787591 100644 --- a/zellij-utils/src/input/unit/fixtures/layouts/multiple-tabs-should-panic.yaml +++ b/zellij-utils/src/input/unit/fixtures/layouts/multiple-tabs-should-not-error.yaml diff --git a/zellij-utils/src/input/unit/fixtures/layouts/no-tabs-should-panic.yaml b/zellij-utils/src/input/unit/fixtures/layouts/no-tabs-should-error.yaml index a67b0ff95..a67b0ff95 100644 --- a/zellij-utils/src/input/unit/fixtures/layouts/no-tabs-should-panic.yaml +++ b/zellij-utils/src/input/unit/fixtures/layouts/no-tabs-should-error.yaml diff --git a/zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-error.yaml b/zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-error.yaml new file mode 100644 index 000000000..e7223602d --- /dev/null +++ b/zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-error.yaml @@ -0,0 +1,17 @@ +--- +direction: Horizontal +parts: + - direction: Horizontal + tabs: + - direction: Vertical + parts: + - direction: Horizontal + split_size: + Percent: 50 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Vertical + split_size: + Percent: 50 diff --git a/zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-panic.yaml b/zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-panic.yaml deleted file mode 100644 index 1ef5a05ee..000000000 --- a/zellij-utils/src/input/unit/fixtures/layouts/tabs-and-parts-together-should-panic.yaml +++ /dev/null @@ -1,25 +0,0 @@ ---- -direction: Horizontal -parts: - - direction: Horizontal - tabs: - - direction: Vertical - parts: - - direction: Horizontal - split_size: - Percent: 50 - - direction: Horizontal - parts: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 - tabs: - - direction: Vertical - split_size: - Percent: 50 - - direction: Vertical - split_size: - Percent: 50 diff --git a/zellij-utils/src/input/unit/fixtures/layouts/three-tabs-merged-correctly.yaml b/zellij-utils/src/input/unit/fixtures/layouts/three-tabs-merged-correctly.yaml new file mode 100644 index 000000000..96e1524d5 --- /dev/null +++ b/zellij-utils/src/input/unit/fixtures/layouts/three-tabs-merged-correctly.yaml @@ -0,0 +1,25 @@ +--- +direction: Vertical +parts: + - direction: Horizontal + tabs: + - direction: Horizontal + split_size: + Percent: 50 + - direction: Horizontal + split_size: + Percent: 50 + parts: + - direction: Horizontal + split_size: + Percent: 50 + - direction: Horizontal + - direction: Vertical + split_size: + Percent: 50 + parts: + - direction: Vertical + split_size: + Percent: 50 + - direction: Horizontal + - direction: Horizontal diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index 5d9fda35a..1a90c1ff4 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -23,7 +23,7 @@ fn default_layout_is_ok() { fn default_layout_has_one_tab() { let path = default_layout_dir("default.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.tabs.len(), 1); } @@ -31,7 +31,7 @@ fn default_layout_has_one_tab() { fn default_layout_has_one_pre_tab() { let path = default_layout_dir("default.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.pre_tab.parts.len(), 1); } @@ -39,7 +39,7 @@ fn default_layout_has_one_pre_tab() { fn default_layout_has_one_post_tab() { let path = default_layout_dir("default.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.post_tab.len(), 1); } @@ -47,7 +47,7 @@ fn default_layout_has_one_post_tab() { fn default_layout_merged_correctly() { let path = default_layout_dir("default.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(Some(main_layout.tabs[0].clone())); let merged_layout = Layout { direction: Direction::Horizontal, @@ -85,7 +85,7 @@ fn default_layout_merged_correctly() { fn default_layout_new_tab_correct() { let path = default_layout_dir("default.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(None); let merged_layout = Layout { direction: Direction::Horizontal, @@ -137,7 +137,7 @@ fn default_disable_status_layout_is_ok() { fn default_disable_status_layout_has_one_tab() { let path = default_layout_dir("disable-status-bar.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.tabs.len(), 1); } @@ -145,7 +145,7 @@ fn default_disable_status_layout_has_one_tab() { fn default_disable_status_layout_has_one_pre_tab() { let path = default_layout_dir("disable-status-bar.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.pre_tab.parts.len(), 1); } @@ -153,7 +153,7 @@ fn default_disable_status_layout_has_one_pre_tab() { fn default_disable_status_layout_has_no_post_tab() { let path = default_layout_dir("disable-status-bar.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); assert!(main_layout.post_tab.is_empty()); } @@ -168,7 +168,7 @@ fn three_panes_with_tab_is_ok() { fn three_panes_with_tab_has_one_tab() { let path = layout_test_dir("three-panes-with-tab.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.tabs.len(), 1); } @@ -176,7 +176,7 @@ fn three_panes_with_tab_has_one_tab() { fn three_panes_with_tab_no_post_tab() { let path = layout_test_dir("three-panes-with-tab.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert!(main_layout.post_tab.is_empty()); } @@ -184,7 +184,7 @@ fn three_panes_with_tab_no_post_tab() { fn three_panes_with_tab_no_pre_tab() { let path = layout_test_dir("three-panes-with-tab.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert!(main_layout.pre_tab.parts.is_empty()); } @@ -192,7 +192,7 @@ fn three_panes_with_tab_no_pre_tab() { fn three_panes_with_tab_merged_correctly() { let path = layout_test_dir("three-panes-with-tab.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(Some(main_layout.tabs[0].clone())); let merged_layout = Layout { direction: Direction::Horizontal, @@ -244,7 +244,7 @@ fn three_panes_with_tab_merged_correctly() { fn three_panes_with_tab_new_tab_is_correct() { let path = layout_test_dir("three-panes-with-tab.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(None); let merged_layout = Layout { direction: Direction::Horizontal, @@ -273,7 +273,7 @@ fn three_panes_with_tab_and_default_plugins_is_ok() { fn three_panes_with_tab_and_default_plugins_has_one_tab() { let path = layout_test_dir("three-panes-with-tab-and-default-plugins.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.tabs.len(), 1); } @@ -281,7 +281,7 @@ fn three_panes_with_tab_and_default_plugins_has_one_tab() { fn three_panes_with_tab_and_default_plugins_one_post_tab() { let path = layout_test_dir("three-panes-with-tab-and-default-plugins.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.post_tab.len(), 1); } @@ -289,7 +289,7 @@ fn three_panes_with_tab_and_default_plugins_one_post_tab() { fn three_panes_with_tab_and_default_plugins_has_pre_tab() { let path = layout_test_dir("three-panes-with-tab-and-default-plugins.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert!(!main_layout.pre_tab.parts.is_empty()); } @@ -297,7 +297,7 @@ fn three_panes_with_tab_and_default_plugins_has_pre_tab() { fn three_panes_with_tab_and_default_plugins_merged_correctly() { let path = layout_test_dir("three-panes-with-tab-and-default-plugins.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(Some(main_layout.tabs[0].clone())); let merged_layout = Layout { direction: Direction::Horizontal, @@ -365,7 +365,7 @@ fn three_panes_with_tab_and_default_plugins_merged_correctly() { fn three_panes_with_tab_and_default_plugins_new_tab_is_correct() { let path = layout_test_dir("three-panes-with-tab-and-default-plugins.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(None); let merged_layout = Layout { direction: Direction::Horizontal, @@ -410,7 +410,7 @@ fn deeply_nested_tab_is_ok() { fn deeply_nested_tab_has_one_tab() { let path = layout_test_dir("deeply-nested-tab-layout.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.tabs.len(), 1); } @@ -418,7 +418,7 @@ fn deeply_nested_tab_has_one_tab() { fn deeply_nested_tab_three_post_tab() { let path = layout_test_dir("deeply-nested-tab-layout.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert_eq!(main_layout.post_tab.len(), 3); } @@ -426,7 +426,7 @@ fn deeply_nested_tab_three_post_tab() { fn deeply_nested_tab_has_many_pre_tab() { let path = layout_test_dir("deeply-nested-tab-layout.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); assert!(!main_layout.pre_tab.parts.is_empty()); } @@ -434,7 +434,7 @@ fn deeply_nested_tab_has_many_pre_tab() { fn deeply_nested_tab_merged_correctly() { let path = layout_test_dir("deeply-nested-tab-layout.yaml".into()); let layout = Layout::new(&path); - let main_layout = layout.as_ref().unwrap().construct_main_layout(); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); let tab_layout = main_layout.construct_tab_layout(Some(main_layout.tabs[0].clone())); let merged_layout = Layout { direction: Direction::Horizontal, @@ -519,17 +519,172 @@ fn deeply_nested_tab_merged_correctly() { } #[test] -#[should_panic] -// TODO Make error out of this -fn no_tabs_specified_should_panic() { - let path = layout_test_dir("no-tabs-should-panic.yaml".into()); +fn no_tabs_specified_should_err() { + let path = layout_test_dir("no-tabs-should-error.yaml".into()); let layout = Layout::new(&path); - let _main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout(); + assert!(main_layout.is_err()); } #[test] -fn multiple_tabs_specified_should_not_panic() { - let path = layout_test_dir("multiple-tabs-should-panic.yaml".into()); +fn tabs_and_parts_specified_together_should_should_err() { + let path = layout_test_dir("tabs-and-parts-together-should-error.yaml".into()); let layout = Layout::new(&path); - let _main_layout = layout.unwrap().construct_main_layout(); + let main_layout = layout.unwrap().construct_main_layout(); + assert!(main_layout.is_err()); +} + +#[test] +fn multiple_tabs_specified_should_not_err() { + let path = layout_test_dir("multiple-tabs-should-not-error.yaml".into()); + let layout = Layout::new(&path); + let main_layout = layout.unwrap().construct_main_layout(); + assert!(main_layout.is_ok()) +} +#[test] +fn three_tabs_is_ok() { + let path = layout_test_dir("three-tabs-merged-correctly.yaml".into()); + let layout = Layout::new(&path); + assert!(layout.is_ok()); +} + +#[test] +fn three_tabs_has_three_tabs() { + let path = layout_test_dir("three-tabs-merged-correctly.yaml".into()); + let layout = Layout::new(&path); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); + assert_eq!(main_layout.tabs.len(), 3); +} + +#[test] +fn three_tabs_has_one_post_tab() { + let path = layout_test_dir("three-tabs-merged-correctly.yaml".into()); + let layout = Layout::new(&path); + let main_layout = layout.unwrap().construct_main_layout().unwrap(); + assert_eq!(main_layout.post_tab.len(), 1); +} + +#[test] +fn three_tabs_tab_one_merged_correctly() { + let path = layout_test_dir("three-tabs-merged-correctly.yaml".into()); + let layout = Layout::new(&path); + let main_layout = layout.as_ref().unwrap().construct_main_layout().unwrap(); + let tab_layout = main_layout.construct_tab_layout(Some(main_layout.tabs[0].clone())); |