tests: fix warnings when doing `./v -W -progress -check-syntax test-fixed`
parent
9772eb7c96
commit
0c192cfd64
|
@ -1,9 +1,9 @@
|
|||
import encoding.utf8 { validate_str }
|
||||
import encoding.utf8
|
||||
|
||||
fn test_validate_str() {
|
||||
assert validate_str('añçá') == true
|
||||
assert validate_str('\x61\xC3\xB1\xC3\xA7\xC3\xA1') == true
|
||||
assert validate_str('\xC0\xC1') == false
|
||||
assert validate_str('\xF5\xFF') == false
|
||||
assert validate_str('\xE0\xEF') == false
|
||||
assert utf8.validate_str('añçá') == true
|
||||
assert utf8.validate_str('\x61\xC3\xB1\xC3\xA7\xC3\xA1') == true
|
||||
assert utf8.validate_str('\xC0\xC1') == false
|
||||
assert utf8.validate_str('\xF5\xFF') == false
|
||||
assert utf8.validate_str('\xE0\xEF') == false
|
||||
}
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
import sync
|
||||
import time
|
||||
|
||||
fn do_rec(mut ch sync.Channel, mut resch sync.Channel) {
|
||||
mut sum := i64(0)
|
||||
for {
|
||||
for {
|
||||
mut a := 0
|
||||
if !ch.pop(&a) {
|
||||
break
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
// Channel Benchmark
|
||||
//
|
||||
// `nobj` integers are sent thru a channel with queue length`buflen`
|
||||
|
@ -5,12 +6,11 @@
|
|||
//
|
||||
// The receive threads add all received numbers and send them to the
|
||||
// main thread where the total sum is compare to the expected value.
|
||||
|
||||
const (
|
||||
nsend = 2
|
||||
nrec = 2
|
||||
buflen = 100
|
||||
nobj = 10000
|
||||
nsend = 2
|
||||
nrec = 2
|
||||
buflen = 100
|
||||
nobj = 10000
|
||||
objs_per_thread = 5000
|
||||
)
|
||||
|
||||
|
@ -18,16 +18,18 @@ fn do_rec(ch chan int, resch chan i64, n int) {
|
|||
mut sum := i64(0)
|
||||
for _ in 0 .. n {
|
||||
mut r := 0
|
||||
for ch.try_pop(r) != .success {}
|
||||
for ch.try_pop(r) != .success {
|
||||
}
|
||||
sum += r
|
||||
}
|
||||
println(sum)
|
||||
resch <- sum
|
||||
}
|
||||
|
||||
fn do_send(ch chan int, start, end int) {
|
||||
fn do_send(ch chan int, start int, end int) {
|
||||
for i in start .. end {
|
||||
for ch.try_push(i) != .success {}
|
||||
for ch.try_push(i) != .success {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -46,8 +48,10 @@ fn test_channel_polling() {
|
|||
mut sum := i64(0)
|
||||
for _ in 0 .. nrec {
|
||||
sum += <-resch
|
||||
println('> running sum: $sum')
|
||||
}
|
||||
// use sum formula by Gauß to calculate the expected result
|
||||
expected_sum := i64(nobj)*(nobj-1)/2
|
||||
expected_sum := i64(nobj) * (nobj - 1) / 2
|
||||
println('expected sum: $expected_sum | sum: $sum')
|
||||
assert sum == expected_sum
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ fn test_is_leap_year() {
|
|||
assert time.is_leap_year(2100) == false
|
||||
}
|
||||
|
||||
fn check_days_in_month(month, year, expected int) bool {
|
||||
fn check_days_in_month(month int, year int, expected int) bool {
|
||||
res := time.days_in_month(month, year) or {
|
||||
return false
|
||||
}
|
||||
|
@ -89,18 +89,21 @@ fn test_format_ss() {
|
|||
}
|
||||
|
||||
fn test_format_ss_milli() {
|
||||
assert '11.07.1980 21:23:42.123' == time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy)
|
||||
assert '11.07.1980 21:23:42.123' ==
|
||||
time_to_test.get_fmt_str(.dot, .hhmmss24_milli, .ddmmyyyy)
|
||||
assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli()
|
||||
}
|
||||
|
||||
fn test_format_ss_micro() {
|
||||
assert '11.07.1980 21:23:42.123456' == time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy)
|
||||
assert '11.07.1980 21:23:42.123456' ==
|
||||
time_to_test.get_fmt_str(.dot, .hhmmss24_micro, .ddmmyyyy)
|
||||
assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro()
|
||||
}
|
||||
|
||||
fn test_smonth() {
|
||||
month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
|
||||
month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
|
||||
'Dec',
|
||||
]
|
||||
for i, name in month_names {
|
||||
month_num := i + 1
|
||||
t := time.Time{
|
||||
|
@ -117,7 +120,7 @@ fn test_smonth() {
|
|||
}
|
||||
|
||||
fn test_day_of_week() {
|
||||
for i in 0..7 {
|
||||
for i in 0 .. 7 {
|
||||
day_of_week := i + 1
|
||||
// 2 Dec 2019 is Monday
|
||||
t := time.Time{
|
||||
|
@ -164,33 +167,30 @@ fn test_str() {
|
|||
// not optimal test but will find obvious bugs
|
||||
fn test_now() {
|
||||
now := time.now()
|
||||
|
||||
// The year the test was built
|
||||
assert now.year >= 2020
|
||||
assert now.month > 0
|
||||
assert now.month <= 12
|
||||
assert now.minute >= 0
|
||||
assert now.minute < 60
|
||||
assert now.second >=0
|
||||
assert now.second <= 60 // <= 60 cause of leap seconds
|
||||
assert now.microsecond >= 0
|
||||
assert now.microsecond < 1000000
|
||||
|
||||
assert now.year >= 2020
|
||||
assert now.month > 0
|
||||
assert now.month <= 12
|
||||
assert now.minute >= 0
|
||||
assert now.minute < 60
|
||||
assert now.second >= 0
|
||||
assert now.second <= 60 // <= 60 cause of leap seconds
|
||||
assert now.microsecond >= 0
|
||||
assert now.microsecond < 1000000
|
||||
}
|
||||
|
||||
fn test_utc() {
|
||||
now := time.utc()
|
||||
|
||||
// The year the test was built
|
||||
assert now.year >= 2020
|
||||
assert now.month > 0
|
||||
assert now.month <= 12
|
||||
assert now.minute >= 0
|
||||
assert now.minute < 60
|
||||
assert now.second >=0
|
||||
assert now.second <= 60 // <= 60 cause of leap seconds
|
||||
assert now.microsecond >= 0
|
||||
assert now.microsecond < 1000000
|
||||
assert now.year >= 2020
|
||||
assert now.month > 0
|
||||
assert now.month <= 12
|
||||
assert now.minute >= 0
|
||||
assert now.minute < 60
|
||||
assert now.second >= 0
|
||||
assert now.second <= 60 // <= 60 cause of leap seconds
|
||||
assert now.microsecond >= 0
|
||||
assert now.microsecond < 1000000
|
||||
}
|
||||
|
||||
fn test_unix_time() {
|
||||
|
@ -203,10 +203,10 @@ fn test_unix_time() {
|
|||
//
|
||||
utm1 := t1.unix_time_milli()
|
||||
utm2 := t2.unix_time_milli()
|
||||
assert (utm1 - u64(ut1)*1000) < 1000
|
||||
assert (utm2 - u64(ut2)*1000) < 1000
|
||||
assert (utm1 - u64(ut1) * 1000) < 1000
|
||||
assert (utm2 - u64(ut2) * 1000) < 1000
|
||||
//
|
||||
//println('utm1: $utm1 | utm2: $utm2')
|
||||
// println('utm1: $utm1 | utm2: $utm2')
|
||||
assert utm2 - utm1 > 2
|
||||
assert utm2 - utm1 < 999
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// import v.table
|
||||
import v.doc
|
||||
import v.parser
|
||||
|
||||
// fn test_generate_with_pos() {}
|
||||
// fn test_generate() {}
|
||||
|
|
|
@ -2,55 +2,47 @@ fn test_fixed_array_lit_init() {
|
|||
a1 := ['1', '2', '3']!!
|
||||
assert typeof(a1) == '[3]string'
|
||||
assert '$a1' == "['1', '2', '3']"
|
||||
|
||||
a2 := ['a', 'b']!!
|
||||
assert typeof(a2) == '[2]string'
|
||||
assert '$a2' == "['a', 'b']"
|
||||
|
||||
c1 := [1, 2, 3]!!
|
||||
assert typeof(c1) == '[3]int'
|
||||
assert '$c1' == '[1, 2, 3]'
|
||||
|
||||
c2 := [i16(1), 2, 3]!!
|
||||
assert typeof(c2) == '[3]i16'
|
||||
assert '$c2' == '[1, 2, 3]'
|
||||
|
||||
mut c3 := [i64(1), 2, 3]!!
|
||||
assert typeof(c3) == '[3]i64'
|
||||
assert '$c3' == '[1, 2, 3]'
|
||||
|
||||
mut c4 := [u64(1), 2, 3]!!
|
||||
assert typeof(c4) == '[3]u64'
|
||||
assert '$c4' == '[1, 2, 3]'
|
||||
|
||||
mut d1 := [1.1, 2.2, 3.3]!!
|
||||
assert typeof(d1) == '[3]f64'
|
||||
assert '$d1' == '[1.1, 2.2, 3.3]'
|
||||
|
||||
mut d2 := [f32(1.1), 2.2, 3.3]!!
|
||||
assert typeof(d2) == '[3]f32'
|
||||
assert '$d2' == '[1.1, 2.2, 3.3]'
|
||||
}
|
||||
|
||||
fn test_fixed_type_init() {
|
||||
a := [2]int
|
||||
assert a == [2]int
|
||||
assert a == [0,0]!!
|
||||
a := [2]int{}
|
||||
assert a == [2]int{}
|
||||
assert a == [0, 0]!!
|
||||
assert a == a
|
||||
mut c := [3,3]!!
|
||||
mut c := [3, 3]!!
|
||||
assert a != c
|
||||
assert c == [3,3]!!
|
||||
c = [2]int
|
||||
assert c == [3, 3]!!
|
||||
c = [2]int{}
|
||||
assert a == c
|
||||
}
|
||||
|
||||
fn test_fixed_custom_init() {
|
||||
a := [2]byte{init: 7}
|
||||
assert a == [byte(7), 7]!!
|
||||
|
||||
mut b := [3]int{}
|
||||
assert b == [0,0,0]!!
|
||||
assert b == [0, 0, 0]!!
|
||||
// assign
|
||||
b = [3]int{init:5}
|
||||
assert b == [5,5,5]!!
|
||||
b = [3]int{init: 5}
|
||||
assert b == [5, 5, 5]!!
|
||||
}
|
||||
|
|
|
@ -1,46 +1,39 @@
|
|||
fn test_fixed_array_to_string() {
|
||||
mut a1 := [3]string
|
||||
mut a1 := [3]string{}
|
||||
a1[0] = '1'
|
||||
a1[1] = '2'
|
||||
a1[2] = '3'
|
||||
assert '$a1' == "['1', '2', '3']"
|
||||
|
||||
mut a2 := [2]string
|
||||
mut a2 := [2]string{}
|
||||
a2[0] = 'a'
|
||||
a2[1] = 'b'
|
||||
assert '$a2' == "['a', 'b']"
|
||||
|
||||
mut c1 := [3]int
|
||||
mut c1 := [3]int{}
|
||||
c1[0] = 1
|
||||
c1[1] = 2
|
||||
c1[2] = 3
|
||||
assert '$c1' == '[1, 2, 3]'
|
||||
|
||||
mut c2 := [3]i16
|
||||
mut c2 := [3]i16{}
|
||||
c2[0] = 1
|
||||
c2[1] = 2
|
||||
c2[2] = 3
|
||||
assert '$c2' == '[1, 2, 3]'
|
||||
|
||||
mut c3 := [3]i64
|
||||
mut c3 := [3]i64{}
|
||||
c3[0] = 1
|
||||
c3[1] = 2
|
||||
c3[2] = 3
|
||||
assert '$c3' == '[1, 2, 3]'
|
||||
|
||||
mut c4 := [3]u64
|
||||
mut c4 := [3]u64{}
|
||||
c4[0] = 1
|
||||
c4[1] = 2
|
||||
c4[2] = 3
|
||||
assert '$c4' == '[1, 2, 3]'
|
||||
|
||||
mut d1 := [3]f64
|
||||
mut d1 := [3]f64{}
|
||||
d1[0] = 1.1
|
||||
d1[1] = 2.2
|
||||
d1[2] = 3.3
|
||||
assert '$d1' == '[1.1, 2.2, 3.3]'
|
||||
|
||||
mut d2 := [3]f32
|
||||
mut d2 := [3]f32{}
|
||||
d2[0] = 1.1
|
||||
d2[1] = 2.2
|
||||
d2[2] = 3.3
|
||||
|
|
|
@ -26,7 +26,7 @@ fn myfn4(string)
|
|||
|
||||
fn foobar()
|
||||
|
||||
fn slopediv(num, den u32) int
|
||||
fn slopediv(num u32, den u32) int
|
||||
|
||||
type F1 = fn ()
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ fn test_explicit_calls_should_also_work() {
|
|||
}
|
||||
|
||||
//
|
||||
fn choose4<T>(a, b, c, d T) T {
|
||||
fn choose4<T>(a T, b T, c T, d T) T {
|
||||
// NB: a similar construct is used in prime31's via engine
|
||||
return a
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ fn simple<T>(p T) T {
|
|||
return p
|
||||
}
|
||||
|
||||
fn plus<T>(xxx, b T) T {
|
||||
fn plus<T>(xxx T, b T) T {
|
||||
// x := a
|
||||
// y := b
|
||||
// ww := ww
|
||||
|
|
|
@ -1,59 +1,59 @@
|
|||
fn foo(a, b string) int {
|
||||
return 10 + a.len + b.len
|
||||
}
|
||||
|
||||
fn foo2(a, b string) int {
|
||||
return 20 + a.len + b.len
|
||||
}
|
||||
|
||||
fn test_array_with_fns() {
|
||||
mut a := [foo, foo2]
|
||||
assert a.len == 2
|
||||
assert (a != [foo, foo2]) == false
|
||||
assert (foo in a) == true
|
||||
f0 := a[0]
|
||||
assert f0('xx', '') == 12
|
||||
f1 := a[1]
|
||||
assert f1('yyy', '') == 23
|
||||
a[0], a[1] = a[1], a[0]
|
||||
f2 := a[0]
|
||||
assert f2('zzzz', '') == 24
|
||||
f3 := a[1]
|
||||
assert f3('aaaaa', '') == 15
|
||||
mut b := [foo]
|
||||
assert (foo2 !in b) == true
|
||||
b[0] = a[0]
|
||||
f4 := b[0]
|
||||
assert f4('bbbbbb', '') == 26
|
||||
for func in b {
|
||||
assert func('ccccccc', '') == 27
|
||||
}
|
||||
b = []
|
||||
b << foo
|
||||
b << [foo2]
|
||||
assert (b == [foo, foo2]) == true
|
||||
f5 := b[0]
|
||||
assert f5('dddddddd', '') == 18
|
||||
}
|
||||
|
||||
fn test_map_with_fns() {
|
||||
mut a := {'one':foo, 'two':foo2}
|
||||
assert a.len == 2
|
||||
assert (a == {'one':foo, 'two':foo2}) == true
|
||||
f0 := a['one']
|
||||
assert f0('xx', '') == 12
|
||||
f1 := a['two']
|
||||
assert f1('yyy', '') == 23
|
||||
a['one'], a['two'] = a['two'], a['one']
|
||||
f2 := a['one']
|
||||
assert f2('zzzz', '') == 24
|
||||
f3 := a['two']
|
||||
assert f3('aaaaa', '') == 15
|
||||
mut b := {'one':foo}
|
||||
b['one'] = a['one']
|
||||
f4 := b['one']
|
||||
assert f4('bbbbbb', '') == 26
|
||||
for _, func in b {
|
||||
assert func('ccccccc', '') == 27
|
||||
}
|
||||
}
|
||||
fn foo(a string, b string) int {
|
||||
return 10 + a.len + b.len
|
||||
}
|
||||
|
||||
fn foo2(a string, b string) int {
|
||||
return 20 + a.len + b.len
|
||||
}
|
||||
|
||||
fn test_array_with_fns() {
|
||||
mut a := [foo, foo2]
|
||||
assert a.len == 2
|
||||
assert (a != [foo, foo2]) == false
|
||||
assert (foo in a) == true
|
||||
f0 := a[0]
|
||||
assert f0('xx', '') == 12
|
||||
f1 := a[1]
|
||||
assert f1('yyy', '') == 23
|
||||
a[0], a[1] = a[1], a[0]
|
||||
f2 := a[0]
|
||||
assert f2('zzzz', '') == 24
|
||||
f3 := a[1]
|
||||
assert f3('aaaaa', '') == 15
|
||||
mut b := [foo]
|
||||
assert (foo2 !in b) == true
|
||||
b[0] = a[0]
|
||||
f4 := b[0]
|
||||
assert f4('bbbbbb', '') == 26
|
||||
for func in b {
|
||||
assert func('ccccccc', '') == 27
|
||||
}
|
||||
b = []
|
||||
b << foo
|
||||
b << [foo2]
|
||||
assert (b == [foo, foo2]) == true
|
||||
f5 := b[0]
|
||||
assert f5('dddddddd', '') == 18
|
||||
}
|
||||
|
||||
fn test_map_with_fns() {
|
||||
mut a := {'one':foo, 'two':foo2}
|
||||
assert a.len == 2
|
||||
assert (a == {'one':foo, 'two':foo2}) == true
|
||||
f0 := a['one']
|
||||
assert f0('xx', '') == 12
|
||||
f1 := a['two']
|
||||
assert f1('yyy', '') == 23
|
||||
a['one'], a['two'] = a['two'], a['one']
|
||||
f2 := a['one']
|
||||
assert f2('zzzz', '') == 24
|
||||
f3 := a['two']
|
||||
assert f3('aaaaa', '') == 15
|
||||
mut b := {'one':foo}
|
||||
b['one'] = a['one']
|
||||
f4 := b['one']
|
||||
assert f4('bbbbbb', '') == 26
|
||||
for _, func in b {
|
||||
assert func('ccccccc', '') == 27
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
module amodule
|
||||
|
||||
pub fn iadd(x, y int) int {
|
||||
pub fn iadd(x int, y int) int {
|
||||
return x + y
|
||||
}
|
||||
|
||||
pub fn imul(x, y int) int {
|
||||
pub fn imul(x int, y int) int {
|
||||
return x * y
|
||||
}
|
||||
|
||||
// /////////////////////////////////////
|
||||
fn private_isub(x, y int) int {
|
||||
fn private_isub(x int, y int) int {
|
||||
return x - y
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
fn iadd(x, y int) int {
|
||||
fn iadd(x int, y int) int {
|
||||
return x + y
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// verify fix for #2913
|
||||
fn some_multiret_fn(a, b int) (int, int) {
|
||||
fn some_multiret_fn(a int, b int) (int, int) {
|
||||
return a + 1, b + 1
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
// verify fix for #2913
|
||||
fn some_multiret_fn(a, b int) (int, int) {
|
||||
fn some_multiret_fn(a int, b int) (int, int) {
|
||||
return a + 1, b + 1
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import sync
|
||||
|
||||
const (
|
||||
signals_per_thread = 100_000
|
||||
signals_per_thread = 100000
|
||||
)
|
||||
|
||||
fn send_signals(sem, sem_end sync.Semaphore) {
|
||||
fn send_signals(sem sync.Semaphore, sem_end sync.Semaphore) {
|
||||
for _ in 0 .. signals_per_thread {
|
||||
sem.post()
|
||||
}
|
||||
|
|
|
@ -3,37 +3,37 @@ const (
|
|||
)
|
||||
|
||||
fn test_hardcoded_static_arr() {
|
||||
myints := [10]int
|
||||
myints := [10]int{}
|
||||
size := sizeof(myints)
|
||||
assert size == 40
|
||||
}
|
||||
|
||||
fn test_const_based_static_arr() {
|
||||
myints := [sbuffer_size]int
|
||||
myints := [sbuffer_size]int{}
|
||||
size := sizeof(myints)
|
||||
assert size == 40
|
||||
}
|
||||
|
||||
fn test_const_based_static_arr_of_f64() {
|
||||
myf64 := [sbuffer_size]f64
|
||||
myf64 := [sbuffer_size]f64{}
|
||||
size := sizeof(myf64)
|
||||
assert size == 80
|
||||
}
|
||||
|
||||
fn test_const_based_static_arr_of_f32() {
|
||||
myf32 := [sbuffer_size]f32
|
||||
myf32 := [sbuffer_size]f32{}
|
||||
size := sizeof(myf32)
|
||||
assert size == 40
|
||||
}
|
||||
|
||||
fn test_const_based_static_arr_of_i8() {
|
||||
myi8 := [sbuffer_size]i8
|
||||
myi8 := [sbuffer_size]i8{}
|
||||
size := sizeof(myi8)
|
||||
assert size == 10
|
||||
}
|
||||
|
||||
fn test_const_based_static_arr_of_i16() {
|
||||
myi16 := [sbuffer_size]i16
|
||||
myi16 := [sbuffer_size]i16{}
|
||||
size := sizeof(myi16)
|
||||
assert size == 20
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue