1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

tests: fix some warnings in preparation for -W test-self

This commit is contained in:
Delyan Angelov 2021-01-31 11:05:17 +02:00
parent 89bf48e3ba
commit 978359a6fc
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
7 changed files with 72 additions and 45 deletions

View File

@ -17,11 +17,13 @@ fn test_atoi() {
assert false assert false
} }
if x := strconv.atoi('str') { if x := strconv.atoi('str') {
println(x)
assert false assert false
} else { } else {
assert true assert true
} }
if x := strconv.atoi('') { if x := strconv.atoi('') {
println(x)
assert false assert false
} else { } else {
assert true assert true

View File

@ -1,7 +1,5 @@
module atomic2 module atomic2
import sync
/* /*
Implements the atomic operations. For now TCC does not support Implements the atomic operations. For now TCC does not support
the atomic versions on nix so it uses locks to simulate the same behavor. the atomic versions on nix so it uses locks to simulate the same behavor.

View File

@ -35,7 +35,6 @@ fn test_select() {
go do_send_int2(chi) go do_send_int2(chi)
go do_send_int3(chi) go do_send_int3(chi)
mut sum := i64(0) mut sum := i64(0)
mut rl := i64(0)
mut sl := i64(0) mut sl := i64(0)
for _ in 0 .. 60000 + recch.cap { for _ in 0 .. 60000 + recch.cap {
select { select {

View File

@ -1,16 +1,30 @@
struct DB {
name string
}
struct DB { name string } struct DxB {
struct DxB { name string } name string
struct DeclExprA { name string } }
struct AStructWithAVeryLongName { name string }
struct DeclExprA {
name string
}
struct AStructWithAVeryLongName {
name string
}
fn test_struct_names_can_be_used_for_creating_them() { fn test_struct_names_can_be_used_for_creating_them() {
a := DB{} a := DB{}
println(a)
assert true assert true
b := DxB{} b := DxB{}
println(b)
assert true assert true
c := DeclExprA{} c := DeclExprA{}
println(c)
assert true assert true
d := AStructWithAVeryLongName{} d := AStructWithAVeryLongName{}
println(d)
assert true assert true
} }

View File

@ -11,19 +11,20 @@ pub fn (c Color) str() string {
fn test_match_integers() { fn test_match_integers() {
mut a := 3 mut a := 3
mut b := 0 mut b := 0
match a match a {
2 { 2 {
println('two') println('two')
} }
3 { 3 {
println('three') println('three')
b = 3 b = 3
} }
4 { 4 {
println('four') println('four')
} }
else { else {
println('???') println('???')
}
} }
assert b == 3 assert b == 3
assert match 2 { assert match 2 {
@ -37,6 +38,7 @@ fn test_match_integers() {
else { 5 } else { 5 }
} == 5 } == 5
assert match 1 { assert match 1 {
2 { 0 }
else { 5 } else { 5 }
} == 5 } == 5
a = 0 a = 0
@ -68,6 +70,7 @@ fn test_match_integers() {
assert a == 6 assert a == 6
a = 0 a = 0
match 1 { match 1 {
0 {}
else { a = -2 } else { a = -2 }
} }
assert a == -2 assert a == -2
@ -225,9 +228,15 @@ fn test_match_sumtype_multiple_types() {
} }
fn test_sub_expression() { fn test_sub_expression() {
b := false && match 1 {0 {true} else {true}} b := false && match 1 {
0 { true }
else { true }
}
assert !b assert !b
c := true || match 1 {0 {false} else {false}} c := true || match 1 {
0 { false }
else { false }
}
assert c assert c
} }
@ -270,6 +279,9 @@ fn test_sumtype_with_array() {
} }
fn test_match_expression_add() { fn test_match_expression_add() {
a := match true { true {1} false {2} } + 3 a := match true {
true { 1 }
false { 2 }
} + 3
assert a == 4 assert a == 4
} }

View File

@ -14,35 +14,35 @@ type MySumType = Abc | Xyz
type AnotherSumType = XxYyZz | int type AnotherSumType = XxYyZz | int
type SuperSumType = MySumType | AnotherSumType | string type SuperSumType = AnotherSumType | MySumType | string
fn test_typeof_for_builtin_int_types() { fn test_typeof_for_builtin_int_types() {
assert typeof(i8(1)) == 'i8' assert typeof(i8(1)).name == 'i8'
assert typeof(i16(1)) == 'i16' assert typeof(i16(1)).name == 'i16'
assert typeof(int(1)) == 'int' assert typeof(int(1)).name == 'int'
// assert typeof(1) == 'int_literal' // assert typeof(1).name == 'int_literal'
assert typeof(i64(1)) == 'i64' assert typeof(i64(1)).name == 'i64'
assert typeof(byte(1)) == 'byte' assert typeof(byte(1)).name == 'byte'
assert typeof(u16(1)) == 'u16' assert typeof(u16(1)).name == 'u16'
assert typeof(u32(1)) == 'u32' assert typeof(u32(1)).name == 'u32'
assert typeof(u64(1)) == 'u64' assert typeof(u64(1)).name == 'u64'
} }
fn test_typeof_for_builtin_float_types() { fn test_typeof_for_builtin_float_types() {
assert typeof(f32(1.0)) == 'f32' assert typeof(f32(1.0)).name == 'f32'
assert typeof(f64(1.0)) == 'f64' assert typeof(f64(1.0)).name == 'f64'
// assert typeof(1.0) == 'float_literal' // assert typeof(1.0).name == 'float_literal'
} }
fn test_typeof_for_builtin_string_type() { fn test_typeof_for_builtin_string_type() {
assert typeof('abc') == 'string' assert typeof('abc').name == 'string'
assert typeof('/v/nv/vlib/v/tests/typeof_simple_types_test.v') == 'string' assert typeof('/v/nv/vlib/v/tests/typeof_simple_types_test.v').name == 'string'
assert typeof('22') == 'string' assert typeof('22').name == 'string'
} }
fn test_typeof_for_structs() { fn test_typeof_for_structs() {
assert typeof(Abc{}) == 'Abc' assert typeof(Abc{}).name == 'Abc'
assert typeof(Xyz{}) == 'Xyz' assert typeof(Xyz{}).name == 'Xyz'
} }
// //

View File

@ -86,7 +86,7 @@ fn test_character_unescape() {
assert lines['newline'].str() == 'new\nline' assert lines['newline'].str() == 'new\nline'
assert lines['tab'].str() == '\ttab' assert lines['tab'].str() == '\ttab'
assert lines['backslash'].str() == 'back\\slash' assert lines['backslash'].str() == 'back\\slash'
assert lines['quotes'].str() == '\"quotes\"' assert lines['quotes'].str() == '"quotes"'
assert lines['slash'].str() == '/dev/null' assert lines['slash'].str() == '/dev/null'
} }
@ -169,6 +169,7 @@ fn test_parse_user() {
assert false assert false
User2{} User2{}
} }
println(u2)
u := json2.decode<User>(s) or { u := json2.decode<User>(s) or {
assert false assert false
User{} User{}
@ -249,14 +250,15 @@ fn test_struct_in_struct() {
fn test_encode_map() { fn test_encode_map() {
expected := '{"one":1,"two":2,"three":3,"four":4}' expected := '{"one":1,"two":2,"three":3,"four":4}'
numbers := { numbers := {
'one': json2.Any(1) 'one': json2.Any(1)
'two': json2.Any(2) 'two': json2.Any(2)
'three': json2.Any(3) 'three': json2.Any(3)
'four': json2.Any(4) 'four': json2.Any(4)
} }
out := numbers.str() out := numbers.str()
assert out == expected assert out == expected
} }
/* /*
fn test_parse_map() { fn test_parse_map() {
expected := { expected := {