tests: fix warnings when doing `./v -W -progress -check-syntax test-fixed`

pull/6688/head
Delyan Angelov 2020-10-26 14:41:57 +02:00
parent 9772eb7c96
commit 0c192cfd64
17 changed files with 143 additions and 156 deletions

View File

@ -1,9 +1,9 @@
import encoding.utf8 { validate_str } import encoding.utf8
fn test_validate_str() { fn test_validate_str() {
assert validate_str('añçá') == true assert utf8.validate_str('añçá') == true
assert validate_str('\x61\xC3\xB1\xC3\xA7\xC3\xA1') == true assert utf8.validate_str('\x61\xC3\xB1\xC3\xA7\xC3\xA1') == true
assert validate_str('\xC0\xC1') == false assert utf8.validate_str('\xC0\xC1') == false
assert validate_str('\xF5\xFF') == false assert utf8.validate_str('\xF5\xFF') == false
assert validate_str('\xE0\xEF') == false assert utf8.validate_str('\xE0\xEF') == false
} }

View File

@ -1,5 +1,4 @@
import sync import sync
import time
fn do_rec(mut ch sync.Channel, mut resch sync.Channel) { fn do_rec(mut ch sync.Channel, mut resch sync.Channel) {
mut sum := i64(0) mut sum := i64(0)

14
vlib/sync/channel_polling_test.v 100755 → 100644
View File

@ -1,3 +1,4 @@
// Channel Benchmark // Channel Benchmark
// //
// `nobj` integers are sent thru a channel with queue length`buflen` // `nobj` integers are sent thru a channel with queue length`buflen`
@ -5,7 +6,6 @@
// //
// The receive threads add all received numbers and send them to the // The receive threads add all received numbers and send them to the
// main thread where the total sum is compare to the expected value. // main thread where the total sum is compare to the expected value.
const ( const (
nsend = 2 nsend = 2
nrec = 2 nrec = 2
@ -18,16 +18,18 @@ fn do_rec(ch chan int, resch chan i64, n int) {
mut sum := i64(0) mut sum := i64(0)
for _ in 0 .. n { for _ in 0 .. n {
mut r := 0 mut r := 0
for ch.try_pop(r) != .success {} for ch.try_pop(r) != .success {
}
sum += r sum += r
} }
println(sum) println(sum)
resch <- 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 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) mut sum := i64(0)
for _ in 0 .. nrec { for _ in 0 .. nrec {
sum += <-resch sum += <-resch
println('> running sum: $sum')
} }
// use sum formula by Gauß to calculate the expected result // 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 assert sum == expected_sum
} }

View File

@ -24,7 +24,7 @@ fn test_is_leap_year() {
assert time.is_leap_year(2100) == false 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 { res := time.days_in_month(month, year) or {
return false return false
} }
@ -89,18 +89,21 @@ fn test_format_ss() {
} }
fn test_format_ss_milli() { 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() assert '1980-07-11 21:23:42.123' == time_to_test.format_ss_milli()
} }
fn test_format_ss_micro() { 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() assert '1980-07-11 21:23:42.123456' == time_to_test.format_ss_micro()
} }
fn test_smonth() { fn test_smonth() {
month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', month_names := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] 'Dec',
]
for i, name in month_names { for i, name in month_names {
month_num := i + 1 month_num := i + 1
t := time.Time{ t := time.Time{
@ -117,7 +120,7 @@ fn test_smonth() {
} }
fn test_day_of_week() { fn test_day_of_week() {
for i in 0..7 { for i in 0 .. 7 {
day_of_week := i + 1 day_of_week := i + 1
// 2 Dec 2019 is Monday // 2 Dec 2019 is Monday
t := time.Time{ t := time.Time{
@ -164,30 +167,27 @@ fn test_str() {
// not optimal test but will find obvious bugs // not optimal test but will find obvious bugs
fn test_now() { fn test_now() {
now := time.now() now := time.now()
// The year the test was built // The year the test was built
assert now.year >= 2020 assert now.year >= 2020
assert now.month > 0 assert now.month > 0
assert now.month <= 12 assert now.month <= 12
assert now.minute >= 0 assert now.minute >= 0
assert now.minute < 60 assert now.minute < 60
assert now.second >=0 assert now.second >= 0
assert now.second <= 60 // <= 60 cause of leap seconds assert now.second <= 60 // <= 60 cause of leap seconds
assert now.microsecond >= 0 assert now.microsecond >= 0
assert now.microsecond < 1000000 assert now.microsecond < 1000000
} }
fn test_utc() { fn test_utc() {
now := time.utc() now := time.utc()
// The year the test was built // The year the test was built
assert now.year >= 2020 assert now.year >= 2020
assert now.month > 0 assert now.month > 0
assert now.month <= 12 assert now.month <= 12
assert now.minute >= 0 assert now.minute >= 0
assert now.minute < 60 assert now.minute < 60
assert now.second >=0 assert now.second >= 0
assert now.second <= 60 // <= 60 cause of leap seconds assert now.second <= 60 // <= 60 cause of leap seconds
assert now.microsecond >= 0 assert now.microsecond >= 0
assert now.microsecond < 1000000 assert now.microsecond < 1000000
@ -203,10 +203,10 @@ fn test_unix_time() {
// //
utm1 := t1.unix_time_milli() utm1 := t1.unix_time_milli()
utm2 := t2.unix_time_milli() utm2 := t2.unix_time_milli()
assert (utm1 - u64(ut1)*1000) < 1000 assert (utm1 - u64(ut1) * 1000) < 1000
assert (utm2 - u64(ut2)*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 > 2
assert utm2 - utm1 < 999 assert utm2 - utm1 < 999
} }

View File

@ -1,6 +1,5 @@
// import v.table // import v.table
import v.doc import v.doc
import v.parser
// fn test_generate_with_pos() {} // fn test_generate_with_pos() {}
// fn test_generate() {} // fn test_generate() {}

View File

@ -2,55 +2,47 @@ fn test_fixed_array_lit_init() {
a1 := ['1', '2', '3']!! a1 := ['1', '2', '3']!!
assert typeof(a1) == '[3]string' assert typeof(a1) == '[3]string'
assert '$a1' == "['1', '2', '3']" assert '$a1' == "['1', '2', '3']"
a2 := ['a', 'b']!! a2 := ['a', 'b']!!
assert typeof(a2) == '[2]string' assert typeof(a2) == '[2]string'
assert '$a2' == "['a', 'b']" assert '$a2' == "['a', 'b']"
c1 := [1, 2, 3]!! c1 := [1, 2, 3]!!
assert typeof(c1) == '[3]int' assert typeof(c1) == '[3]int'
assert '$c1' == '[1, 2, 3]' assert '$c1' == '[1, 2, 3]'
c2 := [i16(1), 2, 3]!! c2 := [i16(1), 2, 3]!!
assert typeof(c2) == '[3]i16' assert typeof(c2) == '[3]i16'
assert '$c2' == '[1, 2, 3]' assert '$c2' == '[1, 2, 3]'
mut c3 := [i64(1), 2, 3]!! mut c3 := [i64(1), 2, 3]!!
assert typeof(c3) == '[3]i64' assert typeof(c3) == '[3]i64'
assert '$c3' == '[1, 2, 3]' assert '$c3' == '[1, 2, 3]'
mut c4 := [u64(1), 2, 3]!! mut c4 := [u64(1), 2, 3]!!
assert typeof(c4) == '[3]u64' assert typeof(c4) == '[3]u64'
assert '$c4' == '[1, 2, 3]' assert '$c4' == '[1, 2, 3]'
mut d1 := [1.1, 2.2, 3.3]!! mut d1 := [1.1, 2.2, 3.3]!!
assert typeof(d1) == '[3]f64' assert typeof(d1) == '[3]f64'
assert '$d1' == '[1.1, 2.2, 3.3]' assert '$d1' == '[1.1, 2.2, 3.3]'
mut d2 := [f32(1.1), 2.2, 3.3]!! mut d2 := [f32(1.1), 2.2, 3.3]!!
assert typeof(d2) == '[3]f32' assert typeof(d2) == '[3]f32'
assert '$d2' == '[1.1, 2.2, 3.3]' assert '$d2' == '[1.1, 2.2, 3.3]'
} }
fn test_fixed_type_init() { fn test_fixed_type_init() {
a := [2]int a := [2]int{}
assert a == [2]int assert a == [2]int{}
assert a == [0,0]!! assert a == [0, 0]!!
assert a == a assert a == a
mut c := [3,3]!! mut c := [3, 3]!!
assert a != c assert a != c
assert c == [3,3]!! assert c == [3, 3]!!
c = [2]int c = [2]int{}
assert a == c assert a == c
} }
fn test_fixed_custom_init() { fn test_fixed_custom_init() {
a := [2]byte{init: 7} a := [2]byte{init: 7}
assert a == [byte(7), 7]!! assert a == [byte(7), 7]!!
mut b := [3]int{} mut b := [3]int{}
assert b == [0,0,0]!! assert b == [0, 0, 0]!!
// assign // assign
b = [3]int{init:5} b = [3]int{init: 5}
assert b == [5,5,5]!! assert b == [5, 5, 5]!!
} }

View File

@ -1,46 +1,39 @@
fn test_fixed_array_to_string() { fn test_fixed_array_to_string() {
mut a1 := [3]string mut a1 := [3]string{}
a1[0] = '1' a1[0] = '1'
a1[1] = '2' a1[1] = '2'
a1[2] = '3' a1[2] = '3'
assert '$a1' == "['1', '2', '3']" assert '$a1' == "['1', '2', '3']"
mut a2 := [2]string{}
mut a2 := [2]string
a2[0] = 'a' a2[0] = 'a'
a2[1] = 'b' a2[1] = 'b'
assert '$a2' == "['a', 'b']" assert '$a2' == "['a', 'b']"
mut c1 := [3]int{}
mut c1 := [3]int
c1[0] = 1 c1[0] = 1
c1[1] = 2 c1[1] = 2
c1[2] = 3 c1[2] = 3
assert '$c1' == '[1, 2, 3]' assert '$c1' == '[1, 2, 3]'
mut c2 := [3]i16{}
mut c2 := [3]i16
c2[0] = 1 c2[0] = 1
c2[1] = 2 c2[1] = 2
c2[2] = 3 c2[2] = 3
assert '$c2' == '[1, 2, 3]' assert '$c2' == '[1, 2, 3]'
mut c3 := [3]i64{}
mut c3 := [3]i64
c3[0] = 1 c3[0] = 1
c3[1] = 2 c3[1] = 2
c3[2] = 3 c3[2] = 3
assert '$c3' == '[1, 2, 3]' assert '$c3' == '[1, 2, 3]'
mut c4 := [3]u64{}
mut c4 := [3]u64
c4[0] = 1 c4[0] = 1
c4[1] = 2 c4[1] = 2
c4[2] = 3 c4[2] = 3
assert '$c4' == '[1, 2, 3]' assert '$c4' == '[1, 2, 3]'
mut d1 := [3]f64{}
mut d1 := [3]f64
d1[0] = 1.1 d1[0] = 1.1
d1[1] = 2.2 d1[1] = 2.2
d1[2] = 3.3 d1[2] = 3.3
assert '$d1' == '[1.1, 2.2, 3.3]' assert '$d1' == '[1.1, 2.2, 3.3]'
mut d2 := [3]f32{}
mut d2 := [3]f32
d2[0] = 1.1 d2[0] = 1.1
d2[1] = 2.2 d2[1] = 2.2
d2[2] = 3.3 d2[2] = 3.3

View File

@ -26,7 +26,7 @@ fn myfn4(string)
fn foobar() fn foobar()
fn slopediv(num, den u32) int fn slopediv(num u32, den u32) int
type F1 = fn () type F1 = fn ()

View File

@ -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 // NB: a similar construct is used in prime31's via engine
return a return a
} }

View File

@ -5,7 +5,7 @@ fn simple<T>(p T) T {
return p return p
} }
fn plus<T>(xxx, b T) T { fn plus<T>(xxx T, b T) T {
// x := a // x := a
// y := b // y := b
// ww := ww // ww := ww

View File

@ -1,8 +1,8 @@
fn foo(a, b string) int { fn foo(a string, b string) int {
return 10 + a.len + b.len return 10 + a.len + b.len
} }
fn foo2(a, b string) int { fn foo2(a string, b string) int {
return 20 + a.len + b.len return 20 + a.len + b.len
} }

View File

@ -1,14 +1,14 @@
module amodule module amodule
pub fn iadd(x, y int) int { pub fn iadd(x int, y int) int {
return x + y return x + y
} }
pub fn imul(x, y int) int { pub fn imul(x int, y int) int {
return x * y return x * y
} }
// ///////////////////////////////////// // /////////////////////////////////////
fn private_isub(x, y int) int { fn private_isub(x int, y int) int {
return x - y return x - y
} }

View File

@ -1,4 +1,4 @@
fn iadd(x, y int) int { fn iadd(x int, y int) int {
return x + y return x + y
} }

View File

@ -1,5 +1,5 @@
// verify fix for #2913 // 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 return a + 1, b + 1
} }

View File

@ -1,5 +1,5 @@
// verify fix for #2913 // 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 return a + 1, b + 1
} }

View File

@ -1,10 +1,10 @@
import sync import sync
const ( 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 { for _ in 0 .. signals_per_thread {
sem.post() sem.post()
} }

View File

@ -3,37 +3,37 @@ const (
) )
fn test_hardcoded_static_arr() { fn test_hardcoded_static_arr() {
myints := [10]int myints := [10]int{}
size := sizeof(myints) size := sizeof(myints)
assert size == 40 assert size == 40
} }
fn test_const_based_static_arr() { fn test_const_based_static_arr() {
myints := [sbuffer_size]int myints := [sbuffer_size]int{}
size := sizeof(myints) size := sizeof(myints)
assert size == 40 assert size == 40
} }
fn test_const_based_static_arr_of_f64() { fn test_const_based_static_arr_of_f64() {
myf64 := [sbuffer_size]f64 myf64 := [sbuffer_size]f64{}
size := sizeof(myf64) size := sizeof(myf64)
assert size == 80 assert size == 80
} }
fn test_const_based_static_arr_of_f32() { fn test_const_based_static_arr_of_f32() {
myf32 := [sbuffer_size]f32 myf32 := [sbuffer_size]f32{}
size := sizeof(myf32) size := sizeof(myf32)
assert size == 40 assert size == 40
} }
fn test_const_based_static_arr_of_i8() { fn test_const_based_static_arr_of_i8() {
myi8 := [sbuffer_size]i8 myi8 := [sbuffer_size]i8{}
size := sizeof(myi8) size := sizeof(myi8)
assert size == 10 assert size == 10
} }
fn test_const_based_static_arr_of_i16() { fn test_const_based_static_arr_of_i16() {
myi16 := [sbuffer_size]i16 myi16 := [sbuffer_size]i16{}
size := sizeof(myi16) size := sizeof(myi16)
assert size == 20 assert size == 20
} }