mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
tests: use new array init syntax, fix mutability
This commit is contained in:
parent
0641a31fe0
commit
153ac230ec
@ -22,7 +22,7 @@ fn test_pointer() {
|
||||
}
|
||||
|
||||
fn test_assign() {
|
||||
arr := [2, 4, 8, 16, 32, 64, 128]
|
||||
mut arr := [2, 4, 8, 16, 32, 64, 128]
|
||||
|
||||
arr[0] = 2
|
||||
arr[1] &= 255
|
||||
@ -99,7 +99,7 @@ struct K {
|
||||
}
|
||||
|
||||
fn test_empty() {
|
||||
mut chunks := []Chunk
|
||||
mut chunks := []Chunk{}
|
||||
a := Chunk{}
|
||||
assert chunks.len == 0
|
||||
chunks << a
|
||||
@ -111,7 +111,7 @@ fn test_empty() {
|
||||
}
|
||||
|
||||
fn test_push() {
|
||||
mut a := []int
|
||||
mut a := []int{}
|
||||
a << 1
|
||||
a << 3
|
||||
assert a[1] == 3
|
||||
@ -289,7 +289,7 @@ fn test_reverse() {
|
||||
for i, _ in d {
|
||||
assert d[i] == b[b.len - i - 1]
|
||||
}
|
||||
e := []int
|
||||
e := []int{}
|
||||
f := e.reverse()
|
||||
assert f.len == 0
|
||||
}
|
||||
@ -711,7 +711,7 @@ fn test_hex(){
|
||||
}
|
||||
|
||||
fn test_left_shift_precendence() {
|
||||
mut arr := []int
|
||||
mut arr := []int{}
|
||||
arr << 1 + 1
|
||||
arr << 1 - 1
|
||||
arr << 2 / 1
|
||||
|
@ -11,7 +11,7 @@ const (
|
||||
// NOTE: temp until we have []bytes(buff)
|
||||
fn c_array_to_bytes_tmp(len int, buffer voidptr) []byte {
|
||||
|
||||
mut arr := []byte
|
||||
mut arr := []byte{}
|
||||
arr = make(len, 1, 1)
|
||||
arr.data = buffer
|
||||
/*
|
||||
|
@ -31,7 +31,7 @@ fn test_crypto_rand_read() {
|
||||
|
||||
fn test_crypto_rand_int_u64() {
|
||||
max := u64(160)
|
||||
mut unique := []int
|
||||
mut unique := []int{}
|
||||
for _ in 0..80 {
|
||||
r := rand.int_u64(max) or {
|
||||
assert false
|
||||
|
@ -4,10 +4,8 @@
|
||||
|
||||
module rand
|
||||
|
||||
import(
|
||||
math.bits
|
||||
encoding.binary
|
||||
)
|
||||
import math.bits
|
||||
import encoding.binary
|
||||
|
||||
pub fn int_u64(max u64) ?u64 {
|
||||
bitlen := bits.len_64(max)
|
||||
|
@ -16,7 +16,7 @@ pub fn next(max int) int {
|
||||
|
||||
// rand_r returns a pseudo-random number;
|
||||
// writes a result value to the seed argument.
|
||||
pub fn rand_r(seed mut int) int {
|
||||
pub fn rand_r(seed &int) int {
|
||||
ns := *seed * 1103515245 + 12345
|
||||
(*seed) = ns
|
||||
return ns & 0x7fffffff
|
||||
|
@ -5,21 +5,26 @@ struct Test {
|
||||
}
|
||||
|
||||
fn test_interpolation_map_to_string() {
|
||||
a := map[string]string
|
||||
if true {
|
||||
|
||||
}
|
||||
//
|
||||
else{}
|
||||
mut a := map[string]string
|
||||
a['1'] = 'one'
|
||||
a['2'] = 'two'
|
||||
a['3'] = 'three'
|
||||
assert '$a' == 'map_string_string{1: one, 2: two, 3: three}'
|
||||
b := map[string]int
|
||||
mut b := map[string]int
|
||||
b['1'] = 1
|
||||
b['2'] = 2
|
||||
b['3'] = 3
|
||||
assert '$b' == 'map_string_int{1: 1, 2: 2, 3: 3}'
|
||||
c := map[string]bool
|
||||
mut c := map[string]bool
|
||||
c['1'] = true
|
||||
c['2'] = false
|
||||
assert '$c' == 'map_string_bool{1: true, 2: false}'
|
||||
d := map[string]Test
|
||||
mut d := map[string]Test
|
||||
d['1'] = Test{true, 0, 'abc'}
|
||||
d['2'] = Test{true, 1, 'def'}
|
||||
d['3'] = Test{false, 2, 'ghi'}
|
||||
|
@ -1,5 +1,8 @@
|
||||
fn test_nested_maps() {
|
||||
x := map[string]map[string]int
|
||||
if true{}
|
||||
//
|
||||
else{}
|
||||
mut x := map[string]map[string]int
|
||||
x["a"] = map[string]int
|
||||
assert x["a"]["b"] == 0
|
||||
x["a"]["b"] = 5
|
||||
|
Loading…
Reference in New Issue
Block a user