Skip to content

Commit

Permalink
Clarify examples of slice behaviour (#297)
Browse files Browse the repository at this point in the history
This fixes the examples in the language definition and adds a few more
examples to the test suite that mirror this documentation.

The first example demonstrates the inclusive-exclusive nature of the
indicies.

The middle two examples demonstrate the property of `array[:i]` not
overlapping with `array[i:]`.
  • Loading branch information
danielwhite authored Dec 20, 2022
1 parent 2ce7cb6 commit 4387c16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions docs/Language-Definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ Example:
Variable `array` is `[1,2,3,4,5]`.

```
array[1:5] == [2,3,4]
array[1:4] == [2,3,4]
array[:3] == [1,2,3]
array[3:] == [4,5]
array[:4] == [1,2,3]
array[:] == array
```
12 changes: 12 additions & 0 deletions expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,18 @@ func TestExpr(t *testing.T) {
`Array[1:2]`,
[]int{2},
},
{
`Array[1:4]`,
[]int{2, 3, 4},
},
{
`Array[:3]`,
[]int{1, 2, 3},
},
{
`Array[3:]`,
[]int{4, 5},
},
{
`Array[0:5] == Array`,
true,
Expand Down

0 comments on commit 4387c16

Please sign in to comment.