aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorRoee Shapira <35409124+5c077m4n@users.noreply.github.com>2020-11-21 20:39:57 +0200
committerGitHub <noreply@github.com>2020-11-21 19:39:57 +0100
commitfd1f1ce697fae94101e971ff059aed9c33c379fd (patch)
tree92de576efdcfb5a9e8aab81626ee7372584db6be /src/tests
parentrefactor(structure): Change structure of `/tmp` directory (#62) (diff)
downloadsl0ppij-fd1f1ce697fae94101e971ff059aed9c33c379fd.tar.gz
sl0ppij-fd1f1ce697fae94101e971ff059aed9c33c379fd.tar.xz
sl0ppij-fd1f1ce697fae94101e971ff059aed9c33c379fd.zip
fix(layout): total layout percent 100 validation (#57)
* Fix for issue #52 * Added missing fixtures. * Added missing validation. * Moved layout creation and validation to the Layout struct. * Ran cargo fmt. * Added creation of tmp folder if needed. * Code review edit. * Code review edit. * Fancied code up. * PR request change. * PR code review. * Merge from upstream/main. * Merge from upstream/main.
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/fixtures/layouts/parts-total-less-than-100-percent.yaml16
-rw-r--r--src/tests/fixtures/layouts/parts-total-more-than-100-percent.yaml16
-rw-r--r--src/tests/integration/layouts.rs43
3 files changed, 74 insertions, 1 deletions
diff --git a/src/tests/fixtures/layouts/parts-total-less-than-100-percent.yaml b/src/tests/fixtures/layouts/parts-total-less-than-100-percent.yaml
new file mode 100644
index 00000000..e1a1a607
--- /dev/null
+++ b/src/tests/fixtures/layouts/parts-total-less-than-100-percent.yaml
@@ -0,0 +1,16 @@
+---
+ direction: Horizontal
+ parts:
+ - direction: Vertical
+ parts:
+ - direction: Horizontal
+ split_size:
+ Percent: 20
+ - direction: Horizontal
+ split_size:
+ Percent: 50
+ split_size:
+ Percent: 80
+ - direction: Vertical
+ split_size:
+ Percent: 20
diff --git a/src/tests/fixtures/layouts/parts-total-more-than-100-percent.yaml b/src/tests/fixtures/layouts/parts-total-more-than-100-percent.yaml
new file mode 100644
index 00000000..33d94225
--- /dev/null
+++ b/src/tests/fixtures/layouts/parts-total-more-than-100-percent.yaml
@@ -0,0 +1,16 @@
+---
+ direction: Horizontal
+ parts:
+ - direction: Vertical
+ parts:
+ - direction: Horizontal
+ split_size:
+ Percent: 20
+ - direction: Horizontal
+ split_size:
+ Percent: 90
+ split_size:
+ Percent: 80
+ - direction: Vertical
+ split_size:
+ Percent: 20
diff --git a/src/tests/integration/layouts.rs b/src/tests/integration/layouts.rs
index 9781336e..cef96d87 100644
--- a/src/tests/integration/layouts.rs
+++ b/src/tests/integration/layouts.rs
@@ -1,4 +1,5 @@
use ::insta::assert_snapshot;
+use std::path::PathBuf;
use crate::terminal_pane::PositionAndSize;
use crate::tests::fakes::FakeInputOutput;
@@ -20,11 +21,11 @@ pub fn accepts_basic_layout() {
};
let mut fake_input_output = get_fake_os_input(&fake_win_size);
fake_input_output.add_terminal_input(&[COMMAND_TOGGLE, COMMAND_TOGGLE, QUIT]);
- use std::path::PathBuf;
let mut opts = Opt::default();
opts.layout = Some(PathBuf::from(
"src/tests/fixtures/layouts/three-panes-with-nesting.yaml",
));
+
start(Box::new(fake_input_output.clone()), opts);
let output_frames = fake_input_output
.stdout_writer
@@ -49,3 +50,43 @@ pub fn accepts_basic_layout() {
assert_snapshot!(next_to_last_snapshot);
assert_snapshot!(last_snapshot);
}
+
+#[test]
+#[should_panic(expected = "The total percent for each part should equal 100.")]
+pub fn should_throw_for_more_than_100_percent_total() {
+ let fake_win_size = PositionAndSize {
+ columns: 121,
+ rows: 20,
+ x: 0,
+ y: 0,
+ };
+ let mut fake_input_output = get_fake_os_input(&fake_win_size);
+ fake_input_output.add_terminal_input(&[QUIT]);
+
+ let mut opts = Opt::default();
+ opts.layout = Some(PathBuf::from(
+ "src/tests/fixtures/layouts/parts-total-more-than-100-percent.yaml",
+ ));
+
+ start(Box::new(fake_input_output.clone()), opts);
+}
+
+#[test]
+#[should_panic(expected = "The total percent for each part should equal 100.")]
+pub fn should_throw_for_less_than_100_percent_total() {
+ let fake_win_size = PositionAndSize {
+ columns: 121,
+ rows: 20,
+ x: 0,
+ y: 0,
+ };
+ let mut fake_input_output = get_fake_os_input(&fake_win_size);
+ fake_input_output.add_terminal_input(&[QUIT]);
+
+ let mut opts = Opt::default();
+ opts.layout = Some(PathBuf::from(
+ "src/tests/fixtures/layouts/parts-total-less-than-100-percent.yaml",
+ ));
+
+ start(Box::new(fake_input_output.clone()), opts);
+}