mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler/vlib: replace substr/left/right with [start..end] everywhere
This commit is contained in:
committed by
Alexander Medvednikov
parent
ed55826686
commit
59378dce46
@@ -116,7 +116,7 @@ fn test_repeat() {
|
||||
|
||||
fn test_right() {
|
||||
a := [1, 2, 3, 4]
|
||||
b := a.right(1)
|
||||
b := a[1..]
|
||||
c := a[1..a.len]
|
||||
d := a[1..]
|
||||
assert b[0] == 2
|
||||
@@ -129,6 +129,9 @@ fn test_right() {
|
||||
|
||||
fn test_right_with_n_bigger_than_array_size() {
|
||||
a := [1, 2, 3, 4]
|
||||
// NOTE: slice syntax wont return empty array
|
||||
// instead will give index out of bounds
|
||||
// mut b := a[10..]
|
||||
mut b := a.right(10)
|
||||
assert b.len == 0
|
||||
|
||||
@@ -143,7 +146,7 @@ fn test_right_with_n_bigger_than_array_size() {
|
||||
|
||||
fn test_left() {
|
||||
a := [1, 2, 3]
|
||||
b := a.left(2)
|
||||
b := a[..2]
|
||||
c := a[0..2]
|
||||
d := a[..2]
|
||||
assert b[0] == 1
|
||||
@@ -207,9 +210,9 @@ fn modify (numbers mut []int) {
|
||||
|
||||
fn test_mut_slice() {
|
||||
mut n := [1,2,3]
|
||||
modify(mut n.left(2))
|
||||
modify(mut n[..2])
|
||||
assert n[0] == 777
|
||||
modify(mut n.right(2))
|
||||
modify(mut n[2..])
|
||||
assert n[2] == 777
|
||||
println(n)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user