-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support array indexing by range II (#634)
- Loading branch information
Showing
7 changed files
with
118 additions
and
46 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
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,30 @@ | ||
// Output | ||
// Value at -5: "" | ||
// Value at -4: "zero" | ||
// Value at -3: "one" | ||
// Value at -2: "two" | ||
// Value at -1: "three" | ||
|
||
// Replace this with builtin if/when we get around to writing one. | ||
#[allow_absurd_cast] | ||
fun bash_version(): Num { | ||
let major = trust $ echo "\$\{BASH_VERSINFO[0]}" $ as Num | ||
let minor = trust $ echo "\$\{BASH_VERSINFO[1]}" $ as Num | ||
return (major * 100) + minor | ||
} | ||
|
||
fun test_index(array) { | ||
for index in -5..=-1 { | ||
echo "Value at {index}: \"{array[index]}\"" | ||
} | ||
} | ||
|
||
main { | ||
if bash_version() >= 402 { | ||
let array = ["zero", "one", "two", "three"] | ||
test_index(array) | ||
} else { | ||
// Negative indexing is not supported before Bash 4.2. | ||
echo "Succeeded" | ||
} | ||
} |
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,30 @@ | ||
// Output | ||
// Value at -5: "" | ||
// Value at -4: "zero" | ||
// Value at -3: "one" | ||
// Value at -2: "two" | ||
// Value at -1: "three" | ||
|
||
// Replace this with builtin if/when we get around to writing one. | ||
#[allow_absurd_cast] | ||
fun bash_version(): Num { | ||
let major = trust $ echo "\$\{BASH_VERSINFO[0]}" $ as Num | ||
let minor = trust $ echo "\$\{BASH_VERSINFO[1]}" $ as Num | ||
return (major * 100) + minor | ||
} | ||
|
||
fun test_index(ref byref) { | ||
for index in -5..=-1 { | ||
echo "Value at {index}: \"{byref[index]}\"" | ||
} | ||
} | ||
|
||
main { | ||
if bash_version() >= 402 { | ||
let array = ["zero", "one", "two", "three"] | ||
test_index(array) | ||
} else { | ||
// Negative indexing is not supported before Bash 4.2. | ||
echo "Succeeded" | ||
} | ||
} |
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,29 @@ | ||
// Output | ||
// Value at -5: "" | ||
// Value at -4: "zero" | ||
// Value at -3: "one" | ||
// Value at -2: "two" | ||
// Value at -1: "three" | ||
|
||
// Replace this with builtin if/when we get around to writing one. | ||
#[allow_absurd_cast] | ||
fun bash_version(): Num { | ||
let major = trust $ echo "\$\{BASH_VERSINFO[0]}" $ as Num | ||
let minor = trust $ echo "\$\{BASH_VERSINFO[1]}" $ as Num | ||
return (major * 100) + minor | ||
} | ||
|
||
main { | ||
if bash_version() >= 402 { | ||
// Do not use loop; we want to test compile time arithmetic. | ||
let array = ["zero", "one", "two", "three"] | ||
echo "Value at -5: \"{array[-5]}\"" | ||
echo "Value at -4: \"{array[-4]}\"" | ||
echo "Value at -3: \"{array[-3]}\"" | ||
echo "Value at -2: \"{array[-2]}\"" | ||
echo "Value at -1: \"{array[-1]}\"" | ||
} else { | ||
// Negative indexing is not supported before Bash 4.2. | ||
echo "Succeeded" | ||
} | ||
} |
7 changes: 1 addition & 6 deletions
7
...tests/validity/array_get_index_by_copy.ab → ...idity/array_get_positive_index_by_copy.ab
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
7 changes: 1 addition & 6 deletions
7
src/tests/validity/array_get_index_by_ref.ab → ...lidity/array_get_positive_index_by_ref.ab
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
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