forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add swap method to Vec<T> (FuelLabs#2231)
- Loading branch information
Showing
13 changed files
with
855 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param1_out_of_bounds/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-F443649679DC6856' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-F443649679DC6856' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'vec_swap_param1_out_of_bounds' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param1_out_of_bounds/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "vec_swap_param1_out_of_bounds" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
21 changes: 21 additions & 0 deletions
21
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param1_out_of_bounds/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
script; | ||
|
||
use std::{assert::assert, vec::Vec}; | ||
|
||
fn main() { | ||
let mut vector = ~Vec::new(); | ||
|
||
let number0 = 0u8; | ||
let number1 = 1u8; | ||
let number2 = 2u8; | ||
|
||
vector.push(number0); | ||
vector.push(number1); | ||
vector.push(number2); | ||
|
||
assert(vector.len() == 3); | ||
assert(vector.capacity() == 4); | ||
assert(vector.is_empty() == false); | ||
|
||
vector.swap(3, 0); | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param1_out_of_bounds/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
category = "run" | ||
expected_result = { action = "revert", value = 0 } | ||
validate_abi = false |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param2_out_of_bounds/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-626C5D02EBFA3B6A' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-626C5D02EBFA3B6A' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'vec_swap_param2_out_of_bounds' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param2_out_of_bounds/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "vec_swap_param2_out_of_bounds" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../sway-lib-std" } |
21 changes: 21 additions & 0 deletions
21
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param2_out_of_bounds/src/main.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
script; | ||
|
||
use std::{assert::assert, vec::Vec}; | ||
|
||
fn main() { | ||
let mut vector = ~Vec::new(); | ||
|
||
let number0 = 0u8; | ||
let number1 = 1u8; | ||
let number2 = 2u8; | ||
|
||
vector.push(number0); | ||
vector.push(number1); | ||
vector.push(number2); | ||
|
||
assert(vector.len() == 3); | ||
assert(vector.capacity() == 4); | ||
assert(vector.is_empty() == false); | ||
|
||
vector.swap(0, 3); | ||
} |
3 changes: 3 additions & 0 deletions
3
test/src/e2e_vm_tests/test_programs/should_fail/vec_swap_param2_out_of_bounds/test.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
category = "run" | ||
expected_result = { action = "revert", value = 0 } | ||
validate_abi = false |
14 changes: 14 additions & 0 deletions
14
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/vec_swap/Forc.lock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[package]] | ||
name = 'core' | ||
source = 'path+from-root-E670B7A81773E7E0' | ||
dependencies = [] | ||
|
||
[[package]] | ||
name = 'std' | ||
source = 'path+from-root-E670B7A81773E7E0' | ||
dependencies = ['core'] | ||
|
||
[[package]] | ||
name = 'vec_swap' | ||
source = 'root' | ||
dependencies = ['std'] |
8 changes: 8 additions & 0 deletions
8
test/src/e2e_vm_tests/test_programs/should_pass/stdlib/vec_swap/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[project] | ||
authors = ["Fuel Labs <[email protected]>"] | ||
entry = "main.sw" | ||
license = "Apache-2.0" | ||
name = "vec_swap" | ||
|
||
[dependencies] | ||
std = { path = "../../../../../../../sway-lib-std" } |
Oops, something went wrong.