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
}
if x := strconv.atoi('str') {
println(x)
assert false
} else {
assert true
}
if x := strconv.atoi('') {
println(x)
assert false
} else {
assert true

View File

@ -1,7 +1,5 @@
module atomic2
import sync
/*
Implements the atomic operations. For now TCC does not support
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_int3(chi)
mut sum := i64(0)
mut rl := i64(0)
mut sl := i64(0)
for _ in 0 .. 60000 + recch.cap {
select {

View File

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

View File

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

View File

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

View File

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