Skip to content

Commit

Permalink
remove map_or and add some more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kariy authored and mkaput committed Mar 3, 2023
1 parent cd90716 commit 036d14a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
6 changes: 3 additions & 3 deletions scarb/src/manifest_editor/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ impl Op for AddDependency {

let dep = Dep::resolve(*self, ctx)?;

let was_sorted = tab.as_table_like().map_or(true, |dep_table| {
let values = dep_table.get_values();
let was_sorted = {
let values = tab.as_table_like().unwrap().get_values();
is_sorted(values.iter().map(|(key, _)| key[0]))
});
};

let dep_key = dep.toml_key().to_string();
dep.upsert(tab.as_table_like_mut().unwrap().entry(&dep_key));
Expand Down
58 changes: 56 additions & 2 deletions scarb/tests/e2e/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,62 @@ fn should_sort_if_already_sorted() {
foo = "1.0.0"
"#})
.run();

ManifestEditHarness::offline()
.args(["add", "[email protected]"])
.input(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
[dependencies]
bar = "1.0.0"
dep = "1.0.0"
foo = "1.0.0"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
[dependencies]
bar = "1.0.0"
cat = "2.0.0"
dep = "1.0.0"
foo = "1.0.0"
"#})
.run();

ManifestEditHarness::offline()
.args(["add", "[email protected]"])
.input(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
[dependencies]
bar = "1.0.0"
cat = "2.0.0"
dep = "1.0.0"
foo = "1.0.0"
"#})
.output(indoc! {r#"
[package]
name = "hello"
version = "1.0.0"
[dependencies]
bar = "1.0.0"
cat = "2.0.0"
dep = "1.0.0"
dog = "2.0.0"
foo = "1.0.0"
"#})
.run();
}

#[test]
Expand All @@ -391,7 +447,6 @@ fn should_not_sort_if_already_unsorted() {
[dependencies]
bar = "1.0.0"
foo = "1.0.0"
dep = "1.0.0"
"#})
.output(indoc! {r#"
Expand All @@ -402,7 +457,6 @@ fn should_not_sort_if_already_unsorted() {
[dependencies]
bar = "1.0.0"
foo = "1.0.0"
dep = "1.0.0"
apple = "1.0.0"
"#})
Expand Down

0 comments on commit 036d14a

Please sign in to comment.