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