tests: run vfmt
parent
1abdf2d68f
commit
0a03797694
|
@ -8,13 +8,13 @@ enum Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_array_equality() {
|
fn test_array_equality() {
|
||||||
strs := ["a", "b", "c"]
|
strs := ['a', 'b', 'c']
|
||||||
assert strs == ["a", "b", "c"]
|
assert strs == ['a', 'b', 'c']
|
||||||
assert strs != ["a", "c", "b"]
|
assert strs != ['a', 'c', 'b']
|
||||||
assert strs != ["b", "c", "a"]
|
assert strs != ['b', 'c', 'a']
|
||||||
assert strs != ["b", "a", "c"]
|
assert strs != ['b', 'a', 'c']
|
||||||
assert strs != ["c", "b", "a"]
|
assert strs != ['c', 'b', 'a']
|
||||||
assert strs != ["c", "a", "b"]
|
assert strs != ['c', 'a', 'b']
|
||||||
bools := [true, true, false]
|
bools := [true, true, false]
|
||||||
assert bools == [true, true, false]
|
assert bools == [true, true, false]
|
||||||
assert bools != [true, false, false]
|
assert bools != [true, false, false]
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
fn test_array_to_string_conversion() {
|
fn test_array_to_string_conversion() {
|
||||||
expected := '["1", "2", "3", "4"]'
|
expected := '["1", "2", "3", "4"]'
|
||||||
arr := ['1', '2', '3', '4']
|
arr := ['1', '2', '3', '4']
|
||||||
assert '$arr' == expected
|
assert arr.str() == expected
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
fn test_bitness() {
|
fn test_bitness() {
|
||||||
mut x := 0
|
mut x := 0
|
||||||
$if x32 {
|
$if x32 {
|
||||||
|
|
|
@ -6,10 +6,6 @@ pub const (
|
||||||
e = 9
|
e = 9
|
||||||
)
|
)
|
||||||
|
|
||||||
struct Foo {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test_const() {
|
fn test_const() {
|
||||||
assert a == 1
|
assert a == 1
|
||||||
assert d == 11
|
assert d == 11
|
||||||
|
|
|
@ -18,12 +18,10 @@ fn test_enum_bitfield() {
|
||||||
a.perm.toggle(.execute)
|
a.perm.toggle(.execute)
|
||||||
a.perm.clear(.write)
|
a.perm.clear(.write)
|
||||||
// a.perm.set(.other)
|
// a.perm.set(.other)
|
||||||
|
|
||||||
assert a.perm.has(.read)
|
assert a.perm.has(.read)
|
||||||
assert a.perm.has(.execute)
|
assert a.perm.has(.execute)
|
||||||
assert !a.perm.has(.write)
|
assert !a.perm.has(.write)
|
||||||
assert !a.perm.has(.other)
|
assert !a.perm.has(.other)
|
||||||
|
|
||||||
mut b := BfPermission.read // TODO: this does nothing currenty just sets the type
|
mut b := BfPermission.read // TODO: this does nothing currenty just sets the type
|
||||||
b.set(.write)
|
b.set(.write)
|
||||||
b.set(.other)
|
b.set(.other)
|
||||||
|
|
|
@ -103,9 +103,7 @@ fn test_typed_enum() {
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
fn test_typed_enum() {
|
fn test_typed_enum() {
|
||||||
Expr i = { .obj = 10, .typ = IntExpr_type };
|
Expr i = { .obj = 10, .typ = IntExpr_type };
|
||||||
Expr expr = { .obj = true, .typ = BoolExpr_type };
|
Expr expr = { .obj = true, .typ = BoolExpr_type };
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
fn test_fixed_array_can_be_assigned() {
|
fn test_fixed_array_can_be_assigned() {
|
||||||
x := 2.32
|
x := 2.32
|
||||||
mut v := [8]f64
|
mut v := [8]f64
|
||||||
|
@ -17,6 +16,7 @@ struct Context {
|
||||||
pub mut:
|
pub mut:
|
||||||
vb [8]f64
|
vb [8]f64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fixed_array_can_be_assigned_to_a_struct_field() {
|
fn test_fixed_array_can_be_assigned_to_a_struct_field() {
|
||||||
mut ctx := Context{}
|
mut ctx := Context{}
|
||||||
x := 2.32
|
x := 2.32
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
struct Foo {
|
struct Foo {
|
||||||
x int
|
x int
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (f Foo) str() string { return 'Foo{}' }
|
pub fn (f Foo) str() string { return 'Foo{}' }
|
||||||
|
|
||||||
fn process_foo(foo &Foo) {
|
fn process_foo(foo &Foo) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import time.misc as tmisc
|
import time.misc as tmisc
|
||||||
|
|
||||||
// using a manual temporary intermediate variable should always work:
|
// using a manual temporary intermediate variable should always work:
|
||||||
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_manual() {
|
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_manual() {
|
||||||
t1 := tmisc.random()
|
t1 := tmisc.random()
|
||||||
|
|
|
@ -124,7 +124,6 @@ fn test_fns() {
|
||||||
high_fn(sqr)
|
high_fn(sqr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn test_anon_fn() {
|
fn test_anon_fn() {
|
||||||
/*
|
/*
|
||||||
high_fn(fn (x int) int {
|
high_fn(fn (x int) int {
|
||||||
|
@ -147,6 +146,7 @@ type MyFn fn (int) int
|
||||||
fn test(n int) int {
|
fn test(n int) int {
|
||||||
return n + 1000
|
return n + 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MySt {
|
struct MySt {
|
||||||
f MyFn
|
f MyFn
|
||||||
}
|
}
|
||||||
|
@ -161,6 +161,3 @@ fn test_fn_type_call() {
|
||||||
st1 := &MySt{f:test}
|
st1 := &MySt{f:test}
|
||||||
assert st1.f(10) == 1010
|
assert st1.f(10) == 1010
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ fn test_fn_variadic_generic() {
|
||||||
assert variadic_test_generic(111, 'hello', 'v') == '111 hello v'
|
assert variadic_test_generic(111, 'hello', 'v') == '111 hello v'
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// forwarding
|
// forwarding
|
||||||
fn variadic_forward_a(a ...string) string {
|
fn variadic_forward_a(a ...string) string {
|
||||||
return variadic_forward_b(a)
|
return variadic_forward_b(a)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
fn test_if_expression_precedence_false_condition() {
|
fn test_if_expression_precedence_false_condition() {
|
||||||
b := 10
|
b := 10
|
||||||
c := 20
|
c := 20
|
||||||
|
|
|
@ -15,23 +15,22 @@ fn test_in_expression(){
|
||||||
assert a == true
|
assert a == true
|
||||||
a = false && 0 in arr3
|
a = false && 0 in arr3
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && 0 in arr1
|
a = true && 0 in arr1
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && 3 in arr1
|
a = true && 3 in arr1
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && !(2 in arr2)
|
a = true && !(2 in arr2)
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && !(3 in arr2)
|
a = true && !(3 in arr2)
|
||||||
assert a == true
|
assert a == true
|
||||||
|
|
||||||
a = 1 in arr1 && true
|
a = 1 in arr1 && true
|
||||||
assert a == true
|
assert a == true
|
||||||
a = 1 in arr1 && false
|
a = 1 in arr1 && false
|
||||||
assert a == false
|
assert a == false
|
||||||
}
|
}
|
||||||
/* not implemented
|
|
||||||
|
/*
|
||||||
|
not implemented
|
||||||
fn test_in_expression_with_enum() {
|
fn test_in_expression_with_enum() {
|
||||||
mut a := false
|
mut a := false
|
||||||
arr1 := [Colors.green, .blue]
|
arr1 := [Colors.green, .blue]
|
||||||
|
@ -75,17 +74,14 @@ fn test_in_expression_with_string(){
|
||||||
assert a == true
|
assert a == true
|
||||||
a = false && '' in arr3
|
a = false && '' in arr3
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && '' in arr1
|
a = true && '' in arr1
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && 'abc' in arr1
|
a = true && 'abc' in arr1
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && !('bc' in arr2)
|
a = true && !('bc' in arr2)
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && !('abc' in arr2)
|
a = true && !('abc' in arr2)
|
||||||
assert a == true
|
assert a == true
|
||||||
|
|
||||||
a = 'ab' in arr1 && true
|
a = 'ab' in arr1 && true
|
||||||
assert a == true
|
assert a == true
|
||||||
a = 'ab' in arr1 && false
|
a = 'ab' in arr1 && false
|
||||||
|
@ -102,17 +98,14 @@ fn test_optimized_in_expression(){
|
||||||
assert a == true
|
assert a == true
|
||||||
a = false && 0 in [1, 0]
|
a = false && 0 in [1, 0]
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && 0 in [1, 2]
|
a = true && 0 in [1, 2]
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && 3 in [1, 2]
|
a = true && 3 in [1, 2]
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && !(2 in [0, 2])
|
a = true && !(2 in [0, 2])
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && !(3 in [0, 2])
|
a = true && !(3 in [0, 2])
|
||||||
assert a == true
|
assert a == true
|
||||||
|
|
||||||
a = 1 in [1, 2] && true
|
a = 1 in [1, 2] && true
|
||||||
assert a == true
|
assert a == true
|
||||||
a = 1 in [1, 2] && false
|
a = 1 in [1, 2] && false
|
||||||
|
@ -129,17 +122,14 @@ fn test_optimized_in_expression_with_enum(){
|
||||||
assert a == true
|
assert a == true
|
||||||
a = false && Colors.red in [.green, .red]
|
a = false && Colors.red in [.green, .red]
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && Colors.red in [.green, .blue]
|
a = true && Colors.red in [.green, .blue]
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && Colors.yellow in [.green, .blue]
|
a = true && Colors.yellow in [.green, .blue]
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && !(Colors.blue in [.red, .blue])
|
a = true && !(Colors.blue in [.red, .blue])
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && !(Colors.yellow in [.red, .blue])
|
a = true && !(Colors.yellow in [.red, .blue])
|
||||||
assert a == true
|
assert a == true
|
||||||
|
|
||||||
a = Colors.green in [.green, .blue] && true
|
a = Colors.green in [.green, .blue] && true
|
||||||
assert a == true
|
assert a == true
|
||||||
a = Colors.green in [.green, .blue] && false
|
a = Colors.green in [.green, .blue] && false
|
||||||
|
@ -156,17 +146,14 @@ fn test_optimized_in_expression_with_string(){
|
||||||
assert a == true
|
assert a == true
|
||||||
a = false && '' in ['ab', '']
|
a = false && '' in ['ab', '']
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && '' in ['ab', 'bc']
|
a = true && '' in ['ab', 'bc']
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && 'abc' in ['ab', 'bc']
|
a = true && 'abc' in ['ab', 'bc']
|
||||||
assert a == false
|
assert a == false
|
||||||
|
|
||||||
a = true && !('bc' in ['', 'bc'])
|
a = true && !('bc' in ['', 'bc'])
|
||||||
assert a == false
|
assert a == false
|
||||||
a = true && !('abc' in ['', 'bc'])
|
a = true && !('abc' in ['', 'bc'])
|
||||||
assert a == true
|
assert a == true
|
||||||
|
|
||||||
a = 'ab' in ['ab', 'bc'] && true
|
a = 'ab' in ['ab', 'bc'] && true
|
||||||
assert a == true
|
assert a == true
|
||||||
a = 'ab' in ['ab', 'bc'] && false
|
a = 'ab' in ['ab', 'bc'] && false
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import os
|
import (
|
||||||
import time
|
os
|
||||||
|
time
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
vexe = os.getenv('VEXE')
|
vexe = os.getenv('VEXE')
|
||||||
|
@ -26,7 +28,6 @@ fn main() {
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
fn testsuite_begin() {
|
fn testsuite_begin() {
|
||||||
if !(os.user_os() in ['linux', 'solaris']) && os.getenv('FORCE_LIVE_TEST').len == 0 {
|
if !(os.user_os() in ['linux', 'solaris']) && os.getenv('FORCE_LIVE_TEST').len == 0 {
|
||||||
eprintln('Testing the runtime behaviour of -live mode,')
|
eprintln('Testing the runtime behaviour of -live mode,')
|
||||||
|
@ -71,7 +72,6 @@ fn change_source(new string){
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
||||||
fn test_live_program_can_be_compiled() {
|
fn test_live_program_can_be_compiled() {
|
||||||
cmd := '$vexe -live run $source_file > $output_file &'
|
cmd := '$vexe -live run $source_file > $output_file &'
|
||||||
eprintln('Compiling and running with: $cmd')
|
eprintln('Compiling and running with: $cmd')
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
|
|
||||||
import v.tests.local
|
import v.tests.local
|
||||||
|
|
||||||
fn test_local_module_is_callable() {
|
fn test_local_module_is_callable() {
|
||||||
assert local.local_fn()
|
assert local.local_fn()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,6 @@ fn test_match_enums(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert b == .green
|
assert b == .green
|
||||||
|
|
||||||
match b {
|
match b {
|
||||||
.red {
|
.red {
|
||||||
b = .green
|
b = .green
|
||||||
|
|
|
@ -10,9 +10,7 @@ fn test_multi_ptrtype_ret() {
|
||||||
a, b := multi_voidptr_ret()
|
a, b := multi_voidptr_ret()
|
||||||
assert a == voidptr(0)
|
assert a == voidptr(0)
|
||||||
assert b == true
|
assert b == true
|
||||||
|
|
||||||
c, d := multi_byteptr_ret()
|
c, d := multi_byteptr_ret()
|
||||||
assert c == byteptr(0)
|
assert c == byteptr(0)
|
||||||
assert d == true
|
assert d == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,19 +31,14 @@ fn test_mut() {
|
||||||
|
|
||||||
fn test_mut_2() {
|
fn test_mut_2() {
|
||||||
zero := 0
|
zero := 0
|
||||||
|
|
||||||
mut b := B{}
|
mut b := B{}
|
||||||
b.a << A{}
|
b.a << A{}
|
||||||
|
|
||||||
b.a[0].v = [9, 8, 7]
|
b.a[0].v = [9, 8, 7]
|
||||||
|
|
||||||
b.a[0].v << 6
|
b.a[0].v << 6
|
||||||
b.a[zero].v << 5
|
b.a[zero].v << 5
|
||||||
|
|
||||||
b.a[0].v[zero] = 3
|
b.a[0].v[zero] = 3
|
||||||
b.a[0].v[b.a[zero].v[zero]] += 2 - 1 // TODO
|
b.a[0].v[b.a[zero].v[zero]] += 2 - 1 // TODO
|
||||||
b.a[0].v[b.a[0].v[zero]] += 2 - 1 // TODO
|
b.a[0].v[b.a[0].v[zero]] += 2 - 1 // TODO
|
||||||
|
|
||||||
assert b.a[0].v.len == 5
|
assert b.a[0].v.len == 5
|
||||||
assert b.a[0].v[0] == 3
|
assert b.a[0].v[0] == 3
|
||||||
assert b.a[0].v[1] == 8
|
assert b.a[0].v[1] == 8
|
||||||
|
|
|
@ -8,38 +8,23 @@ pub fn (a Vec) str() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (a Vec) +(b Vec) Vec {
|
fn (a Vec) +(b Vec) Vec {
|
||||||
return Vec {
|
return Vec{a.x + b.x, a.y + b.y}
|
||||||
a.x + b.x,
|
|
||||||
a.y + b.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (a Vec) -(b Vec) Vec {
|
fn (a Vec) -(b Vec) Vec {
|
||||||
return Vec {
|
return Vec{a.x - b.x, a.y - b.y}
|
||||||
a.x - b.x,
|
|
||||||
a.y - b.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (a Vec) *(b Vec) Vec {
|
fn (a Vec) *(b Vec) Vec {
|
||||||
return Vec {
|
return Vec{a.x * b.x, a.y * b.y}
|
||||||
a.x * b.x,
|
|
||||||
a.y * b.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (a Vec) /(b Vec) Vec {
|
fn (a Vec) /(b Vec) Vec {
|
||||||
return Vec {
|
return Vec{a.x / b.x, a.y / b.y}
|
||||||
a.x / b.x,
|
|
||||||
a.y / b.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (a Vec) %(b Vec) Vec {
|
fn (a Vec) %(b Vec) Vec {
|
||||||
return Vec {
|
return Vec{a.x % b.x, a.y % b.y}
|
||||||
a.x % b.x,
|
|
||||||
a.y % b.y
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_operator_overloading_with_string_interpolation() {
|
fn test_operator_overloading_with_string_interpolation() {
|
||||||
|
@ -71,5 +56,4 @@ fn test_operator_overloading_with_string_interpolation() {
|
||||||
assert e.str() == '{8, 15}'
|
assert e.str() == '{8, 15}'
|
||||||
assert f.str() == '{0, 0}'
|
assert f.str() == '{0, 0}'
|
||||||
assert g.str() == '{2, 3}'
|
assert g.str() == '{2, 3}'
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
fn test_pointer_arithmetic() {
|
fn test_pointer_arithmetic() {
|
||||||
arr := [1, 2, 3, 4]
|
arr := [1, 2, 3, 4]
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -15,13 +14,11 @@ fn test_multi_level_pointer_dereferencing() {
|
||||||
n := 100
|
n := 100
|
||||||
pn := &n
|
pn := &n
|
||||||
ppn := &pn
|
ppn := &pn
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
mut pppn := &ppn
|
mut pppn := &ppn
|
||||||
***pppn = 300
|
***pppn = 300
|
||||||
pppa := ***int(pppn)
|
pppa := ***int(pppn)
|
||||||
assert 300 == ***pppa
|
assert 300 == ***pppa
|
||||||
}
|
}
|
||||||
|
|
||||||
assert n == 300 // updated by the unsafe pointer manipulation
|
assert n == 300 // updated by the unsafe pointer manipulation
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
// Build and run files in ./prod/ folder, comparing their output to *.expected.txt files.
|
// Build and run files in ./prod/ folder, comparing their output to *.expected.txt files.
|
||||||
// (Similar to REPL tests, but in -prod mode.)
|
// (Similar to REPL tests, but in -prod mode.)
|
||||||
// import os
|
// import os
|
||||||
import v.tests.repl.runner
|
import (
|
||||||
import benchmark
|
v.tests.repl.runner
|
||||||
|
benchmark
|
||||||
|
)
|
||||||
|
|
||||||
fn test_all_v_prod_files() {
|
fn test_all_v_prod_files() {
|
||||||
// TODO: Fix running this test on Windows:
|
// TODO: Fix running this test on Windows:
|
||||||
|
|
|
@ -1,6 +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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +7,6 @@ fn test_repeated_multiple_multiret() {
|
||||||
a, b := some_multiret_fn(1, 2)
|
a, b := some_multiret_fn(1, 2)
|
||||||
assert a == 2
|
assert a == 2
|
||||||
assert b == 3
|
assert b == 3
|
||||||
|
|
||||||
c, d := some_multiret_fn(3, 4)
|
c, d := some_multiret_fn(3, 4)
|
||||||
assert c == 4
|
assert c == 4
|
||||||
assert d == 5
|
assert d == 5
|
||||||
|
|
|
@ -1,23 +1,19 @@
|
||||||
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_reuse_multiple_multiret() {
|
fn test_reuse_multiple_multiret() {
|
||||||
mut c, mut d := some_multiret_fn(4, 10)
|
mut c, mut d := some_multiret_fn(4, 10)
|
||||||
|
|
||||||
mut a, mut b := some_multiret_fn(c, d)
|
mut a, mut b := some_multiret_fn(c, d)
|
||||||
assert a == c + 1
|
assert a == c + 1
|
||||||
assert b == d + 1
|
assert b == d + 1
|
||||||
|
|
||||||
for i in 1 .. 10 {
|
for i in 1 .. 10 {
|
||||||
c += i
|
c += i
|
||||||
d += i
|
d += i
|
||||||
a, b = some_multiret_fn(c, d)
|
a, b = some_multiret_fn(c, d)
|
||||||
assert a == c + 1
|
assert a == c + 1
|
||||||
assert b == d + 1
|
assert b == d + 1
|
||||||
|
|
||||||
c += i + 1
|
c += i + 1
|
||||||
d += i + 1
|
d += i + 1
|
||||||
a, b = some_multiret_fn(c, d)
|
a, b = some_multiret_fn(c, d)
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
fn test_shift_operators() {
|
fn test_shift_operators() {
|
||||||
|
|
||||||
// check that shift works with all integer types
|
// check that shift works with all integer types
|
||||||
// as the right-hand side operand
|
// as the right-hand side operand
|
||||||
a := 1
|
a := 1
|
||||||
b := 1024
|
b := 1024
|
||||||
i := 10
|
i := 10
|
||||||
|
|
||||||
assert b == a << i8(i)
|
assert b == a << i8(i)
|
||||||
assert b == a << byte(i)
|
assert b == a << byte(i)
|
||||||
assert b == a << i16(i)
|
assert b == a << i16(i)
|
||||||
|
@ -14,7 +12,6 @@ fn test_shift_operators() {
|
||||||
assert b == a << u32(i)
|
assert b == a << u32(i)
|
||||||
assert b == a << i64(i)
|
assert b == a << i64(i)
|
||||||
assert b == a << u64(i)
|
assert b == a << u64(i)
|
||||||
|
|
||||||
assert a == b >> i8(i)
|
assert a == b >> i8(i)
|
||||||
assert a == b >> byte(i)
|
assert a == b >> byte(i)
|
||||||
assert a == b >> i16(i)
|
assert a == b >> i16(i)
|
||||||
|
@ -23,14 +20,12 @@ fn test_shift_operators() {
|
||||||
assert a == b >> u32(i)
|
assert a == b >> u32(i)
|
||||||
assert a == b >> i64(i)
|
assert a == b >> i64(i)
|
||||||
assert a == b >> u64(i)
|
assert a == b >> u64(i)
|
||||||
|
|
||||||
// check that shift operation result type is
|
// check that shift operation result type is
|
||||||
// the same as the type of the left-hand side operand
|
// the same as the type of the left-hand side operand
|
||||||
mut c := u64(0)
|
mut c := u64(0)
|
||||||
d := u64(1)
|
d := u64(1)
|
||||||
c = d << i8(63)
|
c = d << i8(63)
|
||||||
assert c == 9223372036854775808
|
assert c == 9223372036854775808
|
||||||
|
|
||||||
// check that shift-assign works with all types
|
// check that shift-assign works with all types
|
||||||
// of integers on the right-hand side
|
// of integers on the right-hand side
|
||||||
mut e := 1
|
mut e := 1
|
||||||
|
|
|
@ -10,7 +10,9 @@ fn t(options TOptions) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_short_struct_as_parameter() {
|
fn test_short_struct_as_parameter() {
|
||||||
if t({a: 1}) {
|
if t({
|
||||||
|
a: 1
|
||||||
|
}) {
|
||||||
assert true
|
assert true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
// can generate the default method for a struct, then the b) case of
|
// can generate the default method for a struct, then the b) case of
|
||||||
// this test will be done by *that* test, and so the testing will
|
// this test will be done by *that* test, and so the testing will
|
||||||
// be incomplete.
|
// be incomplete.
|
||||||
|
|
||||||
struct Man {
|
struct Man {
|
||||||
name string
|
name string
|
||||||
age int
|
age int
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// This file tests whether V can generate a convenience default .str() method
|
// This file tests whether V can generate a convenience default .str() method
|
||||||
// for a custom struct, when the developer has not defined one himself.
|
// for a custom struct, when the developer has not defined one himself.
|
||||||
// The .str() methods are used for string interpolation and for println() calls.
|
// The .str() methods are used for string interpolation and for println() calls.
|
||||||
|
|
||||||
struct Man {
|
struct Man {
|
||||||
name string
|
name string
|
||||||
age int
|
age int
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// for var args of a custom type, when the developer has NOT defined one.
|
// for var args of a custom type, when the developer has NOT defined one.
|
||||||
// Although similar to string_interpolation_struct_test.v, they should not be
|
// Although similar to string_interpolation_struct_test.v, they should not be
|
||||||
// merged.
|
// merged.
|
||||||
|
|
||||||
struct Man {
|
struct Man {
|
||||||
name string
|
name string
|
||||||
age int
|
age int
|
||||||
|
@ -16,9 +15,7 @@ fn my_variadic_function(x ...Man) string {
|
||||||
fn test_vargs_string_interpolation() {
|
fn test_vargs_string_interpolation() {
|
||||||
man := Man{'Me', 38, ['programming', 'reading', 'hiking']}
|
man := Man{'Me', 38, ['programming', 'reading', 'hiking']}
|
||||||
superman := Man{'Superman', 30, ['flying', 'fighting evil', 'being nice']}
|
superman := Man{'Superman', 30, ['flying', 'fighting evil', 'being nice']}
|
||||||
|
|
||||||
results := my_variadic_function(superman, man)
|
results := my_variadic_function(superman, man)
|
||||||
|
|
||||||
assert results.contains('Man {')
|
assert results.contains('Man {')
|
||||||
//
|
//
|
||||||
assert results.contains('name: Superman')
|
assert results.contains('name: Superman')
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
struct Foo {
|
struct Foo {
|
||||||
bar int
|
bar int
|
||||||
mut:
|
mut:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
type Myint int
|
type Myint int
|
||||||
type Myf32 f32
|
type Myf32 f32
|
||||||
type Myf64 f64
|
type Myf64 f64
|
||||||
|
@ -6,10 +5,6 @@ type Myf64 f64
|
||||||
fn test_type_alias() {
|
fn test_type_alias() {
|
||||||
i := Myint(10)
|
i := Myint(10)
|
||||||
assert i + 100 == 110
|
assert i + 100 == 110
|
||||||
|
|
||||||
f := Myf64(10.4)
|
f := Myf64(10.4)
|
||||||
assert f + 0.5 == 10.9
|
assert f + 0.5 == 10.9
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,7 +26,6 @@ type DeclExpr = DeclExprA | DeclExprB
|
||||||
|
|
||||||
struct BoolExpr {
|
struct BoolExpr {
|
||||||
foo int
|
foo int
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BinExpr {
|
struct BinExpr {
|
||||||
|
@ -53,15 +52,12 @@ fn expr() Expr {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct UnaryExpr {
|
struct UnaryExpr {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_expr(e Expr) {
|
fn handle_expr(e Expr) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_decl_expr(de DeclExpr) {
|
fn handle_decl_expr(de DeclExpr) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_bool() BoolExpr {
|
fn parse_bool() BoolExpr {
|
||||||
|
@ -77,7 +73,6 @@ fn test_sum_type_cast() {
|
||||||
fn test_sum_types() {
|
fn test_sum_types() {
|
||||||
b := parse_bool()
|
b := parse_bool()
|
||||||
handle_expr(b)
|
handle_expr(b)
|
||||||
|
|
||||||
de := DeclExprA{}
|
de := DeclExprA{}
|
||||||
handle_expr(de)
|
handle_expr(de)
|
||||||
handle_decl_expr(de)
|
handle_decl_expr(de)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
fn test_typeof_on_simple_expressions() {
|
fn test_typeof_on_simple_expressions() {
|
||||||
a := 123
|
a := 123
|
||||||
assert typeof(42) == 'int'
|
assert typeof(42) == 'int'
|
||||||
|
@ -20,14 +19,15 @@ struct FooBar {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_typeof_on_structs() {
|
fn test_typeof_on_structs() {
|
||||||
assert typeof(FooBar{}) == "FooBar"
|
assert typeof(FooBar{}) == 'FooBar'
|
||||||
astruct_static := [2]FooBar
|
astruct_static := [2]
|
||||||
astruct_dynamic := [FooBar{}, FooBar{}]
|
astruct_dynamic := [FooBar{}, FooBar{}]
|
||||||
assert typeof(astruct_static) == '[2]FooBar'
|
assert typeof(astruct_static) == '[2]FooBar'
|
||||||
assert typeof(astruct_dynamic) == 'array_FooBar'
|
assert typeof(astruct_dynamic) == 'array_FooBar'
|
||||||
}
|
}
|
||||||
|
|
||||||
type MySumType = int | f32 | FooBar
|
type MySumType = int | f32 | FooBar
|
||||||
|
|
||||||
pub fn (ms MySumType) str() string {
|
pub fn (ms MySumType) str() string {
|
||||||
match ms {
|
match ms {
|
||||||
int { return it.str() }
|
int { return it.str() }
|
||||||
|
|
|
@ -8,4 +8,3 @@ fn test_void_pointer_to_u64_cast_via_fn_call() {
|
||||||
c := receive_addr_return_u64(b)
|
c := receive_addr_return_u64(b)
|
||||||
assert (a == c)
|
assert (a == c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,4 +8,3 @@ fn test_u64_to_void_pointer_cast_via_fn_call() {
|
||||||
c := u64(b)
|
c := u64(b)
|
||||||
assert (a == c)
|
assert (a == c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue