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
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,5 @@ fn a_method() {
|
||||||
|
|
||||||
fn test_backtrace() {
|
fn test_backtrace() {
|
||||||
a_method()
|
a_method()
|
||||||
//panic('hi')
|
// panic('hi')
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,25 @@
|
||||||
|
fn test_bitness() {
|
||||||
fn test_bitness(){
|
mut x := 0
|
||||||
mut x := 0
|
$if x32 {
|
||||||
$if x32 {
|
println('system is 32 bit')
|
||||||
println('system is 32 bit')
|
x = 1
|
||||||
x = 1
|
}
|
||||||
}
|
$if x64 {
|
||||||
$if x64 {
|
println('system is 64 bit')
|
||||||
println('system is 64 bit')
|
x = 2
|
||||||
x = 2
|
}
|
||||||
}
|
assert x > 0
|
||||||
assert x > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_endianness(){
|
fn test_endianness() {
|
||||||
mut x := 0
|
mut x := 0
|
||||||
$if little_endian {
|
$if little_endian {
|
||||||
println('system is little endian')
|
println('system is little endian')
|
||||||
x = 1
|
x = 1
|
||||||
}
|
}
|
||||||
$if big_endian {
|
$if big_endian {
|
||||||
println('system is big endian')
|
println('system is big endian')
|
||||||
x = 2
|
x = 2
|
||||||
}
|
}
|
||||||
assert x > 0
|
assert x > 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -5,12 +5,12 @@ struct DeclExprA { name string }
|
||||||
struct AStructWithAVeryLongName { 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{}
|
||||||
assert true
|
assert true
|
||||||
b := DxB{}
|
b := DxB{}
|
||||||
assert true
|
assert true
|
||||||
c := DeclExprA{}
|
c := DeclExprA{}
|
||||||
assert true
|
assert true
|
||||||
d := AStructWithAVeryLongName{}
|
d := AStructWithAVeryLongName{}
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,14 +17,12 @@ fn test_enum_bitfield() {
|
||||||
a.perm.set(.write)
|
a.perm.set(.write)
|
||||||
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)
|
||||||
assert b.has(.write)
|
assert b.has(.write)
|
||||||
|
|
|
@ -34,7 +34,7 @@ fn test_enum() {
|
||||||
|
|
||||||
fn test_in() {
|
fn test_in() {
|
||||||
color := Color.red
|
color := Color.red
|
||||||
num := 3 // used to be an expr bug before `in`
|
num := 3 // used to be an expr bug before `in`
|
||||||
assert color in [.red, .green]
|
assert color in [.red, .green]
|
||||||
assert num == 3
|
assert num == 3
|
||||||
println(color)
|
println(color)
|
||||||
|
@ -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,12 +1,11 @@
|
||||||
|
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
|
||||||
v = [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!!
|
v = [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!!
|
||||||
assert v[1] == x
|
assert v[1] == x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fixed_array_can_be_used_in_declaration(){
|
fn test_fixed_array_can_be_used_in_declaration() {
|
||||||
x := 2.32
|
x := 2.32
|
||||||
v := [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!!
|
v := [1.0, x, 3.0,4.0,5.0,6.0,7.0,8.0]!!
|
||||||
assert v[1] == x
|
assert v[1] == x
|
||||||
|
@ -17,7 +16,8 @@ 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
|
||||||
ctx.vb = [1.1, x, 3.3, 4.4, 5.0, 6.0, 7.0, 8.9]!!
|
ctx.vb = [1.1, x, 3.3, 4.4, 5.0, 6.0, 7.0, 8.9]!!
|
||||||
|
|
|
@ -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) {
|
||||||
|
@ -21,4 +22,4 @@ fn test_ref_fn_arg() {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fn test_dummy(){}
|
fn test_dummy() {}
|
||||||
|
|
|
@ -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()
|
||||||
|
@ -10,7 +11,7 @@ fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_manu
|
||||||
/*
|
/*
|
||||||
// TODO: Fix this.
|
// TODO: Fix this.
|
||||||
// v should produce temporary intermediate variables in chained calls:
|
// v should produce temporary intermediate variables in chained calls:
|
||||||
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_chained(){
|
fn test_call_fn_that_requires_reference_with_function_that_returns_a_struct_chained() {
|
||||||
res := (tmisc.random().unix_time())
|
res := (tmisc.random().unix_time())
|
||||||
println('res: $res')
|
println('res: $res')
|
||||||
assert true
|
assert true
|
||||||
|
|
|
@ -15,5 +15,5 @@ fn test_fn_multiple_returns() {
|
||||||
fn fn_mr_get_user() (string, int, []string, UserData) {
|
fn fn_mr_get_user() (string, int, []string, UserData) {
|
||||||
groups := ['admins', 'users']
|
groups := ['admins', 'users']
|
||||||
data := UserData{test: 'Test Data'}
|
data := UserData{test: 'Test Data'}
|
||||||
return 'joe',34,groups,data
|
return 'joe', 34, groups, data
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,21 +59,21 @@ type actionf_p2 fn (voidptr, voidptr)
|
||||||
// TODO
|
// TODO
|
||||||
fn modify_array(a mut []int) {
|
fn modify_array(a mut []int) {
|
||||||
a[0] = 10
|
a[0] = 10
|
||||||
for i in 0..a.len {
|
for i in 0 .. a.len {
|
||||||
a[i] = a[i] * 2
|
a[i] = a[i] * 2
|
||||||
}
|
}
|
||||||
//a << 888
|
// a << 888
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_mut_array() {
|
fn test_mut_array() {
|
||||||
mut nums := [1, 2, 3]
|
mut nums := [1, 2, 3]
|
||||||
modify_array(mut nums)
|
modify_array(mut nums)
|
||||||
//assert nums.len == 4
|
// assert nums.len == 4
|
||||||
// println(nums)
|
// println(nums)
|
||||||
assert nums[0] == 20
|
assert nums[0] == 20
|
||||||
assert nums[1] == 4
|
assert nums[1] == 4
|
||||||
assert nums[2] == 6
|
assert nums[2] == 6
|
||||||
//assert nums[3] == 888
|
// assert nums[3] == 888
|
||||||
// workaround for // [91, 32, -33686272] windows bug
|
// workaround for // [91, 32, -33686272] windows bug
|
||||||
println(nums.clone())
|
println(nums.clone())
|
||||||
}
|
}
|
||||||
|
@ -124,14 +124,13 @@ 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 {
|
||||||
println('hello')
|
println('hello')
|
||||||
return x + 1
|
return x + 1
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assert_in_bool_fn(v int) bool {
|
fn assert_in_bool_fn(v int) bool {
|
||||||
|
@ -145,10 +144,11 @@ fn test_assert_in_bool_fn() {
|
||||||
|
|
||||||
type MyFn fn (int) int
|
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
|
||||||
}
|
}
|
||||||
fn test_fn_type_call() {
|
fn test_fn_type_call() {
|
||||||
mut arr := []MyFn
|
mut arr := []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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ fn test_fn_variadic() {
|
||||||
group2 := VaTestGroup{
|
group2 := VaTestGroup{
|
||||||
name: 'admins'
|
name: 'admins'
|
||||||
}
|
}
|
||||||
variadic_test('joe',group1,group2)
|
variadic_test('joe', group1, group2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -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)
|
||||||
|
@ -46,7 +45,7 @@ fn variadic_forward_b(a ...string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fn_variadic_forward() {
|
fn test_fn_variadic_forward() {
|
||||||
assert variadic_forward_a('a','b','c') == 'abc'
|
assert variadic_forward_a('a', 'b', 'c') == 'abc'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fn_variadic_with_arg_no_vargs(name string, groups ...VaTestGroup) {
|
fn fn_variadic_with_arg_no_vargs(name string, groups ...VaTestGroup) {
|
||||||
|
@ -85,7 +84,7 @@ fn test_fn_variadic_method() {
|
||||||
group2 := VaTestGroup{
|
group2 := VaTestGroup{
|
||||||
name: 'admins'
|
name: 'admins'
|
||||||
}
|
}
|
||||||
a.variadic_method('marko',group1,group2)
|
a.variadic_method('marko', group1, group2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fn_variadic_method_no_args() {
|
fn test_fn_variadic_method_no_args() {
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
|
fn test_if_expression_precedence_false_condition() {
|
||||||
fn test_if_expression_precedence_false_condition(){
|
|
||||||
b := 10
|
b := 10
|
||||||
c := 20
|
c := 20
|
||||||
res := 1 + if b > c { b } else { c } + 1
|
res := 1 + if b > c { b } else { c } + 1
|
||||||
assert res == c + 2
|
assert res == c + 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_if_expression_precedence_true_condition(){
|
fn test_if_expression_precedence_true_condition() {
|
||||||
b := 20
|
b := 20
|
||||||
c := 10
|
c := 10
|
||||||
res := 1 + if b > c { b } else { c } + 1
|
res := 1 + if b > c { b } else { c } + 1
|
||||||
|
|
|
@ -2,7 +2,7 @@ enum Colors {
|
||||||
red green blue yellow
|
red green blue yellow
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_in_expression(){
|
fn test_in_expression() {
|
||||||
mut a := false
|
mut a := false
|
||||||
arr1 := [1, 2]
|
arr1 := [1, 2]
|
||||||
arr2 := [0, 2]
|
arr2 := [0, 2]
|
||||||
|
@ -15,24 +15,23 @@ 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
|
|
||||||
fn test_in_expression_with_enum(){
|
/*
|
||||||
|
not implemented
|
||||||
|
fn test_in_expression_with_enum() {
|
||||||
mut a := false
|
mut a := false
|
||||||
arr1 := [Colors.green, .blue]
|
arr1 := [Colors.green, .blue]
|
||||||
arr2 := [Colors.red, .blue]
|
arr2 := [Colors.red, .blue]
|
||||||
|
@ -62,7 +61,7 @@ fn test_in_expression_with_enum(){
|
||||||
assert a == false
|
assert a == false
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
fn test_in_expression_with_string(){
|
fn test_in_expression_with_string() {
|
||||||
mut a := false
|
mut a := false
|
||||||
arr1 := ['ab', 'bc']
|
arr1 := ['ab', 'bc']
|
||||||
arr2 := ['', 'bc']
|
arr2 := ['', 'bc']
|
||||||
|
@ -75,24 +74,21 @@ 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
|
||||||
assert a == false
|
assert a == false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_optimized_in_expression(){
|
fn test_optimized_in_expression() {
|
||||||
mut a := false
|
mut a := false
|
||||||
a = true && 2 in [1, 2]
|
a = true && 2 in [1, 2]
|
||||||
assert a == true
|
assert a == true
|
||||||
|
@ -102,24 +98,21 @@ 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
|
||||||
assert a == false
|
assert a == false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_optimized_in_expression_with_enum(){
|
fn test_optimized_in_expression_with_enum() {
|
||||||
mut a := false
|
mut a := false
|
||||||
a = true && Colors.blue in [.green, .blue]
|
a = true && Colors.blue in [.green, .blue]
|
||||||
assert a == true
|
assert a == true
|
||||||
|
@ -129,24 +122,21 @@ 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
|
||||||
assert a == false
|
assert a == false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_optimized_in_expression_with_string(){
|
fn test_optimized_in_expression_with_string() {
|
||||||
mut a := false
|
mut a := false
|
||||||
a = true && 'bc' in ['ab', 'bc']
|
a = true && 'bc' in ['ab', 'bc']
|
||||||
assert a == true
|
assert a == true
|
||||||
|
@ -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,7 +1,7 @@
|
||||||
module main
|
module main
|
||||||
|
|
||||||
interface Speaker {
|
interface Speaker {
|
||||||
say()string
|
say() string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_todo() {}
|
fn test_todo() {}
|
||||||
|
@ -23,7 +23,7 @@ fn (r mut ChatRoom) add(name string, s Speaker) {
|
||||||
r.talkers[name] = s
|
r.talkers[name] = s
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_using_a_map_of_speaker_interfaces(){
|
fn test_using_a_map_of_speaker_interfaces() {
|
||||||
mut room := new_room()
|
mut room := new_room()
|
||||||
room.add('my cat', Cat{name: 'Tigga'} )
|
room.add('my cat', Cat{name: 'Tigga'} )
|
||||||
room.add('my dog', Dog{name: 'Pirin'} )
|
room.add('my dog', Dog{name: 'Pirin'} )
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import os
|
import (
|
||||||
import time
|
os
|
||||||
|
time
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
vexe = os.getenv('VEXE')
|
vexe = os.getenv('VEXE')
|
||||||
source_file = os.join_path(os.temp_dir(), 'generated_live_program.v')
|
source_file = os.join_path(os.temp_dir(), 'generated_live_program.v')
|
||||||
output_file = os.join_path(os.temp_dir(), 'generated_live_program.output.txt')
|
output_file = os.join_path(os.temp_dir(), 'generated_live_program.output.txt')
|
||||||
live_program_source = "
|
live_program_source = "
|
||||||
module main
|
module main
|
||||||
import time
|
import time
|
||||||
|
@ -26,8 +28,7 @@ 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,')
|
||||||
eprintln('is reliable only on Linux for now.')
|
eprintln('is reliable only on Linux for now.')
|
||||||
|
@ -37,22 +38,22 @@ fn testsuite_begin(){
|
||||||
os.write_file(source_file, live_program_source)
|
os.write_file(source_file, live_program_source)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn testsuite_end(){
|
fn testsuite_end() {
|
||||||
os.rm( source_file )
|
os.rm(source_file)
|
||||||
eprintln('source: $source_file')
|
eprintln('source: $source_file')
|
||||||
eprintln('output: $output_file')
|
eprintln('output: $output_file')
|
||||||
$if !windows {
|
$if !windows {
|
||||||
os.system('cat $output_file')
|
os.system('cat $output_file')
|
||||||
}
|
}
|
||||||
println('---------------------------------------------------------------------------')
|
println('---------------------------------------------------------------------------')
|
||||||
output_lines := os.read_lines( output_file ) or {
|
output_lines := os.read_lines(output_file) or {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mut histogram := map[string]int
|
mut histogram := map[string]int
|
||||||
for line in output_lines {
|
for line in output_lines {
|
||||||
histogram[line] = histogram[line] + 1
|
histogram[line] = histogram[line] + 1
|
||||||
}
|
}
|
||||||
for k,v in histogram {
|
for k, v in histogram {
|
||||||
println('> found ${k} $v times.')
|
println('> found ${k} $v times.')
|
||||||
}
|
}
|
||||||
println('---------------------------------------------------------------------------')
|
println('---------------------------------------------------------------------------')
|
||||||
|
@ -62,17 +63,16 @@ fn testsuite_end(){
|
||||||
assert histogram['ORIGINAL'] > 0
|
assert histogram['ORIGINAL'] > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn change_source(new string){
|
fn change_source(new string) {
|
||||||
time.sleep_ms(250)
|
time.sleep_ms(250)
|
||||||
eprintln('> change ORIGINAL to: $new')
|
eprintln('> change ORIGINAL to: $new')
|
||||||
os.write_file(source_file,live_program_source.replace('ORIGINAL', new))
|
os.write_file(source_file, live_program_source.replace('ORIGINAL', new))
|
||||||
time.sleep_ms(1000)
|
time.sleep_ms(1000)
|
||||||
eprintln('> done.')
|
eprintln('> done.')
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
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')
|
||||||
res := os.system(cmd)
|
res := os.system(cmd)
|
||||||
|
@ -81,17 +81,17 @@ fn test_live_program_can_be_compiled(){
|
||||||
assert res == 0
|
assert res == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_live_program_can_be_changed_1(){
|
fn test_live_program_can_be_changed_1() {
|
||||||
change_source('CHANGED')
|
change_source('CHANGED')
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_live_program_can_be_changed_2(){
|
fn test_live_program_can_be_changed_2() {
|
||||||
change_source('ANOTHER')
|
change_source('ANOTHER')
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_live_program_has_ended(){
|
fn test_live_program_has_ended() {
|
||||||
time.sleep_ms(10*1000)
|
time.sleep_ms(10 * 1000)
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,30 +64,29 @@ fn test_match_integers() {
|
||||||
assert a == -2
|
assert a == -2
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_match_enums(){
|
fn test_match_enums() {
|
||||||
mut b := Color.red
|
mut b := Color.red
|
||||||
match b{
|
match b {
|
||||||
.red {
|
.red {
|
||||||
b = .green
|
b = .green
|
||||||
}
|
}
|
||||||
.green {
|
.green {
|
||||||
b = .blue
|
b = .blue
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
println('b is ${b.str()}')
|
println('b is ${b.str()}')
|
||||||
b = .red
|
b = .red
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert b == .green
|
assert b == .green
|
||||||
|
match b {
|
||||||
match b{
|
.red {
|
||||||
.red {
|
b = .green
|
||||||
b = .green
|
}
|
||||||
}
|
else {
|
||||||
else {
|
println('b is ${b.str()}')
|
||||||
println('b is ${b.str()}')
|
b = .blue
|
||||||
b = .blue
|
}
|
||||||
}
|
}
|
||||||
}
|
assert b == .blue
|
||||||
assert b == .blue
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,17 @@ pub mut:
|
||||||
|
|
||||||
fn foo(b int, a mut []int) {
|
fn foo(b int, a mut []int) {
|
||||||
a[0] = 7
|
a[0] = 7
|
||||||
//a << 4
|
// a << 4
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_mut() {
|
fn test_mut() {
|
||||||
mut numbers := [1,2,3]
|
mut numbers := [1, 2, 3]
|
||||||
foo(7, mut numbers)
|
foo(7, mut numbers)
|
||||||
assert numbers.len == 3
|
assert numbers.len == 3
|
||||||
// TODO bring back once << works with mutable args
|
// TODO bring back once << works with mutable args
|
||||||
//assert numbers.len == 4
|
// assert numbers.len == 4
|
||||||
//assert numbers[0] == 7
|
// assert numbers[0] == 7
|
||||||
//assert numbers[3] == 4
|
// assert numbers[3] == 4
|
||||||
println(numbers)
|
println(numbers)
|
||||||
n := 1
|
n := 1
|
||||||
mut b := &n
|
mut b := &n
|
||||||
|
@ -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
|
||||||
|
|
|
@ -1,28 +1,28 @@
|
||||||
fn test_int_lit_call_method() {
|
fn test_int_lit_call_method() {
|
||||||
x1 := 1234.str()
|
x1 := 1234.str()
|
||||||
assert x1 == '1234'
|
assert x1 == '1234'
|
||||||
x2 := -0xffff.str()
|
x2 := -0xffff.str()
|
||||||
assert x2 == '-65535'
|
assert x2 == '-65535'
|
||||||
x3 := 0b1001001.str()
|
x3 := 0b1001001.str()
|
||||||
assert x3 == '73'
|
assert x3 == '73'
|
||||||
x4 := 0o653262.str()
|
x4 := 0o653262.str()
|
||||||
assert x4 == '218802'
|
assert x4 == '218802'
|
||||||
x5 := 0.str()
|
x5 := 0.str()
|
||||||
assert x5 == '0'
|
assert x5 == '0'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_float_lit_call_method() {
|
fn test_float_lit_call_method() {
|
||||||
x1 := -123.66.str()
|
x1 := -123.66.str()
|
||||||
assert x1 == '-1.2366e+02'
|
assert x1 == '-1.2366e+02'
|
||||||
x2 := 12.5e-2.str()
|
x2 := 12.5e-2.str()
|
||||||
assert x2 == '1.25e-01'
|
assert x2 == '1.25e-01'
|
||||||
x3 := .789.str()
|
x3 := .789.str()
|
||||||
assert x3 == '7.89e-01'
|
assert x3 == '7.89e-01'
|
||||||
x4 := .003e2.str()
|
x4 := .003e2.str()
|
||||||
assert x4 == '3.e-01'
|
assert x4 == '3.e-01'
|
||||||
x5 := 2.e-3.str()
|
x5 := 2.e-3.str()
|
||||||
assert x5 == '2.e-03'
|
assert x5 == '2.e-03'
|
||||||
x6 := 5.0.str()
|
x6 := 5.0.str()
|
||||||
assert x6 == '5.e+00'
|
assert x6 == '5.e+00'
|
||||||
// x7 := 5..str() Syntax `5.` is allowed, but do not call method on it (`5..str()` is parsed as a range). Use `5.0.str()` instead.
|
// x7 := 5..str() Syntax `5.` is allowed, but do not call method on it (`5..str()` is parsed as a range). Use `5.0.str()` instead.
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,69 +7,53 @@ pub fn (a Vec) str() string {
|
||||||
return '{$a.x, $a.y}'
|
return '{$a.x, $a.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 (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() {
|
||||||
a := Vec{2, 3}
|
a := Vec{2, 3}
|
||||||
b := Vec{4, 5}
|
b := Vec{4, 5}
|
||||||
|
|
||||||
c := a + b
|
c := a + b
|
||||||
assert a.x + b.x == c.x
|
assert a.x + b.x == c.x
|
||||||
assert a.y + b.y == c.y
|
assert a.y + b.y == c.y
|
||||||
|
|
||||||
d := a - b
|
d := a - b
|
||||||
assert a.x - b.x == d.x
|
assert a.x - b.x == d.x
|
||||||
assert a.y - b.y == d.y
|
assert a.y - b.y == d.y
|
||||||
|
|
||||||
e := a * b
|
e := a * b
|
||||||
assert a.x * b.x == e.x
|
assert a.x * b.x == e.x
|
||||||
assert a.y * b.y == e.y
|
assert a.y * b.y == e.y
|
||||||
|
|
||||||
f := a / b
|
f := a / b
|
||||||
assert a.x / b.x == f.x
|
assert a.x / b.x == f.x
|
||||||
assert a.y / b.y == f.y
|
assert a.y / b.y == f.y
|
||||||
|
|
||||||
g := a % b
|
g := a % b
|
||||||
assert a.x % b.x == g.x
|
assert a.x % b.x == g.x
|
||||||
assert a.y % b.y == g.y
|
assert a.y % b.y == g.y
|
||||||
|
|
||||||
assert c.str() == '{6, 8}'
|
|
||||||
assert d.str() == '{-2, -2}'
|
|
||||||
assert e.str() == '{8, 15}'
|
|
||||||
assert f.str() == '{0, 0}'
|
|
||||||
assert g.str() == '{2, 3}'
|
|
||||||
|
|
||||||
|
assert c.str() == '{6, 8}'
|
||||||
|
assert d.str() == '{-2, -2}'
|
||||||
|
assert e.str() == '{8, 15}'
|
||||||
|
assert f.str() == '{0, 0}'
|
||||||
|
assert g.str() == '{2, 3}'
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
|
|
||||||
fn test_pointer_arithmetic() {
|
fn test_pointer_arithmetic() {
|
||||||
arr := [1,2,3,4]
|
arr := [1, 2, 3, 4]
|
||||||
unsafe {
|
unsafe {
|
||||||
mut parr := *int(arr.data)
|
mut parr := *int(arr.data)
|
||||||
parr++
|
parr++
|
||||||
|
@ -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,3 +1,3 @@
|
||||||
fn test_print() {
|
fn test_print() {
|
||||||
println(2.0)
|
println(2.0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,15 +1,13 @@
|
||||||
// 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_repeated_multiple_multiret() {
|
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,27 +1,23 @@
|
||||||
// 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)
|
assert a == c + 1
|
||||||
assert a == c+1
|
assert b == d + 1
|
||||||
assert b == d+1
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -4,13 +4,15 @@ struct TOptions {
|
||||||
|
|
||||||
fn t(options TOptions) bool {
|
fn t(options TOptions) bool {
|
||||||
if options.a == 1 {
|
if options.a == 1 {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,38 +2,38 @@ const (
|
||||||
sbuffer_size = 10
|
sbuffer_size = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
struct Foo {
|
struct Foo {
|
||||||
number int
|
number int
|
||||||
str string
|
str string
|
||||||
f f64
|
f f64
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_array_str() {
|
fn test_array_str() {
|
||||||
f := Foo{34, 'hello', 1.2}
|
f := Foo{34, 'hello', 1.2}
|
||||||
println(f)
|
println(f)
|
||||||
//s := f.str()
|
// s := f.str()
|
||||||
//println(s)
|
// println(s)
|
||||||
n := [1, 2, 3]
|
n := [1, 2, 3]
|
||||||
assert n.str() == '[1, 2, 3]'
|
assert n.str() == '[1, 2, 3]'
|
||||||
println(n) // make sure the array is printable
|
println(n) // make sure the array is printable
|
||||||
n2 := [4,5,6]
|
n2 := [4, 5, 6]
|
||||||
//assert n2.str() == '[4, 5, 6]'
|
// assert n2.str() == '[4, 5, 6]'
|
||||||
println(n2)
|
println(n2)
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,13 @@
|
||||||
// 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
|
||||||
interests []string
|
interests []string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_default_struct_array_of_structs_interpolation(){
|
fn test_default_struct_array_of_structs_interpolation() {
|
||||||
people := [
|
people := [
|
||||||
Man{'Superman', 30, ['flying','fighting evil','being nice']},
|
Man{'Superman', 30, ['flying','fighting evil','being nice']},
|
||||||
Man{'Bilbo Baggins', 111, ['exploring', 'hiding']},
|
Man{'Bilbo Baggins', 111, ['exploring', 'hiding']},
|
||||||
|
@ -30,5 +29,5 @@ fn test_default_struct_array_of_structs_interpolation(){
|
||||||
assert s.contains('age: 111')
|
assert s.contains('age: 111')
|
||||||
assert s.contains('interests: ["exploring", "hiding"]')
|
assert s.contains('interests: ["exploring", "hiding"]')
|
||||||
assert s.contains('}]')
|
assert s.contains('}]')
|
||||||
//println(s)
|
// println(s)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
// 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
|
||||||
interests []string
|
interests []string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_default_struct_string_interpolation(){
|
fn test_default_struct_string_interpolation() {
|
||||||
superman := Man{'Superman', 30, ['flying','fighting evil','being nice']}
|
superman := Man{'Superman', 30, ['flying', 'fighting evil', 'being nice']}
|
||||||
s := '$superman'
|
s := '$superman'
|
||||||
assert s.contains('Man {')
|
assert s.contains('Man {')
|
||||||
assert s.contains('name: Superman')
|
assert s.contains('name: Superman')
|
||||||
|
@ -17,5 +16,5 @@ fn test_default_struct_string_interpolation(){
|
||||||
assert s.contains('interests: [')
|
assert s.contains('interests: [')
|
||||||
assert s.contains('"being nice"')
|
assert s.contains('"being nice"')
|
||||||
assert s.contains('}')
|
assert s.contains('}')
|
||||||
//println(s)
|
// println(s)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,23 +2,20 @@
|
||||||
// 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
|
||||||
interests []string
|
interests []string
|
||||||
}
|
}
|
||||||
|
|
||||||
fn my_variadic_function(x ...Man) string {
|
fn my_variadic_function(x ...Man) string {
|
||||||
return '$x' // this interpolation should generate .str() methods for Man
|
return '$x' // this interpolation should generate .str() methods for Man
|
||||||
}
|
}
|
||||||
|
|
||||||
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:
|
||||||
|
@ -20,6 +19,6 @@ fn test_adding_to_mutable_string_field() {
|
||||||
assert foo.bar == 10
|
assert foo.bar == 10
|
||||||
assert foo.str == 'hi'
|
assert foo.str == 'hi'
|
||||||
foo.str += '!'
|
foo.str += '!'
|
||||||
eprintln( foo.str )
|
eprintln(foo.str)
|
||||||
assert foo.str == 'hi!'
|
assert foo.str == 'hi!'
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@ struct Dxx { mut: c Cxx }
|
||||||
struct Exx { mut: v []int }
|
struct Exx { mut: v []int }
|
||||||
struct Fxx { e []Exx }
|
struct Fxx { e []Exx }
|
||||||
|
|
||||||
fn test_chained_string(){
|
fn test_chained_string() {
|
||||||
mut b := Bxx{} b = Bxx{Axx{2}}
|
mut b := Bxx{} b = Bxx{Axx{2}}
|
||||||
assert 'b is: ' + b.a.v.str() == 'b is: 2'
|
assert 'b is: ' + b.a.v.str() == 'b is: 2'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_chained_assignments(){
|
fn test_chained_assignments() {
|
||||||
mut c := Cxx{}
|
mut c := Cxx{}
|
||||||
c.b = Bxx{}
|
c.b = Bxx{}
|
||||||
mut d := Dxx{}
|
mut d := Dxx{}
|
||||||
d.c.b = Bxx{}
|
d.c.b = Bxx{}
|
||||||
assert true
|
assert true
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_chained_array_access(){
|
fn test_chained_array_access() {
|
||||||
f := Fxx{[Exx{[10,20,30]},Exx{[100,200,300,400]}]}
|
f := Fxx{[Exx{[10, 20, 30]}, Exx{[100, 200, 300, 400]}]}
|
||||||
assert 'f.e[0].v.len: 3' == 'f.e[0].v.len: ${f.e[0].v.len}'
|
assert 'f.e[0].v.len: 3' == 'f.e[0].v.len: ${f.e[0].v.len}'
|
||||||
assert 'f.e[1].v.len: 4' == 'f.e[1].v.len: ${f.e[1].v.len}'
|
assert 'f.e[1].v.len: 4' == 'f.e[1].v.len: ${f.e[1].v.len}'
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,13 +20,12 @@ fn test_person_str() {
|
||||||
|
|
||||||
struct Foo {}
|
struct Foo {}
|
||||||
|
|
||||||
type Expr = Foo | BoolExpr | BinExpr | UnaryExpr | DeclExprA | DeclExprB
|
type Expr = Foo | BoolExpr | BinExpr | UnaryExpr | DeclExprA | DeclExprB
|
||||||
|
|
||||||
type DeclExpr = DeclExprA | DeclExprB
|
type DeclExpr = DeclExprA | DeclExprB
|
||||||
|
|
||||||
struct BoolExpr {
|
struct BoolExpr {
|
||||||
foo int
|
foo int
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BinExpr {
|
struct BinExpr {
|
||||||
|
@ -45,7 +44,7 @@ fn expr1() Expr {
|
||||||
mut e := Expr{}
|
mut e := Expr{}
|
||||||
e = BinExpr{'binexpr'}
|
e = BinExpr{'binexpr'}
|
||||||
return e
|
return e
|
||||||
//return BinExpr{}
|
// return BinExpr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expr() Expr {
|
fn expr() Expr {
|
||||||
|
@ -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'
|
||||||
|
@ -8,7 +7,7 @@ fn test_typeof_on_simple_expressions() {
|
||||||
assert typeof(a) == 'int'
|
assert typeof(a) == 'int'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_typeof_on_atypes(){
|
fn test_typeof_on_atypes() {
|
||||||
aint := []int
|
aint := []int
|
||||||
astring := []string
|
astring := []string
|
||||||
assert typeof(aint) == 'array_int'
|
assert typeof(aint) == 'array_int'
|
||||||
|
@ -19,15 +18,16 @@ struct FooBar {
|
||||||
x int
|
x int
|
||||||
}
|
}
|
||||||
|
|
||||||
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() }
|
||||||
|
@ -37,7 +37,7 @@ pub fn (ms MySumType) str() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_typeof_on_sumtypes(){
|
fn test_typeof_on_sumtypes() {
|
||||||
a := MySumType(32)
|
a := MySumType(32)
|
||||||
b := MySumType(f32(123.0))
|
b := MySumType(f32(123.0))
|
||||||
c := MySumType(FooBar{x:43})
|
c := MySumType(FooBar{x:43})
|
||||||
|
@ -66,7 +66,7 @@ fn test_typeof_on_sumtypes_of_structs() {
|
||||||
a := fexpr(1)
|
a := fexpr(1)
|
||||||
b := fexpr(2)
|
b := fexpr(2)
|
||||||
c := fexpr(3)
|
c := fexpr(3)
|
||||||
d := ExprType( UnaryExpr{} )
|
d := ExprType(UnaryExpr{})
|
||||||
assert typeof(a) == 'UnaryExpr'
|
assert typeof(a) == 'UnaryExpr'
|
||||||
assert typeof(b) == 'BinExpr'
|
assert typeof(b) == 'BinExpr'
|
||||||
assert typeof(c) == 'BoolExpr'
|
assert typeof(c) == 'BoolExpr'
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fn receive_addr_return_u64 (addr voidptr) u64 {
|
fn receive_addr_return_u64(addr voidptr) u64 {
|
||||||
return u64(addr)
|
return u64(addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
fn receive_u64_return_addr (something u64) voidptr {
|
fn receive_u64_return_addr(something u64) voidptr {
|
||||||
return voidptr(something)
|
return voidptr(something)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ fn new_s() EmptyStruct {
|
||||||
return EmptyStruct{}
|
return EmptyStruct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_using_an_empty_struct_compiles_and_works(){
|
fn test_using_an_empty_struct_compiles_and_works() {
|
||||||
s := new_s()
|
s := new_s()
|
||||||
eprintln('s: $s')
|
eprintln('s: $s')
|
||||||
assert true
|
assert true
|
||||||
|
|
Loading…
Reference in New Issue