diff options
Diffstat (limited to 'zellij-utils/src/input/unit/layout_test.rs')
-rw-r--r-- | zellij-utils/src/input/unit/layout_test.rs | 669 |
1 files changed, 387 insertions, 282 deletions
diff --git a/zellij-utils/src/input/unit/layout_test.rs b/zellij-utils/src/input/unit/layout_test.rs index d588fcda6..f15fd709d 100644 --- a/zellij-utils/src/input/unit/layout_test.rs +++ b/zellij-utils/src/input/unit/layout_test.rs @@ -4,9 +4,9 @@ use insta::assert_snapshot; #[test] fn empty_layout() { let kdl_layout = "layout"; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout::default()), + template: Some((TiledPaneLayout::default(), vec![])), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -19,12 +19,15 @@ fn layout_with_one_pane() { pane } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout::default()], - ..Default::default() - }), + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout::default()], + ..Default::default() + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -39,16 +42,19 @@ fn layout_with_multiple_panes() { pane } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![ - PaneLayout::default(), - PaneLayout::default(), - PaneLayout::default(), - ], - ..Default::default() - }), + template: Some(( + TiledPaneLayout { + children: vec![ + TiledPaneLayout::default(), + TiledPaneLayout::default(), + TiledPaneLayout::default(), + ], + ..Default::default() + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -68,22 +74,25 @@ fn layout_with_nested_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![ - PaneLayout { - children_split_direction: SplitDirection::Vertical, - children: vec![PaneLayout::default(), PaneLayout::default()], - ..Default::default() - }, - PaneLayout { - children: vec![PaneLayout::default(), PaneLayout::default()], - ..Default::default() - }, - ], - ..Default::default() - }), + template: Some(( + TiledPaneLayout { + children: vec![ + TiledPaneLayout { + children_split_direction: SplitDirection::Vertical, + children: vec![TiledPaneLayout::default(), TiledPaneLayout::default()], + ..Default::default() + }, + TiledPaneLayout { + children: vec![TiledPaneLayout::default(), TiledPaneLayout::default()], + ..Default::default() + }, + ], + ..Default::default() + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -106,32 +115,34 @@ fn layout_with_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout::default()), - floating_panes_template: vec![ - FloatingPanesLayout::default(), - FloatingPanesLayout { - x: Some(PercentOrFixed::Fixed(10)), - y: Some(PercentOrFixed::Percent(10)), - width: Some(PercentOrFixed::Fixed(10)), - height: Some(PercentOrFixed::Percent(10)), - ..Default::default() - }, - FloatingPanesLayout { - x: Some(PercentOrFixed::Fixed(10)), - y: Some(PercentOrFixed::Percent(10)), - ..Default::default() - }, - FloatingPanesLayout { - run: Some(Run::Command(RunCommand { - command: PathBuf::from("htop"), - hold_on_close: true, + template: Some(( + TiledPaneLayout::default(), + vec![ + FloatingPaneLayout::default(), + FloatingPaneLayout { + x: Some(PercentOrFixed::Fixed(10)), + y: Some(PercentOrFixed::Percent(10)), + width: Some(PercentOrFixed::Fixed(10)), + height: Some(PercentOrFixed::Percent(10)), ..Default::default() - })), - ..Default::default() - }, - ], + }, + FloatingPaneLayout { + x: Some(PercentOrFixed::Fixed(10)), + y: Some(PercentOrFixed::Percent(10)), + ..Default::default() + }, + FloatingPaneLayout { + run: Some(Run::Command(RunCommand { + command: PathBuf::from("htop"), + hold_on_close: true, + ..Default::default() + })), + ..Default::default() + }, + ], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -148,13 +159,15 @@ fn layout_with_mixed_panes_and_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout::default(), PaneLayout::default()], - ..Default::default() - }), - floating_panes_template: vec![FloatingPanesLayout::default()], + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout::default(), TiledPaneLayout::default()], + ..Default::default() + }, + vec![FloatingPaneLayout::default()], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -175,20 +188,22 @@ fn layout_with_floating_panes_template() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout::default()], - ..Default::default() - }), - floating_panes_template: vec![ - FloatingPanesLayout::default(), - FloatingPanesLayout { - x: Some(PercentOrFixed::Fixed(10)), - y: Some(PercentOrFixed::Percent(10)), + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout::default()], ..Default::default() }, - ], + vec![ + FloatingPaneLayout::default(), + FloatingPaneLayout { + x: Some(PercentOrFixed::Fixed(10)), + y: Some(PercentOrFixed::Percent(10)), + ..Default::default() + }, + ], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -208,30 +223,32 @@ fn layout_with_shared_tiled_and_floating_panes_template() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - run: Some(Run::Command(RunCommand { - command: PathBuf::from("htop"), - hold_on_close: true, - ..Default::default() - })), - ..Default::default() - }], - ..Default::default() - }), - floating_panes_template: vec![ - FloatingPanesLayout::default(), - FloatingPanesLayout { - run: Some(Run::Command(RunCommand { - command: PathBuf::from("htop"), - hold_on_close: true, + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + run: Some(Run::Command(RunCommand { + command: PathBuf::from("htop"), + hold_on_close: true, + ..Default::default() + })), ..Default::default() - })), + }], ..Default::default() }, - ], + vec![ + FloatingPaneLayout::default(), + FloatingPaneLayout { + run: Some(Run::Command(RunCommand { + command: PathBuf::from("htop"), + hold_on_close: true, + ..Default::default() + })), + ..Default::default() + }, + ], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -254,7 +271,7 @@ fn layout_with_tabs_and_floating_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); assert_snapshot!(format!("{:#?}", layout)); } @@ -265,10 +282,10 @@ fn layout_with_tabs() { tab } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - tabs: vec![(None, PaneLayout::default(), vec![])], - template: Some(PaneLayout::default()), + tabs: vec![(None, TiledPaneLayout::default(), vec![])], + template: Some((TiledPaneLayout::default(), vec![])), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -289,17 +306,17 @@ fn layout_with_nested_differing_tabs() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { tabs: vec![ ( None, - PaneLayout { + TiledPaneLayout { children_split_direction: SplitDirection::Vertical, children: vec![ - PaneLayout::default(), - PaneLayout::default(), - PaneLayout::default(), + TiledPaneLayout::default(), + TiledPaneLayout::default(), + TiledPaneLayout::default(), ], ..Default::default() }, @@ -307,15 +324,15 @@ fn layout_with_nested_differing_tabs() { ), ( None, - PaneLayout { + TiledPaneLayout { children_split_direction: SplitDirection::Horizontal, - children: vec![PaneLayout::default(), PaneLayout::default()], + children: vec![TiledPaneLayout::default(), TiledPaneLayout::default()], ..Default::default() }, vec![], // floating panes ), ], - template: Some(PaneLayout::default()), + template: Some((TiledPaneLayout::default(), vec![])), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -331,29 +348,32 @@ fn layout_with_panes_in_different_mixed_split_sizes() { pane size=2; } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![ - PaneLayout { - split_size: Some(SplitSize::Fixed(1)), - ..Default::default() - }, - PaneLayout { - split_size: Some(SplitSize::Percent(10)), - ..Default::default() - }, - PaneLayout { - split_size: None, - ..Default::default() - }, - PaneLayout { - split_size: Some(SplitSize::Fixed(2)), - ..Default::default() - }, - ], - ..Default::default() - }), + template: Some(( + TiledPaneLayout { + children: vec![ + TiledPaneLayout { + split_size: Some(SplitSize::Fixed(1)), + ..Default::default() + }, + TiledPaneLayout { + split_size: Some(SplitSize::Percent(10)), + ..Default::default() + }, + TiledPaneLayout { + split_size: None, + ..Default::default() + }, + TiledPaneLayout { + split_size: Some(SplitSize::Fixed(2)), + ..Default::default() + }, + ], + ..Default::default() + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -366,19 +386,22 @@ fn layout_with_command_panes() { pane command="htop" } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - run: Some(Run::Command(RunCommand { - command: PathBuf::from("htop"), - hold_on_close: true, + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + run: Some(Run::Command(RunCommand { + command: PathBuf::from("htop"), + hold_on_close: true, + ..Default::default() + })), ..Default::default() - })), + }], ..Default::default() - }], - ..Default::default() - }), + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -391,20 +414,23 @@ fn layout_with_command_panes_and_cwd() { pane command="htop" cwd="/path/to/my/cwd" } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - run: Some(Run::Command(RunCommand { - command: PathBuf::from("htop"), - cwd: Some(PathBuf::from("/path/to/my/cwd")), - hold_on_close: true, + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + run: Some(Run::Command(RunCommand { + command: PathBuf::from("htop"), + cwd: Some(PathBuf::from("/path/to/my/cwd")), + hold_on_close: true, + ..Default::default() + })), ..Default::default() - })), + }], ..Default::default() - }], - ..Default::default() - }), + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -419,21 +445,24 @@ fn layout_with_command_panes_and_cwd_and_args() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - run: Some(Run::Command(RunCommand { - command: PathBuf::from("htop"), - cwd: Some(PathBuf::from("/path/to/my/cwd")), - args: vec![String::from("-h"), String::from("-v")], - hold_on_close: true, + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + run: Some(Run::Command(RunCommand { + command: PathBuf::from("htop"), + cwd: Some(PathBuf::from("/path/to/my/cwd")), + args: vec![String::from("-h"), String::from("-v")], + hold_on_close: true, + ..Default::default() + })), ..Default::default() - })), + }], ..Default::default() - }], - ..Default::default() - }), + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -448,7 +477,7 @@ fn layout_with_command_panes_and_close_on_exit() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); assert_snapshot!(format!("{:#?}", layout)); } @@ -461,7 +490,7 @@ fn layout_with_command_panes_and_start_suspended() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); assert_snapshot!(format!("{:#?}", layout)); } @@ -477,27 +506,32 @@ fn layout_with_plugin_panes() { } } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![ - PaneLayout { - run: Some(Run::Plugin(RunPlugin { - location: RunPluginLocation::Zellij(PluginTag::new("tab-bar")), - _allow_exec_host_cmd: false, - })), - ..Default::default() - }, - PaneLayout { - run: Some(Run::Plugin(RunPlugin { - location: RunPluginLocation::File(PathBuf::from("/path/to/my/plugin.wasm")), - _allow_exec_host_cmd: false, - })), - ..Default::default() - }, - ], - ..Default::default() - }), + template: Some(( + TiledPaneLayout { + children: vec![ + TiledPaneLayout { + run: Some(Run::Plugin(RunPlugin { + location: RunPluginLocation::Zellij(PluginTag::new("tab-bar")), + _allow_exec_host_cmd: false, + })), + ..Default::default() + }, + TiledPaneLayout { + run: Some(Run::Plugin(RunPlugin { + location: RunPluginLocation::File(PathBuf::from( + "/path/to/my/plugin.wasm", + )), + _allow_exec_host_cmd: false, + })), + ..Default::default() + }, + ], + ..Default::default() + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -510,15 +544,18 @@ fn layout_with_borderless_panes() { pane borderless=true } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - borderless: true, + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + borderless: true, + ..Default::default() + }], ..Default::default() - }], - ..Default::default() - }), + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -531,15 +568,18 @@ fn layout_with_focused_panes() { pane focus=true } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - focus: Some(true), + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + focus: Some(true), + ..Default::default() + }], ..Default::default() - }], - ..Default::default() - }), + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -552,15 +592,18 @@ fn layout_with_pane_names() { pane name="my awesome pane" } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { - template: Some(PaneLayout { - children: vec![PaneLayout { - name: Some("my awesome pane".into()), + template: Some(( + TiledPaneLayout { + children: vec![TiledPaneLayout { + name: Some("my awesome pane".into()), + ..Default::default() + }], ..Default::default() - }], - ..Default::default() - }), + }, + vec![], + )), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -574,12 +617,12 @@ fn layout_with_tab_names() { tab name="my cool tab name 2" } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { tabs: vec![ ( Some("my cool tab name 1".into()), - PaneLayout { + TiledPaneLayout { children: vec![], ..Default::default() }, @@ -587,14 +630,14 @@ fn layout_with_tab_names() { ), ( Some("my cool tab name 2".into()), - PaneLayout { + TiledPaneLayout { children: vec![], ..Default::default() }, vec![], // floating panes ), ], - template: Some(PaneLayout::default()), + template: Some((TiledPaneLayout::default(), vec![])), ..Default::default() }; assert_eq!(layout, expected_layout); @@ -609,14 +652,14 @@ fn layout_with_focused_tab() { tab } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { tabs: vec![ - (None, PaneLayout::default(), vec![]), - (None, PaneLayout::default(), vec![]), - (None, PaneLayout::default(), vec![]), + (None, TiledPaneLayout::default(), vec![]), + (None, TiledPaneLayout::default(), vec![]), + (None, TiledPaneLayout::default(), vec![]), ], - template: Some(PaneLayout::default()), + template: Some((TiledPaneLayout::default(), vec![])), focused_tab_index: Some(1), ..Default::default() }; @@ -643,21 +686,21 @@ fn layout_with_tab_templates() { one-above-one-below } "#; - let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None).unwrap(); + let layout = Layout::from_kdl(kdl_layout, "layout_file_name".into(), None, None).unwrap(); let expected_layout = Layout { tabs: vec![ ( Some("my first tab".into()), - PaneLayout { + TiledPaneLayout { children_split_direction: SplitDirection::Horizontal, children: vec![ - PaneLayout::default(), - PaneLayout { + TiledPaneLayout::default(), + TiledPaneLayout { children_split_direction: SplitDirection::Vertical, - children: vec![PaneLayout::default(), PaneLayout::default()], + children: vec![TiledPaneLayout::default(), TiledPaneLayout::default()], ..Default::default() }, - PaneLayout::default(), + TiledPaneLayout::default(), ], ..Default::default() |