tests: run vfmt over some of the tests in vlib/v/tests (#9455)
parent
3b166d8327
commit
4a10514081
|
@ -21,6 +21,13 @@ const (
|
|||
'vlib/gg/m4/graphic.v' /* has hand crafted meaningful formatting of matrices */,
|
||||
'vlib/gg/m4/m4_test.v' /* has hand crafted meaningful formatting of matrices */,
|
||||
'vlib/gg/m4/matrix.v' /* has hand crafted meaningful formatting of matrices */,
|
||||
'vlib/v/tests/array_append_short_struct_test.v', /* extra empty line */
|
||||
'vlib/v/tests/fixed_array_const_size_test.v', /* fixed arr type is changed */
|
||||
'vlib/v/tests/fn_high_test.v', /* param name removed */
|
||||
'vlib/v/tests/fn_test.v', /* bad comment formatting */
|
||||
'vlib/v/tests/generics_return_generics_struct_test.v', /* generic fn param removed */
|
||||
'vlib/v/tests/interop_test.v', /* bad comment formatting */
|
||||
'vlib/v/tests/generics_test.v', /* some silent error */
|
||||
]
|
||||
vfmt_verify_list = [
|
||||
'cmd/',
|
||||
|
@ -58,7 +65,7 @@ const (
|
|||
'vlib/v/preludes',
|
||||
'vlib/v/scanner/',
|
||||
'vlib/v/table/',
|
||||
//'vlib/v/tests/',
|
||||
'vlib/v/tests/',
|
||||
'vlib/v/token/',
|
||||
'vlib/v/util/',
|
||||
'vlib/v/vcache/',
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
fn test_anon_fn_call() {
|
||||
anon_fn := fn() string {
|
||||
anon_fn := fn () string {
|
||||
return test()
|
||||
}
|
||||
assert anon_fn() == 'Test'
|
||||
}
|
||||
|
||||
fn test() string {
|
||||
return "Test"
|
||||
return 'Test'
|
||||
}
|
||||
|
|
|
@ -1,36 +1,36 @@
|
|||
fn test_anon_fn_in_map() {
|
||||
mut woop := map{
|
||||
'what': fn() string {
|
||||
'what': fn () string {
|
||||
return 'whoopity whoop'
|
||||
}
|
||||
}
|
||||
assert woop['what']() == 'whoopity whoop'
|
||||
|
||||
woop['shat'] = fn() string {
|
||||
woop['shat'] = fn () string {
|
||||
return 'shoopity shoop'
|
||||
}
|
||||
assert woop['shat']() == 'shoopity shoop'
|
||||
}
|
||||
|
||||
fn test_anon_fn_in_array() {
|
||||
mut woop := [fn() string {
|
||||
mut woop := [fn () string {
|
||||
return 'whoopity whoop'
|
||||
}]
|
||||
assert woop[0]() == 'whoopity whoop'
|
||||
|
||||
woop[0] = fn() string {
|
||||
woop[0] = fn () string {
|
||||
return 'shoopity shoop'
|
||||
}
|
||||
assert woop[0]() == 'shoopity shoop'
|
||||
}
|
||||
|
||||
fn test_anon_fn_in_fixed_array() {
|
||||
mut woop := [fn() string {
|
||||
mut woop := [fn () string {
|
||||
return 'whoopity whoop'
|
||||
}]!
|
||||
assert woop[0]() == 'whoopity whoop'
|
||||
|
||||
woop[0] = fn() string {
|
||||
woop[0] = fn () string {
|
||||
return 'shoopity shoop'
|
||||
}
|
||||
assert woop[0]() == 'shoopity shoop'
|
||||
|
|
|
@ -7,11 +7,11 @@ fn test_calling_an_anon_function_returning_question() {
|
|||
fn create_and_call_anon_function() ? {
|
||||
x := fn (a string, b int) ? {
|
||||
println('test')
|
||||
// NB: the anon function does NOT return explicitly,
|
||||
// so V should generate an implicit "OK" value and
|
||||
// return it. Previously, it created an implicit optional
|
||||
// filled with 0s => .ok was false, and that was treated
|
||||
// as a failure, triggering or blocks.
|
||||
// NB: the anon function does NOT return explicitly,
|
||||
// so V should generate an implicit "OK" value and
|
||||
// return it. Previously, it created an implicit optional
|
||||
// filled with 0s => .ok was false, and that was treated
|
||||
// as a failure, triggering or blocks.
|
||||
}
|
||||
should_not_call_block(x) ?
|
||||
assert true
|
||||
|
|
|
@ -2,7 +2,7 @@ import sync
|
|||
|
||||
fn test_go_anon_fn() {
|
||||
mut wg := sync.new_waitgroup()
|
||||
wg.add(1)
|
||||
wg.add(1)
|
||||
go fn (mut wg sync.WaitGroup) {
|
||||
wg.done()
|
||||
}(mut wg)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
struct Page {
|
||||
contents int
|
||||
contents int
|
||||
}
|
||||
|
||||
fn test_array_append_short_struct() {
|
||||
|
@ -8,7 +8,9 @@ fn test_array_append_short_struct() {
|
|||
contents: 3
|
||||
}
|
||||
println(pages)
|
||||
assert pages == [Page{contents: 3}]
|
||||
assert pages == [Page{
|
||||
contents: 3
|
||||
}]
|
||||
}
|
||||
|
||||
struct Container {
|
||||
|
@ -18,8 +20,12 @@ pub mut:
|
|||
|
||||
fn test_array_insert_or_prepend_short_struct() {
|
||||
mut a := []Container{}
|
||||
a.prepend({name: 'a'})
|
||||
a.insert(0, {name: 'b'})
|
||||
a.prepend(name: 'a')
|
||||
a.insert(0, name: 'b')
|
||||
println(a)
|
||||
assert a == [Container{name: 'b'}, Container{name: 'a'}]
|
||||
assert a == [Container{
|
||||
name: 'b'
|
||||
}, Container{
|
||||
name: 'a'
|
||||
}]
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ fn test_array_cast() {
|
|||
}
|
||||
|
||||
fn test_int() {
|
||||
mut arr := [2.3,3]
|
||||
mut arr := [2.3, 3]
|
||||
unsafe {
|
||||
vp := voidptr(&arr)
|
||||
p := &[]f64(vp)
|
||||
|
|
|
@ -4,7 +4,9 @@ struct Tester {
|
|||
}
|
||||
|
||||
enum Color {
|
||||
red green blue
|
||||
red
|
||||
green
|
||||
blue
|
||||
}
|
||||
|
||||
fn test_array_equality() {
|
||||
|
@ -52,15 +54,15 @@ fn test_nested_array_equality() {
|
|||
a2 := [[[[1]]]]
|
||||
assert a2 == [[[[1]]]]
|
||||
assert a2 != [[[[2]]]]
|
||||
a3 := [[[1,2,3]]]
|
||||
assert a3 == [[[1,2,3]]]
|
||||
assert a3 != [[[1,0,3]]]
|
||||
a3 := [[[1, 2, 3]]]
|
||||
assert a3 == [[[1, 2, 3]]]
|
||||
assert a3 != [[[1, 0, 3]]]
|
||||
a4 := [[1.1], [2.2]]
|
||||
assert a4 == [[1.1], [2.2]]
|
||||
assert a4 != [[2.1], [3.2]]
|
||||
a5 := [[[[1,2], [2,3], [3,4]]]]
|
||||
assert a5 == [[[[1,2], [2,3], [3,4]]]]
|
||||
assert a5 != [[[[2,2], [2,4], [3,4]]]]
|
||||
a5 := [[[[1, 2], [2, 3], [3, 4]]]]
|
||||
assert a5 == [[[[1, 2], [2, 3], [3, 4]]]]
|
||||
assert a5 != [[[[2, 2], [2, 4], [3, 4]]]]
|
||||
a6 := [[['aa', 'bb'], ['cc', 'dd']]]
|
||||
assert a6 == [[['aa', 'bb'], ['cc', 'dd']]]
|
||||
assert a6 != [[['a', 'b'], ['cc', 'dd']]]
|
||||
|
@ -76,6 +78,7 @@ fn test_nested_array_equality() {
|
|||
}
|
||||
|
||||
type Literal = string
|
||||
|
||||
type Literals = []Literal
|
||||
|
||||
fn (l1 Literal) concat(l2 Literal) Literals {
|
||||
|
|
|
@ -32,7 +32,7 @@ fn test_array_or_direct() {
|
|||
}
|
||||
|
||||
fn test_map_or() {
|
||||
m := {
|
||||
m := map{
|
||||
'as': 3
|
||||
'qw': 4
|
||||
'kl': 5
|
||||
|
@ -51,9 +51,12 @@ fn test_map_or() {
|
|||
assert good == 5
|
||||
}
|
||||
|
||||
|
||||
fn get_map_el(key string) ?int {
|
||||
m := {'as': 3, 'qw': 4, 'kl': 5}
|
||||
m := map{
|
||||
'as': 3
|
||||
'qw': 4
|
||||
'kl': 5
|
||||
}
|
||||
r := m[key] ?
|
||||
return r
|
||||
}
|
||||
|
@ -90,12 +93,8 @@ fn test_propagation() {
|
|||
testvar2 = 177
|
||||
int(-67)
|
||||
}
|
||||
m := get_arr_el_direct(3) or {
|
||||
17
|
||||
}
|
||||
n := get_arr_el_direct(0) or {
|
||||
-73
|
||||
}
|
||||
m := get_arr_el_direct(3) or { 17 }
|
||||
n := get_arr_el_direct(0) or { -73 }
|
||||
assert testvar1 == -34
|
||||
assert testvar2 == 99
|
||||
assert e == 7
|
||||
|
@ -114,8 +113,6 @@ fn get_arr_el_nested(i int) ?int {
|
|||
}
|
||||
|
||||
fn test_nested_array_propagation() {
|
||||
g := get_arr_el_nested(3) or {
|
||||
12
|
||||
}
|
||||
g := get_arr_el_nested(3) or { 12 }
|
||||
assert g == 12
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ fn test_array_map_ref() {
|
|||
mut m := map[string]int{}
|
||||
mut m_ref := &map[string]f64{}
|
||||
mut a := []int{len: 10}
|
||||
mut a_ref := &[]f64{cap: 12, len: 2}
|
||||
mut a_ref := &[]f64{len: 2, cap: 12}
|
||||
shared m_shared := &map[string]f64{}
|
||||
shared a_shared := &[]f64{cap: 12, len: 9}
|
||||
shared a_shared := &[]f64{len: 9, cap: 12}
|
||||
// test usage
|
||||
m['a'] = 3
|
||||
unsafe {
|
||||
|
|
|
@ -5,7 +5,9 @@ mut:
|
|||
|
||||
// if this is called more than once, the test'll fail
|
||||
fn (mut c Counter) new_arr(msg string) []int {
|
||||
if c.val > 0 { panic(msg) }
|
||||
if c.val > 0 {
|
||||
panic(msg)
|
||||
}
|
||||
c.val++
|
||||
return [1, 3, 2]
|
||||
}
|
||||
|
|
|
@ -43,20 +43,20 @@ fn test_fixed_array_slice() {
|
|||
fixed_array1 := [1, 2, 3]!
|
||||
arr1 := fixed_array1[0..]
|
||||
assert arr1 == [1, 2, 3]
|
||||
fixed_array2 := [[1, 2], [2, 3], [3, 4],[4, 5]]!
|
||||
fixed_array2 := [[1, 2], [2, 3], [3, 4], [4, 5]]!
|
||||
arr2 := fixed_array2[0..]
|
||||
assert arr2 == [[1, 2], [2, 3], [3, 4],[4, 5]]
|
||||
mut arr := [1,2,3]!
|
||||
assert arr2 == [[1, 2], [2, 3], [3, 4], [4, 5]]
|
||||
mut arr := [1, 2, 3]!
|
||||
fixed_array_slice(arr)
|
||||
mut_fixed_array_slice(mut arr)
|
||||
}
|
||||
|
||||
fn pointer_array_slice(mut a []int) {
|
||||
assert a[0..] == [1,2,3]
|
||||
assert a[..a.len] == [1,2,3]
|
||||
assert a[0..] == [1, 2, 3]
|
||||
assert a[..a.len] == [1, 2, 3]
|
||||
}
|
||||
|
||||
fn test_pointer_array_slice() {
|
||||
mut arr := [1,2,3]
|
||||
mut arr := [1, 2, 3]
|
||||
pointer_array_slice(mut arr)
|
||||
}
|
||||
|
|
|
@ -45,7 +45,13 @@ fn test_interpolation_array_to_string() {
|
|||
|
||||
fn test_interpolation_array_of_map_to_string() {
|
||||
mut ams := []map[string]string{}
|
||||
ams << {'a': 'b', 'c': 'd'}
|
||||
ams << {'e': 'f', 'g': 'h'}
|
||||
ams << map{
|
||||
'a': 'b'
|
||||
'c': 'd'
|
||||
}
|
||||
ams << map{
|
||||
'e': 'f'
|
||||
'g': 'h'
|
||||
}
|
||||
assert '$ams' == "[{'a': 'b', 'c': 'd'}, {'e': 'f', 'g': 'h'}]"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,16 @@
|
|||
const( str = 'abcdefghijklmnopqrstuvwxyz' num = 1234567890 )
|
||||
struct S1 { s1 string = str }
|
||||
struct S2 { s2 int = num }
|
||||
const (
|
||||
str = 'abcdefghijklmnopqrstuvwxyz'
|
||||
num = 1234567890
|
||||
)
|
||||
|
||||
struct S1 {
|
||||
s1 string = str
|
||||
}
|
||||
|
||||
struct S2 {
|
||||
s2 int = num
|
||||
}
|
||||
|
||||
type Sum = S1 | S2
|
||||
|
||||
fn test_as_cast_with_sumtype_fn_result() {
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
struct Moon {}
|
||||
|
||||
struct Mars {}
|
||||
|
||||
type World = Moon | Mars
|
||||
type World = Mars | Moon
|
||||
|
||||
fn test_assert_sumtype() {
|
||||
w := World(Moon{})
|
||||
|
|
|
@ -22,9 +22,7 @@ pub enum PubEnumAttrTest {
|
|||
two
|
||||
}
|
||||
|
||||
|
||||
[attrone]
|
||||
[attrtwo]
|
||||
[attrone; attrtwo]
|
||||
pub enum EnumMultiAttrTest {
|
||||
one
|
||||
two
|
||||
|
@ -40,8 +38,7 @@ pub fn test_pub_fn_attribute() {
|
|||
assert true
|
||||
}
|
||||
|
||||
[attrone]
|
||||
[attrtwo]
|
||||
[attrone; attrtwo]
|
||||
fn test_fn_multi_attribute() {
|
||||
assert true
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Test for backtrace capability
|
||||
Test for backtrace capability
|
||||
*/
|
||||
fn a_method() {
|
||||
print_backtrace()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
struct Object {
|
||||
name string
|
||||
name string
|
||||
value int
|
||||
}
|
||||
|
||||
|
@ -32,61 +32,51 @@ fn test_assign_multi_expr() {
|
|||
val2 := 2
|
||||
|
||||
// simple case for match
|
||||
a,b,c := match false {
|
||||
true { 1,2,3 }
|
||||
false { 4,5,6 }
|
||||
a, b, c := match false {
|
||||
true { 1, 2, 3 }
|
||||
false { 4, 5, 6 }
|
||||
}
|
||||
assert a == 4
|
||||
assert b == 5
|
||||
assert c == 6
|
||||
|
||||
// test with first value `literal`
|
||||
d, e, f := if true {
|
||||
1, 'awesome', [13]
|
||||
} else {
|
||||
0, 'bad', [0]
|
||||
}
|
||||
d, e, f := if true { 1, 'awesome', [13] } else { 0, 'bad', [0] }
|
||||
assert d == 1
|
||||
assert e == 'awesome'
|
||||
assert f == [13]
|
||||
|
||||
// test with first value `literal expr` and statement
|
||||
awesome := 'awesome'
|
||||
g, h, i := if true {
|
||||
1 + val1, awesome, [13]
|
||||
} else {
|
||||
int(0), 'bad', [0]
|
||||
}
|
||||
g, h, i := if true { 1 + val1, awesome, [13] } else { int(0), 'bad', [0] }
|
||||
assert g == 2
|
||||
assert h == 'awesome'
|
||||
assert i == [13]
|
||||
|
||||
// test with first value `.name`
|
||||
j, k, l := if true {
|
||||
val1, 'awesome', [13]
|
||||
} else {
|
||||
val2, 'bad', [0]
|
||||
}
|
||||
j, k, l := if true { val1, 'awesome', [13] } else { val2, 'bad', [0] }
|
||||
assert j == 1
|
||||
assert k == 'awesome'
|
||||
assert l == [13]
|
||||
|
||||
// test with first value name and peek != .comma
|
||||
m, n, o := if true {
|
||||
val1 + 1, val1, val1
|
||||
} else {
|
||||
val2, val2, val2
|
||||
}
|
||||
m, n, o := if true { val1 + 1, val1, val1 } else { val2, val2, val2 }
|
||||
assert m == val1 + 1
|
||||
assert n == val1
|
||||
assert o == val1
|
||||
|
||||
// test practical complex expressions
|
||||
val3 := Object { name: 'initial', value: 19 }
|
||||
val3 := Object{
|
||||
name: 'initial'
|
||||
value: 19
|
||||
}
|
||||
mut q, mut r, mut s := if true {
|
||||
1 + 1, 'awe' + 'some', Object{ ...val3, name: 'ok' }
|
||||
1 + 1, 'awe' + 'some', Object{
|
||||
...val3
|
||||
name: 'ok'
|
||||
}
|
||||
} else {
|
||||
0, '0', Object {}
|
||||
0, '0', Object{}
|
||||
}
|
||||
assert q == 2
|
||||
assert r == 'awesome'
|
||||
|
@ -95,9 +85,12 @@ fn test_assign_multi_expr() {
|
|||
|
||||
// test assign to existing variables
|
||||
q, r, s = if false {
|
||||
0, '0', Object {}
|
||||
0, '0', Object{}
|
||||
} else {
|
||||
5, '55', Object{ ...val3, value: 555 }
|
||||
5, '55', Object{
|
||||
...val3
|
||||
value: 555
|
||||
}
|
||||
}
|
||||
assert q == 5
|
||||
assert r == '55'
|
||||
|
@ -106,7 +99,7 @@ fn test_assign_multi_expr() {
|
|||
}
|
||||
|
||||
fn test_issue_9330() {
|
||||
arr := "0.1".split('.')
|
||||
arr := '0.1'.split('.')
|
||||
a0, a1 := arr[0], arr[1].int()
|
||||
assert a0 == '0'
|
||||
assert a1 == 1
|
||||
|
@ -119,5 +112,4 @@ fn test_issue_9330() {
|
|||
d0, d1 := arr[0].int(), arr[1].f64()
|
||||
assert d0 == 0
|
||||
assert d1 == 1.0
|
||||
|
||||
}
|
||||
|
|
|
@ -3,12 +3,15 @@ struct Test {}
|
|||
fn (test Test) v() {
|
||||
println('Test.v()')
|
||||
}
|
||||
|
||||
fn (test Test) i() int {
|
||||
return 4
|
||||
}
|
||||
|
||||
fn (test Test) s() string {
|
||||
return 'test'
|
||||
}
|
||||
|
||||
fn (test Test) s2() string {
|
||||
return 'Two'
|
||||
}
|
||||
|
@ -33,15 +36,13 @@ fn test_for_methods() {
|
|||
$if method.return_type is string {
|
||||
v := test.$method()
|
||||
r += v.str()
|
||||
}
|
||||
$else $if method.return_type is int {
|
||||
} $else $if method.return_type is int {
|
||||
// TODO
|
||||
//v := test.$method()
|
||||
// v := test.$method()
|
||||
v := '?'
|
||||
r += v.str()
|
||||
assert method.name == 'i'
|
||||
}
|
||||
$else {
|
||||
} $else {
|
||||
// no return type
|
||||
test.$method()
|
||||
assert method.name == 'v'
|
||||
|
@ -64,4 +65,3 @@ fn test_methods_arg() {
|
|||
assert r == '!!!'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,4 +26,3 @@ fn test_is_or() {
|
|||
assert g(i8(1)) == 1
|
||||
assert g(1) == 2
|
||||
}
|
||||
|
||||
|
|
|
@ -8,9 +8,11 @@ mut:
|
|||
fn (mut t TestStruct) one_arg(a1 string) {
|
||||
t.one_arg_called = true
|
||||
}
|
||||
|
||||
fn (mut t TestStruct) two_args(a2 string, b2 int) {
|
||||
t.two_args_called = true
|
||||
}
|
||||
|
||||
fn (mut t TestStruct) three_args(a3 string, b3 int, c3 []string) {
|
||||
t.three_args_called = true
|
||||
}
|
||||
|
@ -43,7 +45,7 @@ fn test_comptime_call_method() {
|
|||
} else if method.name == 'two_args' {
|
||||
t.$method('two', 2)
|
||||
} else if method.name == 'three_args' {
|
||||
t.$method('three', 3, ['th' 'ree'])
|
||||
t.$method('three', 3, ['th', 'ree'])
|
||||
}
|
||||
}
|
||||
assert t.one_arg_called
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
pub const (
|
||||
pub const (
|
||||
a = b
|
||||
c = a + b
|
||||
b = 1
|
||||
|
@ -26,7 +26,7 @@ fn foo_decode(name string) ?Foo {
|
|||
return Foo{name}
|
||||
}
|
||||
|
||||
pub const (
|
||||
pub const (
|
||||
def = foo_decode('baz') or { Foo{} }
|
||||
bar = foo_decode('bar') ?
|
||||
)
|
||||
|
|
|
@ -8,7 +8,7 @@ fn test_conv_to_bool() {
|
|||
assert int(b) == 1
|
||||
|
||||
// branchless tests (can be important for manual optimization)
|
||||
arr := [7,8]!
|
||||
arr := [7, 8]!
|
||||
e := arr[int(b)]
|
||||
assert e == 8
|
||||
b = e < 0
|
||||
|
|
|
@ -18,7 +18,7 @@ fn foo1(mut arr []int) {
|
|||
}
|
||||
|
||||
fn test_cross_assign_of_array_in_fn() {
|
||||
mut arr := [1,2]
|
||||
mut arr := [1, 2]
|
||||
foo1(mut arr)
|
||||
assert arr[0] == 2
|
||||
assert arr[1] == 1
|
||||
|
@ -26,7 +26,10 @@ fn test_cross_assign_of_array_in_fn() {
|
|||
|
||||
// Test cross assign of map values
|
||||
fn test_cross_assign_of_map() {
|
||||
mut a := {'one':1, 'two':2}
|
||||
mut a := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
}
|
||||
a['one'], a['two'] = a['two'], a['one']
|
||||
println(a)
|
||||
assert a['one'] == 2
|
||||
|
@ -39,7 +42,10 @@ fn foo2(mut a map[string]int) {
|
|||
}
|
||||
|
||||
fn test_cross_assign_of_map_in_fn() {
|
||||
mut a := {'one':1, 'two':2}
|
||||
mut a := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
}
|
||||
foo2(mut a)
|
||||
assert a['one'] == 2
|
||||
assert a['two'] == 1
|
||||
|
@ -53,9 +59,12 @@ mut:
|
|||
}
|
||||
|
||||
fn test_cross_assign_of_struct() {
|
||||
mut x := Zoo{a:1, b:2}
|
||||
mut x := Zoo{
|
||||
a: 1
|
||||
b: 2
|
||||
}
|
||||
x.a, x.b = x.b, x.a
|
||||
//println(x)
|
||||
// println(x)
|
||||
assert x.a == 2
|
||||
assert x.b == 1
|
||||
}
|
||||
|
@ -72,7 +81,10 @@ fn foo3(mut f Foo) {
|
|||
}
|
||||
|
||||
fn test_cross_assign_of_struct_in_fn() {
|
||||
mut a := Foo{a:1, b:2}
|
||||
mut a := Foo{
|
||||
a: 1
|
||||
b: 2
|
||||
}
|
||||
foo3(mut a)
|
||||
println(a)
|
||||
assert a.a == 2
|
||||
|
@ -82,8 +94,14 @@ fn test_cross_assign_of_struct_in_fn() {
|
|||
// Test cross assign of mixed types
|
||||
fn test_cross_assign_of_mixed_types() {
|
||||
mut a := [0, 1]
|
||||
mut m := {'one':1, 'two':2}
|
||||
mut x := Zoo{a:1, b:2}
|
||||
mut m := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
}
|
||||
mut x := Zoo{
|
||||
a: 1
|
||||
b: 2
|
||||
}
|
||||
|
||||
a[0], m['one'], x.a, a[1], m['two'], x.b = a[1], m['two'], x.b, a[0], m['one'], x.a
|
||||
|
||||
|
@ -95,14 +113,20 @@ fn test_cross_assign_of_mixed_types() {
|
|||
}
|
||||
|
||||
// Test cross assign of mixed types in function
|
||||
fn foo(mut a []int, mut m map[string]int, mut x Zoo) {
|
||||
fn foo(mut a []int, mut m map[string]int, mut x Zoo) {
|
||||
a[0], m['one'], x.a, a[1], m['two'], x.b = a[1], m['two'], x.b, a[0], m['one'], x.a
|
||||
}
|
||||
|
||||
fn test_cross_assign_of_mixed_types_in_fn() {
|
||||
mut a := [0, 1]
|
||||
mut m := {'one':1, 'two':2}
|
||||
mut x := Zoo{a:1, b:2}
|
||||
mut m := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
}
|
||||
mut x := Zoo{
|
||||
a: 1
|
||||
b: 2
|
||||
}
|
||||
|
||||
foo(mut a, mut m, mut x)
|
||||
|
||||
|
@ -116,10 +140,16 @@ fn test_cross_assign_of_mixed_types_in_fn() {
|
|||
// Test cross assign of complex types
|
||||
fn test_cross_assign_of_complex_types() {
|
||||
mut a := [0, 1]
|
||||
mut m := {'one':1, 'two':2}
|
||||
mut x := Zoo{a:1, b:2}
|
||||
mut m := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
}
|
||||
mut x := Zoo{
|
||||
a: 1
|
||||
b: 2
|
||||
}
|
||||
|
||||
a[0], m['one'], x.a, a[1], m['two'], x.b = a[1]+1, -m['two'], x.b, a[0]*2, m['one']*3, x.a-x.b
|
||||
a[0], m['one'], x.a, a[1], m['two'], x.b = a[1] + 1, -m['two'], x.b, a[0] * 2, m['one'] * 3, x.a - x.b
|
||||
|
||||
assert a == [2, 0]
|
||||
assert m['one'] == -2
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
fn test_cstring() {
|
||||
w := c'world'
|
||||
hlen := unsafe{ C.strlen(c'hello') }
|
||||
hlen2 := unsafe{ C.strlen('hello') }
|
||||
wlen := unsafe{ C.strlen(w) }
|
||||
hlen := unsafe { C.strlen(c'hello') }
|
||||
hlen2 := unsafe { C.strlen('hello') }
|
||||
wlen := unsafe { C.strlen(w) }
|
||||
assert hlen == 5
|
||||
assert hlen2 == 5
|
||||
assert wlen == 5
|
||||
|
|
|
@ -59,7 +59,7 @@ fn test_defer_early_exit() {
|
|||
|
||||
fn test_defer_option() {
|
||||
mut ok := Num{0}
|
||||
set_num_opt(mut ok) or { }
|
||||
set_num_opt(mut ok) or {}
|
||||
assert ok.val == 1
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ fn test_enum_non_default_value() {
|
|||
assert 't.e: $t.e | int(t.e): ${int(t.e).str()}' == 't.e: third | int(t.e): 22'
|
||||
}
|
||||
|
||||
fn test_generation_of_string_interpolation_method_for_pointer_to_struct_containing_enum_fields(){
|
||||
fn test_generation_of_string_interpolation_method_for_pointer_to_struct_containing_enum_fields() {
|
||||
t := &MyStruct{
|
||||
e: .third
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ fn test_fixed_array_can_be_assigned() {
|
|||
x := 2.32
|
||||
mut v := [8]f64{}
|
||||
assert v[1] == 0
|
||||
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
|
||||
v[1] = 2.0
|
||||
for i, e in v {
|
||||
|
@ -41,14 +41,13 @@ fn test_fixed_array_assignment() {
|
|||
|
||||
fn test_fixed_array_can_be_used_in_declaration() {
|
||||
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.len == 8
|
||||
assert v[1] == x
|
||||
}
|
||||
|
||||
|
||||
struct Context {
|
||||
pub mut:
|
||||
pub mut:
|
||||
vb [8]f64
|
||||
}
|
||||
|
||||
|
@ -72,7 +71,7 @@ fn test_fixed_array_can_be_assigned_to_a_struct_field() {
|
|||
}
|
||||
|
||||
fn multiply_by_two(mut arr [3]int) {
|
||||
for i in 0..arr.len {
|
||||
for i in 0 .. arr.len {
|
||||
arr[i] *= 2
|
||||
}
|
||||
}
|
||||
|
@ -82,12 +81,12 @@ fn change_first_element(mut arr [3][3]int) {
|
|||
}
|
||||
|
||||
fn test_fixed_array_can_be_passed_as_mut_arg() {
|
||||
mut arr := [1,2,3]!
|
||||
mut arr := [1, 2, 3]!
|
||||
multiply_by_two(mut arr)
|
||||
assert arr == [2,4,6]!
|
||||
mut arr2 := [[1,2,3]!, [4,5,6]!, [7,8,9]!]!
|
||||
assert arr == [2, 4, 6]!
|
||||
mut arr2 := [[1, 2, 3]!, [4, 5, 6]!, [7, 8, 9]!]!
|
||||
change_first_element(mut arr2)
|
||||
assert arr2 == [[0,2,3]!, [4,5,6]!, [7,8,9]!]!
|
||||
assert arr2 == [[0, 2, 3]!, [4, 5, 6]!, [7, 8, 9]!]!
|
||||
}
|
||||
|
||||
fn test_iteration_over_fixed_array() {
|
||||
|
@ -117,7 +116,6 @@ fn calc_size(a [3]int) {
|
|||
}
|
||||
|
||||
fn test_for_in_fixed_array() {
|
||||
arr := [1,2,3]!
|
||||
arr := [1, 2, 3]!
|
||||
calc_size(arr)
|
||||
}
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@ fn test1() int {
|
|||
fn test_fn_assignment_var() {
|
||||
mut a := 0
|
||||
mut b := 0
|
||||
a , b = test(), test1()
|
||||
|
||||
assert a == 10
|
||||
a, b = test(), test1()
|
||||
|
||||
assert a == 10
|
||||
assert b == 11
|
||||
|
||||
a, b = test(), test()
|
||||
|
@ -20,13 +20,13 @@ fn test_fn_assignment_var() {
|
|||
|
||||
a, b = test(), 12
|
||||
|
||||
assert a == 10
|
||||
assert a == 10
|
||||
assert b == 12
|
||||
|
||||
a, b = 12, test()
|
||||
|
||||
assert a == 12
|
||||
assert b == 10
|
||||
assert b == 10
|
||||
}
|
||||
|
||||
fn test_fn_assignment_array() {
|
||||
|
@ -34,22 +34,20 @@ fn test_fn_assignment_array() {
|
|||
|
||||
a[0], a[1] = test(), test1()
|
||||
|
||||
assert a[0] == 10
|
||||
assert a[0] == 10
|
||||
assert a[1] == 11
|
||||
|
||||
a[0], a[1] = test() , test()
|
||||
a[0], a[1] = test(), test()
|
||||
|
||||
assert a[0] == 10
|
||||
assert a[1] == 10
|
||||
assert a[0] == 10
|
||||
assert a[1] == 10
|
||||
|
||||
a[0], a[1] = test(), 12
|
||||
|
||||
assert a[0] == 10
|
||||
assert a[1] == 12
|
||||
assert a[0] == 10
|
||||
assert a[1] == 12
|
||||
|
||||
a[0], a[1] = 12 , test()
|
||||
assert a[0] == 12
|
||||
a[0], a[1] = 12, test()
|
||||
assert a[0] == 12
|
||||
assert a[1] == 10
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
|
||||
fn cross_assign_anon_fn_one (a int, b bool) string {
|
||||
fn cross_assign_anon_fn_one(a int, b bool) string {
|
||||
return 'one'
|
||||
}
|
||||
|
||||
fn cross_assign_anon_fn_two (a int, b bool) string {
|
||||
fn cross_assign_anon_fn_two(a int, b bool) string {
|
||||
return 'two'
|
||||
}
|
||||
|
||||
|
@ -23,11 +22,11 @@ fn cross_assign_anon_fn_six(a ...int) string {
|
|||
return 'six'
|
||||
}
|
||||
|
||||
fn cross_assign_anon_fn_seven (a int, b bool) string {
|
||||
fn cross_assign_anon_fn_seven(a int, b bool) string {
|
||||
return 'seven'
|
||||
}
|
||||
|
||||
fn cross_assign_anon_fn_eight (a int, b bool) string {
|
||||
fn cross_assign_anon_fn_eight(a int, b bool) string {
|
||||
return 'eight'
|
||||
}
|
||||
|
||||
|
@ -37,7 +36,7 @@ fn test_cross_assign_anon_fn() {
|
|||
one, two = two, one
|
||||
foo := two(0, true) + one(0, true)
|
||||
assert foo == 'onetwo'
|
||||
|
||||
|
||||
mut three := cross_assign_anon_fn_three
|
||||
mut four := cross_assign_anon_fn_four
|
||||
three, four = four, three
|
||||
|
@ -47,20 +46,20 @@ fn test_cross_assign_anon_fn() {
|
|||
foo3 += foo5
|
||||
assert foo2 == 'threefour'
|
||||
assert foo3 == 'threefour'
|
||||
|
||||
|
||||
mut five := cross_assign_anon_fn_five
|
||||
mut six := cross_assign_anon_fn_six
|
||||
five, six = six, five
|
||||
foo6 := six(1, 2, 3) + five(1, 2, 3)
|
||||
assert foo6 == 'fivesix'
|
||||
|
||||
|
||||
one, two, three, four, five, six = two, one, four, three, six, five
|
||||
mut foo7, _ := three()
|
||||
foo8, _ := four()
|
||||
foo7 += foo8
|
||||
foo9 := one(0, true) + two(0, true) + foo7 + five(1, 2, 3) + six(1, 2, 3)
|
||||
assert foo9 == 'onetwothreefourfivesix'
|
||||
|
||||
|
||||
mut seven := cross_assign_anon_fn_seven
|
||||
mut eight := cross_assign_anon_fn_eight
|
||||
one, two, seven, eight = two, seven, eight, one
|
||||
|
|
|
@ -2,10 +2,12 @@ struct Foo {
|
|||
x int
|
||||
}
|
||||
|
||||
pub fn (f Foo) str() string { return 'Foo{}' }
|
||||
pub fn (f Foo) str() string {
|
||||
return 'Foo{}'
|
||||
}
|
||||
|
||||
fn process_foo(foo &Foo) {
|
||||
println('>process_foo, called for ${foo} === ${*foo}')
|
||||
println('>process_foo, called for $foo === ${*foo}')
|
||||
}
|
||||
|
||||
fn get_foo() Foo {
|
||||
|
|
|
@ -3,50 +3,51 @@ fn sqr(x int) int {
|
|||
return x * x
|
||||
}
|
||||
|
||||
fn high_fn(f fn(int) int) {
|
||||
fn high_fn(f fn (int) int) {
|
||||
x := f(111)
|
||||
println('x == $x')
|
||||
}
|
||||
|
||||
fn high_fn_no_ret(f fn(int)) {
|
||||
fn high_fn_no_ret(f fn (int)) {
|
||||
f(111)
|
||||
}
|
||||
|
||||
fn high_fn_array(f fn(a []int) []int) {
|
||||
|
||||
}
|
||||
|
||||
fn high_fn_multi_return(a int, b fn (c []int, d []string) ([]int, []string)) {
|
||||
|
||||
}
|
||||
|
||||
fn high_fn_return_single_anon() (fn(int)f32) {
|
||||
fn high_fn_return_single_anon() fn (int) f32 {
|
||||
_ = 1
|
||||
correct := fn(n int)f32 {
|
||||
correct := fn (n int) f32 {
|
||||
return f32(n * n)
|
||||
}
|
||||
return correct
|
||||
}
|
||||
fn high_fn_return_multi_anons() (fn(int)f32, fn(int)string) {
|
||||
|
||||
fn high_fn_return_multi_anons() (fn (int) f32, fn (int) string) {
|
||||
// parsing trap
|
||||
_ = fn(n int)byte {
|
||||
_ = fn (n int) byte {
|
||||
return 0x00
|
||||
}
|
||||
correct_second := fn(n int)string {
|
||||
correct_second := fn (n int) string {
|
||||
return '$n'
|
||||
}
|
||||
correct_first := fn(n int)f32 {
|
||||
correct_first := fn (n int) f32 {
|
||||
return f32(n * n)
|
||||
}
|
||||
// parsing trap
|
||||
_ = fn(n int)[]int {
|
||||
_ = fn (n int) []int {
|
||||
return [n]
|
||||
}
|
||||
return correct_first, correct_second
|
||||
}
|
||||
fn high_fn_return_named_fn() (fn(int)int) {
|
||||
|
||||
fn high_fn_return_named_fn() fn (int) int {
|
||||
return sqr
|
||||
}
|
||||
|
||||
fn test_high_fn_ret_anons() {
|
||||
param := 13
|
||||
func_sqr1 := high_fn_return_single_anon()
|
||||
|
@ -63,6 +64,7 @@ fn test_high_fn_ret_anons() {
|
|||
fn high_fn_applier(arg int, func fn(a int)string) string {
|
||||
return func(arg)
|
||||
}
|
||||
|
||||
fn test_high_fn_applier() {
|
||||
arg := 13
|
||||
expect := '$arg $arg'
|
||||
|
@ -78,12 +80,12 @@ fn test_fns() {
|
|||
}
|
||||
|
||||
fn test_anon_fn() {
|
||||
f1 := fn(a int){
|
||||
f1 := fn (a int) {
|
||||
println('hello from f1')
|
||||
}
|
||||
f1(1)
|
||||
|
||||
f2 := fn(a int) int {
|
||||
f2 := fn (a int) int {
|
||||
println('hello from f2')
|
||||
return 10
|
||||
}
|
||||
|
@ -102,12 +104,12 @@ fn test_anon_fn() {
|
|||
}
|
||||
|
||||
fn test_anon_fn_direct_call() {
|
||||
fn(name string) {
|
||||
fn (name string) {
|
||||
println('hello $name')
|
||||
}('from anon')
|
||||
|
||||
b := fn(n int) int {
|
||||
return 11+n
|
||||
|
||||
b := fn (n int) int {
|
||||
return 11 + n
|
||||
}(100)
|
||||
assert b == 111
|
||||
}
|
||||
|
@ -121,7 +123,7 @@ fn simple_fn1() int {
|
|||
}
|
||||
|
||||
fn simple_fn2(n f32) (int, string) {
|
||||
return int(1 + n), "fish"
|
||||
return int(1 + n), 'fish'
|
||||
}
|
||||
|
||||
fn test_assigning_fns() {
|
||||
|
@ -131,13 +133,13 @@ fn test_assigning_fns() {
|
|||
func2 := simple_fn2
|
||||
res2_1, res2_2 := func2(13.0)
|
||||
assert res2_1 == 14.0
|
||||
assert res2_2 == "fish"
|
||||
assert res2_2 == 'fish'
|
||||
|
||||
anon_func1 := fn(s string)int {
|
||||
anon_func1 := fn (s string) int {
|
||||
return s.len
|
||||
}
|
||||
func3 := anon_func1
|
||||
res3 := func3("fish")
|
||||
res3 := func3('fish')
|
||||
assert res3 == 4
|
||||
}
|
||||
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
struct Placeholder {
|
||||
name string
|
||||
name string
|
||||
}
|
||||
|
||||
struct FnStruct {
|
||||
mut:
|
||||
array_of_fn []fn(int, &Placeholder, string)bool
|
||||
array_of_fn []fn (int, &Placeholder, string) bool
|
||||
}
|
||||
|
||||
fn test_fn_array_direct_call() {
|
||||
mut fs := FnStruct{}
|
||||
fs.array_of_fn << fn(x int, y &Placeholder, z string) bool {
|
||||
return false
|
||||
}
|
||||
mut fs := FnStruct{}
|
||||
fs.array_of_fn << fn (x int, y &Placeholder, z string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
println(fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder'))
|
||||
assert fs.array_of_fn[0](1, &Placeholder{name: 'Bob'}, 'Builder') == false
|
||||
println(fs.array_of_fn[0](1, &Placeholder{ name: 'Bob' }, 'Builder'))
|
||||
assert fs.array_of_fn[0](1, &Placeholder{ name: 'Bob' }, 'Builder') == false
|
||||
}
|
||||
|
||||
fn test_fn_map_direct_call() {
|
||||
a := {
|
||||
'aaa': fn()string {return 'aaa'},
|
||||
'bbb': fn()string {return 'bbb'},
|
||||
a := map{
|
||||
'aaa': fn () string {
|
||||
return 'aaa'
|
||||
}
|
||||
'bbb': fn () string {
|
||||
return 'bbb'
|
||||
}
|
||||
}
|
||||
println(a['aaa']())
|
||||
println(a['bbb']())
|
||||
assert a['aaa']() == 'aaa'
|
||||
assert a['bbb']() == 'bbb'
|
||||
println(a['bbb']())
|
||||
assert a['aaa']() == 'aaa'
|
||||
assert a['bbb']() == 'bbb'
|
||||
}
|
||||
|
|
|
@ -14,7 +14,9 @@ fn test_fn_multiple_returns() {
|
|||
|
||||
fn fn_mr_get_user() (string, int, []string, UserData) {
|
||||
groups := ['admins', 'users']
|
||||
data := UserData{test: 'Test Data'}
|
||||
data := UserData{
|
||||
test: 'Test Data'
|
||||
}
|
||||
return 'joe', 34, groups, data
|
||||
}
|
||||
|
||||
|
@ -30,9 +32,7 @@ fn split_to_two(s string) ?(string, string) {
|
|||
}
|
||||
|
||||
fn returnable_fail() string {
|
||||
_,_ := split_to_two('bad') or {
|
||||
return 'ok'
|
||||
}
|
||||
_, _ := split_to_two('bad') or { return 'ok' }
|
||||
return 'nok'
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ fn test_multiple_ret() {
|
|||
assert returnable_fail() == 'ok'
|
||||
|
||||
// good case
|
||||
res1_1, res1_2 := split_to_two("fish house") or {
|
||||
res1_1, res1_2 := split_to_two('fish house') or {
|
||||
assert false
|
||||
return
|
||||
}
|
||||
|
@ -49,8 +49,8 @@ fn test_multiple_ret() {
|
|||
assert res1_2 == 'house'
|
||||
|
||||
// none case
|
||||
wrapper1 := fn()(string, string){
|
||||
res2_1, res2_2 := split_to_two("") or {
|
||||
wrapper1 := fn () (string, string) {
|
||||
res2_1, res2_2 := split_to_two('') or {
|
||||
assert err.msg == ''
|
||||
return 'replaced', 'val'
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ fn test_multiple_ret() {
|
|||
assert res2_2 == 'val'
|
||||
|
||||
// error case
|
||||
wrapper2 := fn()(string, string){
|
||||
wrapper2 := fn () (string, string) {
|
||||
res3_1, res3_2 := split_to_two('fishhouse') or {
|
||||
assert err.msg == 'error'
|
||||
return 'replaced', 'val'
|
||||
|
|
|
@ -12,12 +12,16 @@ fn test_fn_mut_args_of_array() {
|
|||
}
|
||||
|
||||
fn init_map(mut n map[string]int) {
|
||||
n = {'one': 1}
|
||||
n = map{
|
||||
'one': 1
|
||||
}
|
||||
}
|
||||
|
||||
fn test_fn_mut_args_of_map() {
|
||||
mut m := map[string]int{}
|
||||
init_map(mut m)
|
||||
println(m)
|
||||
assert m == {'one': 1}
|
||||
assert m == map{
|
||||
'one': 1
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ mut:
|
|||
}
|
||||
|
||||
fn f() shared St {
|
||||
shared x := St{ x: 3.25 }
|
||||
shared x := St{
|
||||
x: 3.25
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -12,19 +14,25 @@ fn g(good bool) ?shared St {
|
|||
if !good {
|
||||
return error('no shared St created')
|
||||
}
|
||||
shared x := St{ x: 12.75 }
|
||||
shared x := St{
|
||||
x: 12.75
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fn test_shared_fn_return() {
|
||||
shared x := f()
|
||||
val := rlock x { x.x }
|
||||
val := rlock x {
|
||||
x.x
|
||||
}
|
||||
assert val == 3.25
|
||||
}
|
||||
|
||||
fn shared_opt_propagate(good bool) ?f64 {
|
||||
shared x := g(good) ?
|
||||
ret := rlock x { x.x }
|
||||
ret := rlock x {
|
||||
x.x
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
@ -37,18 +45,26 @@ fn test_shared_opt_propagate() {
|
|||
|
||||
fn test_shared_opt_good() {
|
||||
shared yy := g(true) or {
|
||||
shared my_default := St{ x: 37.5 }
|
||||
my_default
|
||||
shared my_default := St{
|
||||
x: 37.5
|
||||
}
|
||||
my_default
|
||||
}
|
||||
val := rlock yy {
|
||||
yy.x
|
||||
}
|
||||
val := rlock yy { yy.x }
|
||||
assert val == 12.75
|
||||
}
|
||||
|
||||
fn test_shared_opt_bad() {
|
||||
shared yy := g(false) or {
|
||||
shared my_default := St{ x: 37.5 }
|
||||
my_default
|
||||
shared my_default := St{
|
||||
x: 37.5
|
||||
}
|
||||
my_default
|
||||
}
|
||||
val := rlock yy {
|
||||
yy.x
|
||||
}
|
||||
val := rlock yy { yy.x }
|
||||
assert val == 37.5
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ fn foo2(a string) int {
|
|||
}
|
||||
|
||||
fn bar1(mut a [1]fn (string) int) int {
|
||||
a[0] = foo2
|
||||
a[0] = foo2
|
||||
return a[0]('hello')
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
fn test_for_c_multi_init_vars() {
|
||||
mut rets := []string{}
|
||||
for a,b := 0,1; a < 5; a++ {
|
||||
for a, b := 0, 1; a < 5; a++ {
|
||||
if a == 3 {
|
||||
continue
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn test_for_c_multi_init_vars() {
|
|||
fn test_for_c_multi_inc_vars() {
|
||||
mut rets := []string{}
|
||||
mut b := 1
|
||||
for a := 0; a < 10; a,b = b,a+b {
|
||||
for a := 0; a < 10; a, b = b, a + b {
|
||||
if a in [2, 3] {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -64,7 +64,11 @@ fn test_for_in_fixed_array_of_fixed_array_literal() {
|
|||
|
||||
fn test_for_in_map_of_fixed_array() {
|
||||
mut rets := []string{}
|
||||
m := map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!}
|
||||
m := map{
|
||||
'aa': [1, 2]!
|
||||
'bb': [3, 4]!
|
||||
'cc': [5, 6]!
|
||||
}
|
||||
|
||||
for k, v in m {
|
||||
println('$k, $v')
|
||||
|
@ -78,7 +82,11 @@ fn test_for_in_map_of_fixed_array() {
|
|||
fn test_for_in_map_of_fixed_array_literal() {
|
||||
mut rets := []string{}
|
||||
|
||||
for k, v in map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!} {
|
||||
for k, v in map{
|
||||
'aa': [1, 2]!
|
||||
'bb': [3, 4]!
|
||||
'cc': [5, 6]!
|
||||
} {
|
||||
println('$k, $v')
|
||||
rets << '$k, $v'
|
||||
}
|
||||
|
@ -89,7 +97,11 @@ fn test_for_in_map_of_fixed_array_literal() {
|
|||
|
||||
fn test_for_mut_in_map_of_fixed_array() {
|
||||
mut rets := []string{}
|
||||
mut m := map{'aa': [1, 2]!, 'bb': [3, 4]!, 'cc': [5, 6]!}
|
||||
mut m := map{
|
||||
'aa': [1, 2]!
|
||||
'bb': [3, 4]!
|
||||
'cc': [5, 6]!
|
||||
}
|
||||
|
||||
for k, mut v in m {
|
||||
println('$k, $v')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
struct Doubler {
|
||||
mut:
|
||||
val int
|
||||
val int
|
||||
until int
|
||||
}
|
||||
|
||||
|
|
|
@ -18,40 +18,47 @@ fn foo2(mut arr [3]int) {
|
|||
}
|
||||
|
||||
fn test_for_in_mut_val_of_fixed_array() {
|
||||
mut arr := [1,2,3]!
|
||||
mut arr := [1, 2, 3]!
|
||||
foo2(mut arr)
|
||||
println(arr)
|
||||
assert arr == [2, 4, 6]!
|
||||
}
|
||||
|
||||
fn foo3(mut m map[string][3]int){
|
||||
for i in 0..m['hello'].len {
|
||||
fn foo3(mut m map[string][3]int) {
|
||||
for i in 0 .. m['hello'].len {
|
||||
m['hello'][i] *= 2
|
||||
}
|
||||
}
|
||||
|
||||
fn test_fn_mut_val_of_map() {
|
||||
mut m := {'hello': [1,2,3]!}
|
||||
mut m := map{
|
||||
'hello': [1, 2, 3]!
|
||||
}
|
||||
foo3(mut m)
|
||||
println(m)
|
||||
assert '$m' == "{'hello': [2, 4, 6]}"
|
||||
}
|
||||
|
||||
fn foo4(mut m map[string][3]int){
|
||||
fn foo4(mut m map[string][3]int) {
|
||||
for _, mut j in m['hello'] {
|
||||
j *= 2
|
||||
}
|
||||
}
|
||||
|
||||
fn test_for_in_mut_val_of_map() {
|
||||
mut m := {'hello':[1,2,3]!}
|
||||
mut m := map{
|
||||
'hello': [1, 2, 3]!
|
||||
}
|
||||
foo4(mut m)
|
||||
println(m)
|
||||
assert '$m' == "{'hello': [2, 4, 6]}"
|
||||
}
|
||||
|
||||
fn test_for_in_mut_val_of_map_direct() {
|
||||
mut m := {'foo': 1, 'bar': 2}
|
||||
mut m := map{
|
||||
'foo': 1
|
||||
'bar': 2
|
||||
}
|
||||
for _, mut j in m {
|
||||
j = 3
|
||||
}
|
||||
|
@ -60,9 +67,18 @@ fn test_for_in_mut_val_of_map_direct() {
|
|||
}
|
||||
|
||||
fn test_for_in_mut_val_of_map_fixed_array() {
|
||||
mut m := {'foo': [{'a': 1}]!, 'bar': [{'b': 2}]!}
|
||||
mut m := map{
|
||||
'foo': [map{
|
||||
'a': 1
|
||||
}]!
|
||||
'bar': [map{
|
||||
'b': 2
|
||||
}]!
|
||||
}
|
||||
for _, mut j in m {
|
||||
j = [{'c': 3}]!
|
||||
j = [map{
|
||||
'c': 3
|
||||
}]!
|
||||
}
|
||||
println(m)
|
||||
assert '$m' == "{'foo': [{'c': 3}], 'bar': [{'c': 3}]}"
|
||||
|
|
|
@ -62,7 +62,14 @@ fn test_for_in_fixed_array_label_continue_break() {
|
|||
|
||||
fn test_for_in_map_label_continue_break() {
|
||||
mut rets := []string{}
|
||||
m := map{'a': 4, 'b': 5, 'c': 6, 'd': 7, 'e': 8, 'f': 9}
|
||||
m := map{
|
||||
'a': 4
|
||||
'b': 5
|
||||
'c': 6
|
||||
'd': 7
|
||||
'e': 8
|
||||
'f': 9
|
||||
}
|
||||
outer: for k, v in m {
|
||||
println('$k, $v')
|
||||
rets << '$k, $v'
|
||||
|
|
|
@ -44,7 +44,7 @@ fn test_for_char_in_string() {
|
|||
}
|
||||
|
||||
fn test_for_string_in_map() {
|
||||
m := {
|
||||
m := map{
|
||||
'a': 'b'
|
||||
'c': 'd'
|
||||
}
|
||||
|
@ -54,7 +54,11 @@ fn test_for_string_in_map() {
|
|||
}
|
||||
assert acc == 'a: b, c: d, '
|
||||
|
||||
mut m2 := {'a': 3, 'b': 4, 'c': 5}
|
||||
mut m2 := map{
|
||||
'a': 3
|
||||
'b': 4
|
||||
'c': 5
|
||||
}
|
||||
m2.delete('b')
|
||||
acc = ''
|
||||
for k, v in m2 {
|
||||
|
|
|
@ -2,6 +2,7 @@ type Node = Expr | string
|
|||
type Expr = IfExpr | IntegerLiteral
|
||||
|
||||
struct IntegerLiteral {}
|
||||
|
||||
struct IfExpr {
|
||||
pos int
|
||||
}
|
||||
|
@ -11,7 +12,9 @@ struct NodeWrapper {
|
|||
}
|
||||
|
||||
fn test_nested_sumtype_selector() {
|
||||
c := NodeWrapper{Node(Expr(IfExpr{pos: 1}))}
|
||||
c := NodeWrapper{Node(Expr(IfExpr{
|
||||
pos: 1
|
||||
}))}
|
||||
for c.node is Expr {
|
||||
assert typeof(c.node).name == 'Expr'
|
||||
break
|
||||
|
@ -28,7 +31,7 @@ mut:
|
|||
name string
|
||||
}
|
||||
|
||||
type Food = Milk | Eggs
|
||||
type Food = Eggs | Milk
|
||||
|
||||
struct FoodWrapper {
|
||||
mut:
|
||||
|
|
|
@ -1,32 +1,40 @@
|
|||
struct BuildData { x int }
|
||||
struct Tensor { x int }
|
||||
struct BuildData {
|
||||
x int
|
||||
}
|
||||
|
||||
struct Tensor {
|
||||
x int
|
||||
}
|
||||
|
||||
fn new_tensor<T>(data BuildData) Tensor {
|
||||
println('data: $data')
|
||||
x := T(data.x)
|
||||
println(x)
|
||||
return Tensor{ data.x }
|
||||
println(x)
|
||||
return Tensor{data.x}
|
||||
}
|
||||
|
||||
fn test_generic_function_returning_type_starting_with_t() {
|
||||
ft := new_tensor<f64>(x:123)
|
||||
ft := new_tensor<f64>(x: 123)
|
||||
println(ft)
|
||||
assert typeof(ft).name == 'Tensor'
|
||||
assert '$ft' == 'Tensor{\n x: 123\n}'
|
||||
//
|
||||
it := new_tensor<int>(x:456)
|
||||
assert typeof(ft).name == 'Tensor'
|
||||
assert '$ft' == 'Tensor{\n x: 123\n}'
|
||||
//
|
||||
it := new_tensor<int>(x: 456)
|
||||
println(it)
|
||||
assert typeof(it).name == 'Tensor'
|
||||
assert '$it' == 'Tensor{\n x: 456\n}'
|
||||
assert typeof(it).name == 'Tensor'
|
||||
assert '$it' == 'Tensor{\n x: 456\n}'
|
||||
}
|
||||
|
||||
// the following verifies that returning a generic type T
|
||||
// works at the same time as returning a type starting with T
|
||||
fn new_t<T>(o T) T {
|
||||
x := T(o)
|
||||
return x
|
||||
return x
|
||||
}
|
||||
|
||||
fn test_generic_function_returning_t_type() {
|
||||
f := new_t<f64>(1.23)
|
||||
i := new_t<int>(456)
|
||||
assert '$f' == '1.23'
|
||||
assert '$i' == '456'
|
||||
i := new_t<int>(456)
|
||||
assert '$f' == '1.23'
|
||||
assert '$i' == '456'
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ fn show_result<T, U>(x T, y U) bool {
|
|||
}
|
||||
|
||||
fn test_generic_fn_upper_name_type() {
|
||||
assert show_result<int, bool>(1, false)
|
||||
assert show_result<string, XX>( "s", XX{})
|
||||
assert show_result< XX, string>(XX{}, "s")
|
||||
assert show_result< XX, YY>(XX{}, YY{})
|
||||
assert show_result<int, bool>(1, false)
|
||||
assert show_result<string, XX>('s', XX{})
|
||||
assert show_result<XX, string>(XX{}, 's')
|
||||
assert show_result<XX, YY>(XX{}, YY{})
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
fn get<T>(typ T) T {
|
||||
return typ
|
||||
return typ
|
||||
}
|
||||
|
||||
fn get_string(typ string) string {
|
||||
return 'boom'
|
||||
return 'boom'
|
||||
}
|
||||
|
||||
fn test_generic_with_same_type() {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module main
|
||||
|
||||
import genericmodule
|
||||
import v.tests.generics_from_modules.genericmodule
|
||||
|
||||
fn test_generic_function_from_another_module() {
|
||||
v1 := genericmodule.take<int>(true, 10, 20)
|
||||
|
|
|
@ -11,9 +11,11 @@ fn test_identity() {
|
|||
assert simple<string>('g') + 'h' == 'gh'
|
||||
|
||||
assert simple<[]int>([1])[0] == 1
|
||||
assert simple<map[string]string>({'a':'b'})['a'] == 'b'
|
||||
assert simple<map[string]string>(map{
|
||||
'a': 'b'
|
||||
})['a'] == 'b'
|
||||
|
||||
assert simple<simplemodule.Data>(simplemodule.Data{value: 0}).value == 0
|
||||
assert simple<simplemodule.Data>(simplemodule.Data{ value: 0 }).value == 0
|
||||
}
|
||||
|
||||
fn plus<T>(xxx T, b T) T {
|
||||
|
@ -118,16 +120,18 @@ fn test_return_array() {
|
|||
}
|
||||
|
||||
fn opt<T>(v T) ?T {
|
||||
if sizeof(T) > 1 {return v}
|
||||
if sizeof(T) > 1 {
|
||||
return v
|
||||
}
|
||||
return none
|
||||
}
|
||||
|
||||
fn test_optional() {
|
||||
s := opt('hi') or { '' }
|
||||
assert s == 'hi'
|
||||
i := opt(5) or {0}
|
||||
i := opt(5) or { 0 }
|
||||
assert i == 5
|
||||
b := opt(s[0]) or {99}
|
||||
b := opt(s[0]) or { 99 }
|
||||
assert b == 99
|
||||
}
|
||||
|
||||
|
@ -141,7 +145,7 @@ fn test_ptr() {
|
|||
assert *ptr('aa') == 'aa'
|
||||
}
|
||||
|
||||
fn map_f<T,U>(l []T, f fn(T)U) []U {
|
||||
fn map_f<T, U>(l []T, f fn (T) U) []U {
|
||||
mut r := []U{}
|
||||
for e in l {
|
||||
r << f(e)
|
||||
|
@ -159,11 +163,11 @@ fn foldl<T>(l []T, nil T, f fn(T,T)T) T {
|
|||
}
|
||||
*/
|
||||
fn square(x int) int {
|
||||
return x*x
|
||||
return x * x
|
||||
}
|
||||
|
||||
fn mul_int(x int, y int) int {
|
||||
return x*y
|
||||
return x * y
|
||||
}
|
||||
|
||||
fn assert_eq<T>(a T, b T) {
|
||||
|
@ -173,21 +177,21 @@ fn assert_eq<T>(a T, b T) {
|
|||
|
||||
fn print_nice<T>(x T, indent int) string {
|
||||
mut space := ''
|
||||
for _ in 0..indent {
|
||||
for _ in 0 .. indent {
|
||||
space = space + ' '
|
||||
}
|
||||
return '$space$x'
|
||||
}
|
||||
|
||||
fn test_generic_fn() {
|
||||
assert_eq(simple(0+1), 1)
|
||||
assert_eq(simple(0 + 1), 1)
|
||||
assert_eq(simple('g') + 'h', 'gh')
|
||||
assert_eq(sum([5.1,6.2,7.0]), 18.3)
|
||||
assert_eq(sum([5.1, 6.2, 7.0]), 18.3)
|
||||
assert_eq(plus(i64(4), i64(6)), i64(10))
|
||||
a := [1,2,3,4]
|
||||
a := [1, 2, 3, 4]
|
||||
b := map_f(a, square)
|
||||
assert_eq(sum(b), 30) // 1+4+9+16 = 30
|
||||
//assert_eq(foldl(b, 1, mul_int), 576) // 1*4*9*16 = 576
|
||||
// assert_eq(foldl(b, 1, mul_int), 576) // 1*4*9*16 = 576
|
||||
assert print_nice('str', 8) == ' str'
|
||||
}
|
||||
|
||||
|
@ -243,7 +247,7 @@ pub mut:
|
|||
}
|
||||
|
||||
struct Repo<T, U> {
|
||||
db DB
|
||||
db DB
|
||||
pub mut:
|
||||
model T
|
||||
permission U
|
||||
|
@ -254,13 +258,13 @@ pub mut:
|
|||
// return Repo<T,Permission>{db: db}
|
||||
// }
|
||||
fn test_generic_struct() {
|
||||
mut a := Repo<User, Permission>{
|
||||
mut a := Repo<User,Permission>{
|
||||
model: User{
|
||||
name: 'joe'
|
||||
}
|
||||
}
|
||||
assert a.model.name == 'joe'
|
||||
mut b := Repo<Group, Permission>{
|
||||
mut b := Repo<Group,Permission>{
|
||||
permission: Permission{
|
||||
name: 'superuser'
|
||||
}
|
||||
|
@ -292,11 +296,10 @@ fn test_struct_from_other_module() {
|
|||
}
|
||||
|
||||
fn test_generic_struct_print_array_as_field() {
|
||||
foo := Foo<[]string>{
|
||||
data: []string{}
|
||||
}
|
||||
foo := Foo<[]string>{
|
||||
data: []string{}
|
||||
}
|
||||
assert foo.str() == 'Foo<array, string>{\n data: []\n}'
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -338,7 +341,7 @@ fn test<T>(mut app T) {
|
|||
}
|
||||
|
||||
fn nested_test<T>(mut app T) {
|
||||
app.context = Context {}
|
||||
app.context = Context{}
|
||||
}
|
||||
|
||||
fn test_pass_generic_to_nested_function() {
|
||||
|
@ -361,10 +364,13 @@ fn method_test<T>(mut app T) {
|
|||
fn test_pass_generic_to_nested_method() {
|
||||
mut app := App{}
|
||||
method_test(mut app)
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
fn generic_return_map<M>() map[string]M {
|
||||
return {'': M{}}
|
||||
return map{
|
||||
'': M{}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_generic_return_map() {
|
||||
|
@ -372,7 +378,11 @@ fn test_generic_return_map() {
|
|||
}
|
||||
|
||||
fn generic_return_nested_map<M>() map[string]map[string]M {
|
||||
return {'': {'': M{}}}
|
||||
return map{
|
||||
'': map{
|
||||
'': M{}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_generic_return_nested_map() {
|
||||
|
@ -383,10 +393,13 @@ fn multi_return<A, B>() (A, B) {
|
|||
return A{}, B{}
|
||||
}
|
||||
|
||||
struct Foo1{}
|
||||
struct Foo2{}
|
||||
struct Foo3{}
|
||||
struct Foo4{}
|
||||
struct Foo1 {}
|
||||
|
||||
struct Foo2 {}
|
||||
|
||||
struct Foo3 {}
|
||||
|
||||
struct Foo4 {}
|
||||
|
||||
fn test_multi_return() {
|
||||
// compiles
|
||||
|
@ -399,7 +412,7 @@ fn multi_generic_args<T, V>(t T, v V) bool {
|
|||
}
|
||||
|
||||
fn test_multi_generic_args() {
|
||||
assert multi_generic_args("Super", 2021)
|
||||
assert multi_generic_args('Super', 2021)
|
||||
}
|
||||
|
||||
fn new<T>() T {
|
||||
|
@ -429,9 +442,9 @@ fn test_generic_detection() {
|
|||
v1, v2 := -1, 1
|
||||
|
||||
// not generic
|
||||
a1, a2 := v1<v2, v2> v1
|
||||
a1, a2 := v1 < v2, v2 > v1
|
||||
assert a1 && a2
|
||||
b1, b2 := v1 <simplemodule.zero, v2> v1
|
||||
b1, b2 := v1 < simplemodule.zero, v2 > v1
|
||||
assert b1 && b2
|
||||
|
||||
// generic
|
||||
|
|
|
@ -5,7 +5,7 @@ fn f(x f64) f64 {
|
|||
|
||||
fn test_array_thread_f64_wait() {
|
||||
mut r := []thread f64{cap: 10}
|
||||
for i in 0 .. 10 {
|
||||
for i in 0 .. 10 {
|
||||
r << go f(f64(i) + 0.5)
|
||||
}
|
||||
x := r.wait()
|
||||
|
@ -19,15 +19,15 @@ fn g(shared a []int, i int) {
|
|||
}
|
||||
|
||||
fn test_array_thread_void_wait() {
|
||||
shared a := [2 3 5 7 11 13 17]
|
||||
shared a := [2, 3, 5, 7, 11, 13, 17]
|
||||
t := [
|
||||
go g(shared a, 0)
|
||||
go g(shared a, 3)
|
||||
go g(shared a, 6)
|
||||
go g(shared a, 2)
|
||||
go g(shared a, 1)
|
||||
go g(shared a, 5)
|
||||
go g(shared a, 4)
|
||||
go g(shared a, 0),
|
||||
go g(shared a, 3),
|
||||
go g(shared a, 6),
|
||||
go g(shared a, 2),
|
||||
go g(shared a, 1),
|
||||
go g(shared a, 5),
|
||||
go g(shared a, 4),
|
||||
]
|
||||
println('threads started')
|
||||
t.wait()
|
||||
|
@ -37,7 +37,7 @@ fn test_array_thread_void_wait() {
|
|||
}
|
||||
|
||||
fn test_void_thread_decl() {
|
||||
shared a := [2 3 9]
|
||||
shared a := [2, 3, 9]
|
||||
mut t1 := thread(0)
|
||||
mut tarr := []thread{len: 2}
|
||||
t1 = go g(shared a, 0)
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
fn foo1() ?int {
|
||||
return if true { 0 } else { none }
|
||||
return if true { 0 } else { none }
|
||||
}
|
||||
|
||||
fn foo2() ?int {
|
||||
return if true { 1 } else { error('foo2 error') }
|
||||
return if true { 1 } else { error('foo2 error') }
|
||||
}
|
||||
|
||||
fn foo3() ?int {
|
||||
return if false { 1 } else { error('foo3 error') }
|
||||
return if false { 1 } else { error('foo3 error') }
|
||||
}
|
||||
|
||||
fn foo4() ?int {
|
||||
|
|
|
@ -6,7 +6,7 @@ fn f(n int) ?f64 {
|
|||
}
|
||||
|
||||
fn test_fn_return() {
|
||||
mut res := []f64{cap:2}
|
||||
mut res := []f64{cap: 2}
|
||||
for m in [-3, 5] {
|
||||
if x := f(m) {
|
||||
res << x
|
||||
|
@ -18,8 +18,11 @@ fn test_fn_return() {
|
|||
}
|
||||
|
||||
fn test_map_get() {
|
||||
mut m := {'xy': 5, 'zu': 7}
|
||||
mut res := []int{cap:2}
|
||||
mut m := map{
|
||||
'xy': 5
|
||||
'zu': 7
|
||||
}
|
||||
mut res := []int{cap: 2}
|
||||
for k in ['jk', 'zu'] {
|
||||
if x := m[k] {
|
||||
res << x
|
||||
|
@ -32,7 +35,7 @@ fn test_map_get() {
|
|||
|
||||
fn test_array_get() {
|
||||
mut a := [12.5, 6.5, -17.25]
|
||||
mut res := []f64{cap:2}
|
||||
mut res := []f64{cap: 2}
|
||||
for i in [1, 4] {
|
||||
if x := a[i] {
|
||||
res << x
|
||||
|
@ -44,13 +47,13 @@ fn test_array_get() {
|
|||
}
|
||||
|
||||
fn test_chan_pop() {
|
||||
mut res := []f64{cap:3}
|
||||
mut res := []f64{cap: 3}
|
||||
ch := chan f64{cap: 10}
|
||||
ch <- 6.75
|
||||
ch <- -3.25
|
||||
ch.close()
|
||||
for _ in 0 .. 3 {
|
||||
if x:= <-ch {
|
||||
if x := <-ch {
|
||||
res << x
|
||||
} else {
|
||||
res << -37.5
|
||||
|
|
|
@ -38,11 +38,11 @@ fn test_nested_if_smartcast() {
|
|||
}
|
||||
}
|
||||
|
||||
type Bar = string | Test
|
||||
type Bar = Test | string
|
||||
type Xya = int | string
|
||||
|
||||
struct Test {
|
||||
x string
|
||||
x string
|
||||
xya Xya
|
||||
}
|
||||
|
||||
|
@ -69,10 +69,12 @@ fn test_nested_selector_smartcast() {
|
|||
}
|
||||
|
||||
type Inner = int | string
|
||||
|
||||
struct InnerStruct {
|
||||
x Inner
|
||||
}
|
||||
type Outer = string | InnerStruct
|
||||
|
||||
type Outer = InnerStruct | string
|
||||
|
||||
fn test_nested_if_is() {
|
||||
b := Outer(InnerStruct{Inner(0)})
|
||||
|
@ -168,11 +170,13 @@ fn test_mutability() {
|
|||
}
|
||||
}
|
||||
|
||||
type Expr = CallExpr | CTempVarExpr
|
||||
type Expr = CTempVarExpr | CallExpr
|
||||
|
||||
struct ExprWrapper {
|
||||
mut:
|
||||
expr Expr
|
||||
}
|
||||
|
||||
struct CallExpr {
|
||||
y int
|
||||
x string
|
||||
|
@ -196,21 +200,21 @@ fn test_reassign_from_function_with_parameter_selector() {
|
|||
type Node = Expr | string
|
||||
|
||||
fn test_nested_sumtype() {
|
||||
c := Node(Expr(CallExpr{y: 1}))
|
||||
c := Node(Expr(CallExpr{
|
||||
y: 1
|
||||
}))
|
||||
if c is Expr {
|
||||
if c is CallExpr {
|
||||
assert c.y == 1
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
||||
type Food = Milk | Eggs
|
||||
type Food = Eggs | Milk
|
||||
|
||||
struct FoodWrapper {
|
||||
mut:
|
||||
|
@ -240,16 +244,16 @@ struct NodeWrapper {
|
|||
}
|
||||
|
||||
fn test_nested_sumtype_selector() {
|
||||
c := NodeWrapper{Node(Expr(CallExpr{y: 1}))}
|
||||
c := NodeWrapper{Node(Expr(CallExpr{
|
||||
y: 1
|
||||
}))}
|
||||
if c.node is Expr {
|
||||
if c.node is CallExpr {
|
||||
assert c.node.y == 1
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
@ -279,13 +283,17 @@ type SumAll = Sum1 | Sum2
|
|||
struct All_in_one {
|
||||
pub mut:
|
||||
ptrs []&SumAll
|
||||
ptr &SumAll
|
||||
ptr &SumAll
|
||||
}
|
||||
|
||||
fn test_nested_pointer_smartcast() {
|
||||
mut s := All_in_one{
|
||||
ptr: &Sum1(Foo1{a: 1})
|
||||
ptrs: [&SumAll(Sum2(Bar1{a: 3}))]
|
||||
ptr: &Sum1(Foo1{
|
||||
a: 1
|
||||
})
|
||||
ptrs: [&SumAll(Sum2(Bar1{
|
||||
a: 3
|
||||
}))]
|
||||
}
|
||||
|
||||
if mut s.ptr is Sum1 {
|
||||
|
@ -296,7 +304,7 @@ fn test_nested_pointer_smartcast() {
|
|||
|
||||
a := s.ptrs[0]
|
||||
if a is Sum1 {
|
||||
if a is Foo1{
|
||||
if a is Foo1 {
|
||||
assert a.a == 3
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,33 @@
|
|||
module main
|
||||
|
||||
import geometry { Point, Line, Shape, point_str, module_name }
|
||||
import geometry { Line, Point, Shape, module_name, point_str }
|
||||
|
||||
fn test_imported_symbols_types() {
|
||||
// struct init
|
||||
p0 := Point{x: 10 y: 20}
|
||||
p1 := Point{x: 40 y: 60}
|
||||
// array init
|
||||
l0 := Line {
|
||||
ps: [p0, p1]
|
||||
}
|
||||
assert l0.ps[0].y == 20
|
||||
// struct init
|
||||
p0 := Point{
|
||||
x: 10
|
||||
y: 20
|
||||
}
|
||||
p1 := Point{
|
||||
x: 40
|
||||
y: 60
|
||||
}
|
||||
// array init
|
||||
l0 := Line{
|
||||
ps: [p0, p1]
|
||||
}
|
||||
assert l0.ps[0].y == 20
|
||||
}
|
||||
|
||||
fn test_imported_symbols_functions() {
|
||||
p0 := Point{x: 20 y: 40}
|
||||
p0 := Point{
|
||||
x: 20
|
||||
y: 40
|
||||
}
|
||||
// method
|
||||
assert p0.str() == '20 40'
|
||||
// function
|
||||
assert point_str(p0) == '20 40'
|
||||
assert point_str(p0) == '20 40'
|
||||
}
|
||||
|
||||
fn test_imported_symbols_constants() {
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
enum Colors {
|
||||
red green blue yellow
|
||||
red
|
||||
green
|
||||
blue
|
||||
yellow
|
||||
}
|
||||
|
||||
fn test_in_expression() {
|
||||
|
@ -105,9 +108,9 @@ fn test_in_expression_with_string() {
|
|||
}
|
||||
|
||||
fn test_in_expression_in_map() {
|
||||
m := {
|
||||
'one': 1
|
||||
'two': 2
|
||||
m := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
'three': 3
|
||||
}
|
||||
assert 'one' in m
|
||||
|
|
|
@ -21,9 +21,7 @@ fn test_all() {
|
|||
println('no compiler tests found')
|
||||
assert false
|
||||
}
|
||||
paths := vtest.filter_vtest_only(tests,
|
||||
basepath: dir
|
||||
)
|
||||
paths := vtest.filter_vtest_only(tests, basepath: dir)
|
||||
for path in paths {
|
||||
print(path + ' ')
|
||||
program := path
|
||||
|
@ -40,13 +38,13 @@ fn test_all() {
|
|||
panic(res.output)
|
||||
}
|
||||
$if windows {
|
||||
os.rm('./test.exe') or { }
|
||||
os.rm('./test.exe') or {}
|
||||
$if msvc {
|
||||
os.rm('./test.ilk') or { }
|
||||
os.rm('./test.pdb') or { }
|
||||
os.rm('./test.ilk') or {}
|
||||
os.rm('./test.pdb') or {}
|
||||
}
|
||||
} $else {
|
||||
os.rm('./test') or { }
|
||||
os.rm('./test') or {}
|
||||
}
|
||||
// println('============')
|
||||
// println(res.output)
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
struct Dog { breed string }
|
||||
struct Cat { breed string }
|
||||
struct Dog {
|
||||
breed string
|
||||
}
|
||||
|
||||
struct Cat {
|
||||
breed string
|
||||
}
|
||||
|
||||
interface Animal {
|
||||
breed string
|
||||
|
@ -19,15 +24,17 @@ struct Holder {
|
|||
}
|
||||
|
||||
struct Holder2 {
|
||||
x map[string]Holder
|
||||
x map[string]Holder
|
||||
breed string
|
||||
}
|
||||
|
||||
fn test_auto_str_gen_for_complex_interface_types() {
|
||||
a := Animal(Dog{'hi'})
|
||||
h := Holder{a}
|
||||
m := map{'dsa': h}
|
||||
h2 := Holder2{ m, 'N/A' }
|
||||
m := map{
|
||||
'dsa': h
|
||||
}
|
||||
h2 := Holder2{m, 'N/A'}
|
||||
a2 := Animal(h2)
|
||||
|
||||
assert '$a2' == r"
|
||||
|
|
|
@ -39,7 +39,7 @@ fn test_interface_struct() {
|
|||
name: 'Richard'
|
||||
}
|
||||
}
|
||||
assert bz1.sp.say_hello() == "Hello, My name is Richard and I\'m the bawz"
|
||||
assert bz1.sp.say_hello() == "Hello, My name is Richard and I'm the bawz"
|
||||
print('Test Boss inside Baz struct: ')
|
||||
bz1.sp.speak('Hello world!')
|
||||
bz2 := Baz{
|
||||
|
@ -59,7 +59,7 @@ fn test_interface_mut_struct() {
|
|||
name: 'Derek'
|
||||
}
|
||||
}
|
||||
assert mbaz.sp.say_hello() == "Hello, My name is Derek and I\'m the bawz"
|
||||
assert mbaz.sp.say_hello() == "Hello, My name is Derek and I'm the bawz"
|
||||
mbaz.sp = Cat{
|
||||
name: 'Dog'
|
||||
breed: 'Not a dog'
|
||||
|
@ -82,7 +82,7 @@ fn test_interface_struct_from_array() {
|
|||
},
|
||||
]
|
||||
assert bazs[0].sp.say_hello() == 'Meow meow Kitty the Catty Koo meow'
|
||||
assert bazs[1].sp.say_hello() == "Hello, My name is Bob and I\'m the bawz"
|
||||
assert bazs[1].sp.say_hello() == "Hello, My name is Bob and I'm the bawz"
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -308,17 +308,17 @@ fn animal_match(a Animal) {
|
|||
|
||||
interface II {
|
||||
mut:
|
||||
my_field int
|
||||
my_field int
|
||||
}
|
||||
|
||||
struct AA {
|
||||
BB
|
||||
BB
|
||||
}
|
||||
|
||||
struct BB {
|
||||
pad [10]byte
|
||||
mut:
|
||||
my_field int
|
||||
my_field int
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
|
||||
module local
|
||||
|
||||
pub fn local_fn() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -2,21 +2,33 @@ type Type = int
|
|||
type RType = rune
|
||||
|
||||
fn test_map_key_alias() {
|
||||
mut m_int := map{12: '12', 2: '2'}
|
||||
mut m_int := map{
|
||||
12: '12'
|
||||
2: '2'
|
||||
}
|
||||
m_int[14] = '14'
|
||||
m_int[Type(15)] = '15'
|
||||
assert m_int.str() == "{12: '12', 2: '2', 14: '14', 15: '15'}"
|
||||
//// /// ///// //
|
||||
mut m_rune := map{`a`: '12', `l`: '14'}
|
||||
mut m_rune := map{
|
||||
`a`: '12'
|
||||
`l`: '14'
|
||||
}
|
||||
m_rune[`g`] = '12'
|
||||
m_rune[RType(`$`)] = '16'
|
||||
assert m_rune.str() == "{`a`: '12', `l`: '14', `g`: '12', `$`: '16'}"
|
||||
}
|
||||
|
||||
fn test_map_alias_key_init() {
|
||||
m_int := map{Type(12): '12', Type(2): '2'}
|
||||
m_int := map{
|
||||
Type(12): '12'
|
||||
Type(2): '2'
|
||||
}
|
||||
assert m_int.str() == "{12: '12', 2: '2'}"
|
||||
//// // ///// //
|
||||
m_rune := map{RType(`a`): '12', RType(`l`): '14'}
|
||||
m_rune := map{
|
||||
RType(`a`): '12'
|
||||
RType(`l`): '14'
|
||||
}
|
||||
assert m_rune.str() == "{`a`: '12', `l`: '14'}"
|
||||
}
|
||||
|
|
|
@ -37,9 +37,15 @@ fn test_array_with_fns() {
|
|||
}
|
||||
|
||||
fn test_map_with_fns() {
|
||||
mut a := {'one':foo, 'two':foo2}
|
||||
mut a := map{
|
||||
'one': foo
|
||||
'two': foo2
|
||||
}
|
||||
assert a.len == 2
|
||||
assert (a == {'one':foo, 'two':foo2}) == true
|
||||
assert (a == map{
|
||||
'one': foo
|
||||
'two': foo2
|
||||
}) == true
|
||||
f0 := a['one']
|
||||
assert f0('xx', '') == 12
|
||||
f1 := a['two']
|
||||
|
@ -49,7 +55,9 @@ fn test_map_with_fns() {
|
|||
assert f2('zzzz', '') == 24
|
||||
f3 := a['two']
|
||||
assert f3('aaaaa', '') == 15
|
||||
mut b := {'one':foo}
|
||||
mut b := map{
|
||||
'one': foo
|
||||
}
|
||||
b['one'] = a['one']
|
||||
f4 := b['one']
|
||||
assert f4('bbbbbb', '') == 26
|
||||
|
@ -70,7 +78,9 @@ fn test_map_and_array_with_fns_typeof_and_direct_call() {
|
|||
a := [foo3]
|
||||
assert typeof(a).name == '[]fn (string) int'
|
||||
assert a[0]('hello') == 15
|
||||
b := {'one': foo3}
|
||||
b := map{
|
||||
'one': foo3
|
||||
}
|
||||
assert typeof(b).name == 'map[string]fn (string) int'
|
||||
assert b['one']('hi') == 12
|
||||
}
|
||||
|
@ -96,13 +106,17 @@ fn bar3(m map[string]fn (string) int) int {
|
|||
}
|
||||
|
||||
fn bar4(mut m map[string]fn (string) int) int {
|
||||
m['fn'] = foo4
|
||||
m['fn'] = foo4
|
||||
return m['fn']('hi')
|
||||
}
|
||||
|
||||
fn test_map_of_fns_as_argument() {
|
||||
m1 := {'fn': foo3}
|
||||
m1 := map{
|
||||
'fn': foo3
|
||||
}
|
||||
assert bar3(m1) == 12
|
||||
mut m2 := {'fn': foo3}
|
||||
mut m2 := map{
|
||||
'fn': foo3
|
||||
}
|
||||
assert bar4(mut m2) == 22
|
||||
}
|
||||
|
|
|
@ -1,17 +1,25 @@
|
|||
fn foo(mut m map[string][1][2]map[string]int) {
|
||||
m['foo'] = [[{'bar': 1}, {'baz':3}]!]!
|
||||
m['foo'] = [[map{
|
||||
'bar': 1
|
||||
}, map{
|
||||
'baz': 3
|
||||
}]!]!
|
||||
}
|
||||
|
||||
fn test_complex_map_fixed_array() {
|
||||
mut m := map[string][1][2]map[string]int
|
||||
mut m := map[string][1][2]map[string]int{}
|
||||
foo(mut m)
|
||||
println(m)
|
||||
assert '$m' == "{'foo': [[{'bar': 1}, {'baz': 3}]]}"
|
||||
}
|
||||
|
||||
fn test_innermost_value_of_map_fixed_array() {
|
||||
mut m := map[string][1][2]map[string]int
|
||||
m['foo'] = [[{'bar': 1}, {'baz': 3}]!]!
|
||||
mut m := map[string][1][2]map[string]int{}
|
||||
m['foo'] = [[map{
|
||||
'bar': 1
|
||||
}, map{
|
||||
'baz': 3
|
||||
}]!]!
|
||||
println(m['foo'][0][0]['bar'])
|
||||
println(m['foo'][0][0]['bar'] == 1)
|
||||
assert m['foo'][0][0]['bar'] == 1
|
||||
|
@ -19,9 +27,18 @@ fn test_innermost_value_of_map_fixed_array() {
|
|||
}
|
||||
|
||||
fn test_complex_map_high_order_fixed_array() {
|
||||
mut m := {'foo': [[{'a': 1}]!]!, 'bar': [[{'b': 2}]!]!}
|
||||
mut m := map{
|
||||
'foo': [[map{
|
||||
'a': 1
|
||||
}]!]!
|
||||
'bar': [[map{
|
||||
'b': 2
|
||||
}]!]!
|
||||
}
|
||||
for _, mut j in m {
|
||||
j = [[{'c': 3}]!]!
|
||||
j = [[map{
|
||||
'c': 3
|
||||
}]!]!
|
||||
}
|
||||
println(m)
|
||||
assert '$m' == "{'foo': [[{'c': 3}]], 'bar': [[{'c': 3}]]}"
|
||||
|
|
|
@ -1,18 +1,38 @@
|
|||
fn test_map_equality() {
|
||||
a1 := {'a':1, 'b':2}
|
||||
b1 := {'b':2, 'a':1}
|
||||
c1 := {'a':2, 'b':1}
|
||||
a1 := map{
|
||||
'a': 1
|
||||
'b': 2
|
||||
}
|
||||
b1 := map{
|
||||
'b': 2
|
||||
'a': 1
|
||||
}
|
||||
c1 := map{
|
||||
'a': 2
|
||||
'b': 1
|
||||
}
|
||||
|
||||
assert a1 == b1
|
||||
assert a1 != c1
|
||||
|
||||
a2 := {'a':1}
|
||||
b2 := {'a':1, 'b':2}
|
||||
a2 := map{
|
||||
'a': 1
|
||||
}
|
||||
b2 := map{
|
||||
'a': 1
|
||||
'b': 2
|
||||
}
|
||||
|
||||
assert a2 != b2
|
||||
|
||||
a3 := {'a':'1', 'b':'2'}
|
||||
b3 := {'b':'2', 'a':'1'}
|
||||
a3 := map{
|
||||
'a': '1'
|
||||
'b': '2'
|
||||
}
|
||||
b3 := map{
|
||||
'b': '2'
|
||||
'a': '1'
|
||||
}
|
||||
|
||||
assert a3 == b3
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fn test_high_order_map_assign() {
|
||||
mut m := map[string]map[string]int
|
||||
mut m := map[string]map[string]int{}
|
||||
m['hello']['hi'] = 1
|
||||
println(m)
|
||||
assert '$m' == "{'hello': {'hi': 1}}"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const (
|
||||
alpha = 'a'
|
||||
beta = 'b'
|
||||
m = map{
|
||||
alpha : 'Alpha'
|
||||
beta : 'Beta'
|
||||
beta = 'b'
|
||||
m = map{
|
||||
alpha: 'Alpha'
|
||||
beta: 'Beta'
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -13,13 +13,14 @@ fn test_const_keys() {
|
|||
}
|
||||
|
||||
enum Enum {
|
||||
a b
|
||||
a
|
||||
b
|
||||
}
|
||||
|
||||
const (
|
||||
m2 = map{
|
||||
Enum.a.str() : 'first'
|
||||
Enum.b.str() : 'second'
|
||||
Enum.a.str(): 'first'
|
||||
Enum.b.str(): 'second'
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
@ -5,28 +5,33 @@ struct Test {
|
|||
}
|
||||
|
||||
fn test_interpolation_map_to_string() {
|
||||
mut a := map[string]string
|
||||
mut a := map[string]string{}
|
||||
a['1'] = 'one'
|
||||
a['2'] = 'two'
|
||||
a['3'] = 'three'
|
||||
assert '$a' == "{'1': 'one', '2': 'two', '3': 'three'}"
|
||||
|
||||
mut b := map[string]int
|
||||
mut b := map[string]int{}
|
||||
b['1'] = 1
|
||||
b['2'] = 2
|
||||
b['3'] = 3
|
||||
assert '$b' == "{'1': 1, '2': 2, '3': 3}"
|
||||
|
||||
mut c := map[string]bool
|
||||
mut c := map[string]bool{}
|
||||
c['1'] = true
|
||||
c['2'] = false
|
||||
assert '$c' == "{'1': true, '2': false}"
|
||||
|
||||
d := {'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4}
|
||||
d := map{
|
||||
'f1': 1.1
|
||||
'f2': 2.2
|
||||
'f3': 3.3
|
||||
'f4': 4.4
|
||||
}
|
||||
println('d: $d')
|
||||
assert '$d' == "{'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4}"
|
||||
|
||||
mut e := map[string]Test
|
||||
mut e := map[string]Test{}
|
||||
e['1'] = Test{true, 0, 'abc'}
|
||||
e['2'] = Test{true, 1, 'def'}
|
||||
e['3'] = Test{false, 2, 'ghi'}
|
||||
|
@ -37,6 +42,8 @@ fn test_interpolation_map_to_string() {
|
|||
assert s.contains("}, '2': Test{")
|
||||
assert s.contains("y: 'def'")
|
||||
|
||||
f := {'hello': [1,2,3]!}
|
||||
f := map{
|
||||
'hello': [1, 2, 3]!
|
||||
}
|
||||
assert '$f' == "{'hello': [1, 2, 3]}"
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
type Test = map[string]string
|
||||
|
||||
fn test_index() {
|
||||
t := Test({'c': 'abc'})
|
||||
assert t['c'] == 'abc'
|
||||
t := Test(map{
|
||||
'c': 'abc'
|
||||
})
|
||||
assert t['c'] == 'abc'
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
fn test_string_int() {
|
||||
mut m := {'hi':4}
|
||||
m2:= {'hi':5}
|
||||
mut m := map{
|
||||
'hi': 4
|
||||
}
|
||||
m2 := map{
|
||||
'hi': 5
|
||||
}
|
||||
assert m != m2
|
||||
m['hi']++
|
||||
assert m == m2
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
|
||||
type SumType = int | string
|
||||
|
||||
fn s2s(s SumType) SumType { return s }
|
||||
fn s2s(s SumType) SumType {
|
||||
return s
|
||||
}
|
||||
|
||||
fn test_match_expression_on_sumtype_ordinary_branch(){
|
||||
fn test_match_expression_on_sumtype_ordinary_branch() {
|
||||
// tests whether an ordinary branch supports multiple statements,
|
||||
// followed by a default expression
|
||||
mut c := 0
|
||||
|
@ -13,7 +14,8 @@ fn test_match_expression_on_sumtype_ordinary_branch(){
|
|||
c = 1
|
||||
eprintln('hi')
|
||||
'a string'
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
'unknown'
|
||||
}
|
||||
}
|
||||
|
@ -21,8 +23,7 @@ fn test_match_expression_on_sumtype_ordinary_branch(){
|
|||
assert c == 1
|
||||
}
|
||||
|
||||
|
||||
fn test_match_expression_on_sumtype_else(){
|
||||
fn test_match_expression_on_sumtype_else() {
|
||||
// tests whether else branches support multiple statements,
|
||||
// when the other branches are simple default expressions
|
||||
mut c := 0
|
||||
|
@ -30,7 +31,8 @@ fn test_match_expression_on_sumtype_else(){
|
|||
res := match s {
|
||||
string {
|
||||
'a string'
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
c = 3
|
||||
eprintln('hi')
|
||||
'unknown'
|
||||
|
@ -40,7 +42,7 @@ fn test_match_expression_on_sumtype_else(){
|
|||
assert c == 3
|
||||
}
|
||||
|
||||
fn test_match_expression_on_sumtype_full(){
|
||||
fn test_match_expression_on_sumtype_full() {
|
||||
// tests whether all branches can have multiple statements,
|
||||
// followed by a default expression
|
||||
mut c := 0
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
fn test_match_in_map_init() {
|
||||
ret := foo()
|
||||
println(ret)
|
||||
assert ret == map{'token': 'a', 'sleep': '30', 'every': '1'}
|
||||
assert ret == map{
|
||||
'token': 'a'
|
||||
'sleep': '30'
|
||||
'every': '1'
|
||||
}
|
||||
}
|
||||
|
||||
fn foo() map[string]string {
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
interface Animal { name string }
|
||||
struct Dog { name string }
|
||||
struct Cat { name string }
|
||||
interface Animal {
|
||||
name string
|
||||
}
|
||||
|
||||
struct Dog {
|
||||
name string
|
||||
}
|
||||
|
||||
struct Cat {
|
||||
name string
|
||||
}
|
||||
|
||||
fn test_interface_match() {
|
||||
a := Animal(Dog{name: 'Jet'})
|
||||
match a {
|
||||
Dog { assert true }
|
||||
Cat { assert false }
|
||||
else { assert false }
|
||||
}
|
||||
a := Animal(Dog{
|
||||
name: 'Jet'
|
||||
})
|
||||
match a {
|
||||
Dog { assert true }
|
||||
Cat { assert false }
|
||||
else { assert false }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ type Node = Expr | string
|
|||
type Expr = IfExpr | IntegerLiteral
|
||||
|
||||
struct IntegerLiteral {}
|
||||
|
||||
struct IfExpr {
|
||||
pos int
|
||||
}
|
||||
|
@ -11,7 +12,9 @@ struct NodeWrapper {
|
|||
}
|
||||
|
||||
fn test_nested_sumtype_match_selector() {
|
||||
c := NodeWrapper{Node(Expr(IfExpr{pos: 1}))}
|
||||
c := NodeWrapper{Node(Expr(IfExpr{
|
||||
pos: 1
|
||||
}))}
|
||||
match c.node {
|
||||
Expr {
|
||||
match c.node {
|
||||
|
@ -30,7 +33,9 @@ fn test_nested_sumtype_match_selector() {
|
|||
}
|
||||
|
||||
fn test_nested_sumtype_match() {
|
||||
c := Node(Expr(IfExpr{pos: 1}))
|
||||
c := Node(Expr(IfExpr{
|
||||
pos: 1
|
||||
}))
|
||||
match c {
|
||||
Expr {
|
||||
match c {
|
||||
|
@ -58,7 +63,7 @@ mut:
|
|||
name string
|
||||
}
|
||||
|
||||
type Food = Milk | Eggs
|
||||
type Food = Eggs | Milk
|
||||
|
||||
struct FoodWrapper {
|
||||
mut:
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
struct Cat{name string}
|
||||
struct Dog{name string}
|
||||
struct Cat {
|
||||
name string
|
||||
}
|
||||
|
||||
struct Dog {
|
||||
name string
|
||||
}
|
||||
|
||||
type Animal = Cat | Dog
|
||||
|
||||
const (
|
||||
cat = Cat{name: 'cat'}
|
||||
dog = Dog{name: 'dog'}
|
||||
cat = Cat{
|
||||
name: 'cat'
|
||||
}
|
||||
dog = Dog{
|
||||
name: 'dog'
|
||||
}
|
||||
)
|
||||
|
||||
fn test_shadow() {
|
||||
|
@ -15,7 +24,7 @@ fn test_shadow() {
|
|||
Cat {
|
||||
assert animal.name == cat.name
|
||||
}
|
||||
else{
|
||||
else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +37,7 @@ fn test_as() {
|
|||
Dog {
|
||||
assert animal.name == dog.name
|
||||
}
|
||||
else{
|
||||
else {
|
||||
assert false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,24 @@ mut:
|
|||
|
||||
// this must return a reference, or else you'll get a C error
|
||||
// TODO: add a proper checker check for that case
|
||||
fn new(x int) &Test { return &Test{ x } }
|
||||
fn (mut t Test) inc() &Test { t.val++ return t }
|
||||
fn (mut t Test) add(x int) &Test { t.val += x return t }
|
||||
fn (mut t Test) div(x int) &Test { t.val /= x return t }
|
||||
fn new(x int) &Test {
|
||||
return &Test{x}
|
||||
}
|
||||
|
||||
fn (mut t Test) inc() &Test {
|
||||
t.val++
|
||||
return t
|
||||
}
|
||||
|
||||
fn (mut t Test) add(x int) &Test {
|
||||
t.val += x
|
||||
return t
|
||||
}
|
||||
|
||||
fn (mut t Test) div(x int) &Test {
|
||||
t.val /= x
|
||||
return t
|
||||
}
|
||||
|
||||
fn test_method_call_chains() {
|
||||
mut x := new(4).inc().inc().inc().inc().add(4).div(2).inc()
|
||||
|
|
|
@ -7,11 +7,11 @@ interface Animal {
|
|||
}
|
||||
|
||||
fn (a Animal) info() string {
|
||||
return "I'm a ${a.breed} ${typeof(a).name}"
|
||||
return "I'm a $a.breed ${typeof(a).name}"
|
||||
}
|
||||
|
||||
fn new_animal(breed string) Animal {
|
||||
return &Cat{ breed }
|
||||
return &Cat{breed}
|
||||
}
|
||||
|
||||
fn test_methods_on_interfaces() {
|
||||
|
|
|
@ -3,7 +3,7 @@ import crypto.sha256
|
|||
import term { white }
|
||||
import crypto.md5 { sum }
|
||||
import log as l
|
||||
import time as t { now, utc, Time }
|
||||
import time as t { Time, utc }
|
||||
import math
|
||||
import crypto.sha512
|
||||
import cli { Command }
|
||||
|
|
|
@ -3,6 +3,6 @@ import time
|
|||
fn test_module_type_cast() {
|
||||
a := time.Duration(5)
|
||||
b := time.Duration(6)
|
||||
//println(a+b)
|
||||
assert a+b == 11
|
||||
// println(a+b)
|
||||
assert a + b == 11
|
||||
}
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/*
|
||||
module acommentedmodule
|
||||
|
||||
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module geometry
|
||||
|
||||
const(
|
||||
const (
|
||||
module_name = 'geometry'
|
||||
)
|
||||
|
||||
|
@ -12,24 +12,24 @@ pub enum Shape {
|
|||
|
||||
pub struct Point {
|
||||
pub mut:
|
||||
x int
|
||||
y int
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
pub struct Line {
|
||||
pub mut:
|
||||
ps []Point
|
||||
ps []Point
|
||||
}
|
||||
|
||||
pub fn (a Point) +(b Point) Point {
|
||||
return Point {
|
||||
x: a.x + b.x
|
||||
y: a.y + b.y
|
||||
}
|
||||
pub fn (a Point) + (b Point) Point {
|
||||
return Point{
|
||||
x: a.x + b.x
|
||||
y: a.y + b.y
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (a Point) str() string {
|
||||
return '${a.x} ${a.y}'
|
||||
return '$a.x $a.y'
|
||||
}
|
||||
|
||||
pub fn point_str(a Point) string {
|
||||
|
|
|
@ -3,14 +3,23 @@ module main
|
|||
import geometry { Point }
|
||||
|
||||
fn test_operator_overloading() {
|
||||
one := Point {x:1, y:2}
|
||||
two := Point {x:5, y:1}
|
||||
sum := one + two
|
||||
one := Point{
|
||||
x: 1
|
||||
y: 2
|
||||
}
|
||||
two := Point{
|
||||
x: 5
|
||||
y: 1
|
||||
}
|
||||
sum := one + two
|
||||
assert sum.x == 6
|
||||
assert sum.y == 3
|
||||
}
|
||||
|
||||
fn test_str_method() {
|
||||
one := Point {x:1, y:2}
|
||||
assert '$one' == '1 2'
|
||||
one := Point{
|
||||
x: 1
|
||||
y: 2
|
||||
}
|
||||
assert '$one' == '1 2'
|
||||
}
|
||||
|
|
|
@ -2,10 +2,10 @@ import simplemodule
|
|||
|
||||
// this tests whether the tests can import the same module without any special
|
||||
// custom paths setup on the CLI
|
||||
fn test_iadd(){
|
||||
fn test_iadd() {
|
||||
assert simplemodule.iadd(10, 20) == 30
|
||||
}
|
||||
|
||||
fn test_imul(){
|
||||
assert simplemodule.imul(5,8) == 40
|
||||
fn test_imul() {
|
||||
assert simplemodule.imul(5, 8) == 40
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module xxx
|
||||
|
||||
pub fn f() string {
|
||||
return 'x'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module yyy
|
||||
pub fn f() string {
|
||||
|
||||
pub fn f() string {
|
||||
return 'y'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module zzz
|
||||
|
||||
pub fn f() string {
|
||||
return 'z'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ fn test_mut_2() {
|
|||
}
|
||||
|
||||
fn test_mut_3() {
|
||||
mut indices := []int{len: 3}
|
||||
mut indices := []int{len: 3}
|
||||
mut results := []string{}
|
||||
|
||||
for i, mut v in indices {
|
||||
v = i
|
||||
a := v
|
||||
println('$i $v $a')
|
||||
for i, mut v in indices {
|
||||
v = i
|
||||
a := v
|
||||
println('$i $v $a')
|
||||
results << '$i $v $a'
|
||||
}
|
||||
}
|
||||
assert results[0] == '0 0 0'
|
||||
assert results[1] == '1 1 1'
|
||||
assert results[2] == '2 2 2'
|
||||
|
@ -65,42 +65,46 @@ fn test_mut_3() {
|
|||
|
||||
struct St {
|
||||
mut:
|
||||
n int
|
||||
n int
|
||||
}
|
||||
|
||||
fn f(mut x St) {
|
||||
mut y := St{n: 2}
|
||||
a := x
|
||||
b := y
|
||||
x.n = 3
|
||||
y.n = 4
|
||||
println('$a.n $b.n')
|
||||
mut y := St{
|
||||
n: 2
|
||||
}
|
||||
a := x
|
||||
b := y
|
||||
x.n = 3
|
||||
y.n = 4
|
||||
println('$a.n $b.n')
|
||||
assert '$a.n $b.n' == '1 2'
|
||||
}
|
||||
|
||||
fn test_mut_4() {
|
||||
mut x := St{ n: 1 }
|
||||
f(mut x)
|
||||
mut x := St{
|
||||
n: 1
|
||||
}
|
||||
f(mut x)
|
||||
}
|
||||
|
||||
fn test_mut_5() {
|
||||
mut arr1 := []int{len:2}
|
||||
mut arr2 := []int{len:2}
|
||||
mut arr1 := []int{len: 2}
|
||||
mut arr2 := []int{len: 2}
|
||||
mut results := []string{}
|
||||
|
||||
for i, mut v in arr1 {
|
||||
for ii, mut vv in arr2 {
|
||||
v = i
|
||||
a := v
|
||||
println('$i $v $a')
|
||||
for i, mut v in arr1 {
|
||||
for ii, mut vv in arr2 {
|
||||
v = i
|
||||
a := v
|
||||
println('$i $v $a')
|
||||
results << '$i $v $a'
|
||||
|
||||
vv = ii
|
||||
aa := vv
|
||||
println('$ii $vv $aa')
|
||||
results << "$ii $vv $aa"
|
||||
}
|
||||
}
|
||||
vv = ii
|
||||
aa := vv
|
||||
println('$ii $vv $aa')
|
||||
results << '$ii $vv $aa'
|
||||
}
|
||||
}
|
||||
|
||||
assert results[0] == '0 0 0'
|
||||
assert results[1] == '0 0 0'
|
||||
|
@ -114,21 +118,21 @@ fn test_mut_5() {
|
|||
|
||||
fn test_mut_6() {
|
||||
mut results := []int{}
|
||||
mut arr := []int{len:3}
|
||||
for _, mut v in arr {
|
||||
mut arr := []int{len: 3}
|
||||
for _, mut v in arr {
|
||||
v = v + 1
|
||||
println(v)
|
||||
results << v
|
||||
}
|
||||
}
|
||||
assert results[0] == 1
|
||||
assert results[1] == 1
|
||||
assert results[2] == 1
|
||||
}
|
||||
|
||||
fn test_mut_7() {
|
||||
mut arr := []int{len:3}
|
||||
mut arr := []int{len: 3}
|
||||
mut results := []int{}
|
||||
for _, mut v in arr {
|
||||
for _, mut v in arr {
|
||||
v = v + 1 // v: 1
|
||||
mut vv := v // vv: 1, v: 1
|
||||
vv = vv + v // vv: 2, v: 1
|
||||
|
@ -136,7 +140,7 @@ fn test_mut_7() {
|
|||
println(vv)
|
||||
results << v
|
||||
results << vv
|
||||
}
|
||||
}
|
||||
assert results[0] == 1
|
||||
assert results[1] == 2
|
||||
assert results[2] == 1
|
||||
|
@ -146,37 +150,40 @@ fn test_mut_7() {
|
|||
}
|
||||
|
||||
fn test_mut_8() {
|
||||
mut indices := []int{len: 1}
|
||||
for i, mut v in indices {
|
||||
v = i
|
||||
mut b := v
|
||||
println(typeof(i).name)
|
||||
println(typeof(v).name)
|
||||
println(typeof(b).name)
|
||||
u := [v, 5, 6]
|
||||
println(typeof(u).name)
|
||||
mut indices := []int{len: 1}
|
||||
for i, mut v in indices {
|
||||
v = i
|
||||
mut b := v
|
||||
println(typeof(i).name)
|
||||
println(typeof(v).name)
|
||||
println(typeof(b).name)
|
||||
u := [v, 5, 6]
|
||||
println(typeof(u).name)
|
||||
println(u)
|
||||
assert typeof(b).name == 'int'
|
||||
assert typeof(u).name == '[]int'
|
||||
assert u == [0, 5, 6]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn test_mut_9() {
|
||||
mut arr := [0,0,0]
|
||||
mut arr := [0, 0, 0]
|
||||
mut results := []string{}
|
||||
for _, mut v in arr {
|
||||
v = v + 1 // v: 1
|
||||
mut vv := v // vv: 1, v: 1
|
||||
vv = vv + v // vv: 2, v: 1
|
||||
foo := {'a': v, 'b': vv} // or use new syntax foo := map{'a': v, 'b': vv}, results are the same
|
||||
foo := map{
|
||||
'a': v
|
||||
'b': vv
|
||||
}
|
||||
println(v)
|
||||
println(vv)
|
||||
println(foo)
|
||||
results << '$v'
|
||||
results << '$vv'
|
||||
results << '$foo'
|
||||
}
|
||||
}
|
||||
assert results[0] == '1'
|
||||
assert results[1] == '2'
|
||||
assert results[2] == "{'a': 1, 'b': 2}"
|
||||
|
@ -210,7 +217,7 @@ fn foo1(mut arr [][]int) {
|
|||
}
|
||||
|
||||
fn test_mut_10() {
|
||||
mut arr := [[0,0]]
|
||||
mut arr := [[0, 0]]
|
||||
foo1(mut arr)
|
||||
}
|
||||
|
||||
|
@ -236,7 +243,7 @@ fn foo2(mut arr [][]int) {
|
|||
}
|
||||
|
||||
fn test_mut_11() {
|
||||
mut arr := [[0,0]]
|
||||
mut arr := [[0, 0]]
|
||||
foo2(mut arr)
|
||||
}
|
||||
|
||||
|
@ -251,7 +258,7 @@ fn foo3(mut arr [][]int) {
|
|||
}
|
||||
|
||||
fn test_mut_12() {
|
||||
mut arr := [[0, 0]]
|
||||
mut arr := [[0, 0]]
|
||||
foo3(mut arr)
|
||||
}
|
||||
|
||||
|
@ -270,7 +277,9 @@ fn foo4(mut f Foo) {
|
|||
}
|
||||
|
||||
fn test_mut_13() {
|
||||
mut f := Foo{foo: 1}
|
||||
mut f := Foo{
|
||||
foo: 1
|
||||
}
|
||||
foo4(mut f)
|
||||
}
|
||||
|
||||
|
@ -286,7 +295,7 @@ fn foo5(mut arr []int) {
|
|||
}
|
||||
|
||||
fn test_mut_14() {
|
||||
mut arr := [1,2,3]
|
||||
mut arr := [1, 2, 3]
|
||||
foo5(mut arr)
|
||||
}
|
||||
|
||||
|
@ -302,7 +311,7 @@ fn foo6(mut arr [3]int) {
|
|||
}
|
||||
|
||||
fn test_mut_15() {
|
||||
mut arr := [1,2,3]!
|
||||
mut arr := [1, 2, 3]!
|
||||
foo6(mut arr)
|
||||
}
|
||||
|
||||
|
@ -318,20 +327,31 @@ fn foo7(mut m map[string]int) {
|
|||
}
|
||||
|
||||
fn test_mut_16() {
|
||||
mut m := map{'one': 100, 'two': 2}
|
||||
mut m := map{
|
||||
'one': 100
|
||||
'two': 2
|
||||
}
|
||||
foo7(mut m)
|
||||
}
|
||||
|
||||
fn test_mut_17() {
|
||||
mut arr := [map{'foo':1}]
|
||||
mut arr := [map{
|
||||
'foo': 1
|
||||
}]
|
||||
for _, mut j in arr {
|
||||
mut k := j.clone()
|
||||
j['foo'] = 0
|
||||
unsafe {k['foo'] = 10}
|
||||
unsafe {
|
||||
k['foo'] = 10
|
||||
}
|
||||
println(j)
|
||||
println(k)
|
||||
assert j == {'foo': 0}
|
||||
assert k == {'foo': 10}
|
||||
assert j == map{
|
||||
'foo': 0
|
||||
}
|
||||
assert k == map{
|
||||
'foo': 10
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,8 +62,6 @@ fn test_nested_propagation_method() {
|
|||
mut x := St{
|
||||
z: 2.25
|
||||
}
|
||||
x.aa_propagate() or {
|
||||
x.z = 13.0625
|
||||
}
|
||||
x.aa_propagate() or { x.z = 13.0625 }
|
||||
assert x.z == 13.0625
|
||||
}
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
import math.complex
|
||||
|
||||
struct Cat {
|
||||
name string
|
||||
name string
|
||||
breed string
|
||||
age int
|
||||
age int
|
||||
}
|
||||
|
||||
type Feline = Cat
|
||||
|
||||
fn test_offsetof() {
|
||||
cat := Cat{name: 'Cthulhu' breed: 'Great Old One' age: 2147483647}
|
||||
cat := Cat{
|
||||
name: 'Cthulhu'
|
||||
breed: 'Great Old One'
|
||||
age: 2147483647
|
||||
}
|
||||
unsafe {
|
||||
assert *(&string(byteptr(&cat) + __offsetof(Cat, name))) == 'Cthulhu'
|
||||
assert *(&string(byteptr(&cat) + __offsetof(Cat, breed))) == 'Great Old One'
|
||||
|
@ -26,7 +30,11 @@ fn test_offsetof_struct_from_another_module() {
|
|||
}
|
||||
|
||||
fn test_offsetof_alias() {
|
||||
fel := Feline{name: 'Cthulhu' breed: 'Great Old One' age: 2147483647}
|
||||
fel := Feline{
|
||||
name: 'Cthulhu'
|
||||
breed: 'Great Old One'
|
||||
age: 2147483647
|
||||
}
|
||||
unsafe {
|
||||
assert *(&string(byteptr(&fel) + __offsetof(Feline, name))) == 'Cthulhu'
|
||||
assert *(&string(byteptr(&fel) + __offsetof(Feline, breed))) == 'Great Old One'
|
||||
|
|
|
@ -11,12 +11,16 @@ fn (a Foo) == (b Foo) bool {
|
|||
}
|
||||
|
||||
fn test_operator_overloading_cmp() {
|
||||
a := Foo{i: 38}
|
||||
b := Foo{i: 38}
|
||||
a := Foo{
|
||||
i: 38
|
||||
}
|
||||
b := Foo{
|
||||
i: 38
|
||||
}
|
||||
mut arr := [a, b]
|
||||
|
||||
assert (a > b) == false
|
||||
assert (a < b) == false
|
||||
assert (a < b) == false
|
||||
//// /// //
|
||||
assert a >= b
|
||||
assert a <= b
|
||||
|
|
|
@ -79,5 +79,5 @@ fn test_operator_overloading_with_string_interpolation() {
|
|||
ad *= Vec{2, 2}
|
||||
assert ad.str() == '{8, 18}'
|
||||
ad /= Vec{2, 2}
|
||||
assert ad.str() == '{4, 9}'
|
||||
assert ad.str() == '{4, 9}'
|
||||
}
|
||||
|
|
|
@ -41,9 +41,9 @@ fn test_channel_push() {
|
|||
|
||||
fn test_thread_wait() {
|
||||
thrs := [
|
||||
go f(3)
|
||||
go f(-7)
|
||||
go f(12)
|
||||
go f(3),
|
||||
go f(-7),
|
||||
go f(12),
|
||||
]
|
||||
mut res := []int{cap: 3}
|
||||
for t in thrs {
|
||||
|
@ -56,4 +56,3 @@ fn test_nested_opt() {
|
|||
a := f(f(f(-3) or { -7 }) or { 4 }) or { 17 }
|
||||
assert a == 4
|
||||
}
|
||||
|
||||
|
|
|
@ -36,13 +36,9 @@ fn return_a_string() string {
|
|||
|
||||
//
|
||||
fn test_optional_int() {
|
||||
a := i_0(0) or {
|
||||
4999
|
||||
}
|
||||
a := i_0(0) or { 4999 }
|
||||
assert a == 4999
|
||||
b := i_0(4123) or {
|
||||
4999
|
||||
}
|
||||
b := i_0(4123) or { 4999 }
|
||||
assert b == 4123
|
||||
}
|
||||
|
||||
|
@ -59,13 +55,9 @@ fn test_optional_bool() {
|
|||
}
|
||||
*/
|
||||
fn test_optional_struct() {
|
||||
sa := struct_0(0) or {
|
||||
Abc{7999}
|
||||
}
|
||||
sa := struct_0(0) or { Abc{7999} }
|
||||
assert sa.x == 7999
|
||||
sb := struct_0(3456) or {
|
||||
Abc{7999}
|
||||
}
|
||||
sb := struct_0(3456) or { Abc{7999} }
|
||||
assert sb.x == 3456
|
||||
}
|
||||
|
||||
|
@ -75,16 +67,12 @@ fn test_optional_with_statements_before_last_expression() {
|
|||
Abc{12345}
|
||||
}
|
||||
assert s.x == 12345
|
||||
b := b_0(true) or {
|
||||
false
|
||||
}
|
||||
b := b_0(true) or { false }
|
||||
assert b == true
|
||||
}
|
||||
|
||||
fn test_optional_with_fn_call_as_last_expression() {
|
||||
s := string_0(0) or {
|
||||
return_a_string()
|
||||
}
|
||||
s := string_0(0) or { return_a_string() }
|
||||
assert s == 'abcdef'
|
||||
}
|
||||
|
||||
|
@ -99,46 +87,28 @@ fn test_optional_with_fn_call_last_expr_and_preceding_statements() {
|
|||
|
||||
fn test_nested_optional() {
|
||||
a := i_0(1) or {
|
||||
b := i_0(0) or {
|
||||
3
|
||||
}
|
||||
b := i_0(0) or { 3 }
|
||||
b
|
||||
}
|
||||
assert a == 1
|
||||
b := i_0(0) or {
|
||||
c := i_0(1) or {
|
||||
3
|
||||
}
|
||||
c := i_0(1) or { 3 }
|
||||
c
|
||||
}
|
||||
assert b == 1
|
||||
c := i_0(0) or {
|
||||
d := i_0(0) or {
|
||||
3
|
||||
}
|
||||
d := i_0(0) or { 3 }
|
||||
d
|
||||
}
|
||||
assert c == 3
|
||||
}
|
||||
|
||||
fn test_nested_optional_with_opt_fn_call_as_last_value() {
|
||||
a := i_0(1) or {
|
||||
i_0(0) or {
|
||||
3
|
||||
}
|
||||
}
|
||||
a := i_0(1) or { i_0(0) or { 3 } }
|
||||
assert a == 1
|
||||
b := i_0(0) or {
|
||||
i_0(1) or {
|
||||
3
|
||||
}
|
||||
}
|
||||
b := i_0(0) or { i_0(1) or { 3 } }
|
||||
assert b == 1
|
||||
c := i_0(0) or {
|
||||
i_0(0) or {
|
||||
3
|
||||
}
|
||||
}
|
||||
c := i_0(0) or { i_0(0) or { 3 } }
|
||||
assert c == 3
|
||||
// TODO Enable once optional in boolean expressions are working
|
||||
// d := b_0(true) or {
|
||||
|
@ -156,9 +126,9 @@ fn test_nested_optional_with_opt_fn_call_as_last_value() {
|
|||
}
|
||||
|
||||
fn remove_suffix1(s string) string {
|
||||
n := s.len
|
||||
i := s.last_index('.') or { n }
|
||||
return s[0..i]
|
||||
n := s.len
|
||||
i := s.last_index('.') or { n }
|
||||
return s[0..i]
|
||||
}
|
||||
|
||||
fn test_var_inside_or_block() {
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
|
||||
fn test_error_can_be_converted_to_string(){
|
||||
fn test_error_can_be_converted_to_string() {
|
||||
assert 'Option{ error: "an error" }' == error('an error').str()
|
||||
}
|
||||
|
||||
fn test_error_can_be_assigned_to_a_variable(){
|
||||
fn test_error_can_be_assigned_to_a_variable() {
|
||||
f := error('an error')
|
||||
assert 'Option{ error: "an error" }' == f.str()
|
||||
}
|
||||
|
||||
fn test_error_can_be_printed(){
|
||||
fn test_error_can_be_printed() {
|
||||
f := error('an error')
|
||||
println(f)
|
||||
assert true
|
||||
}
|
||||
|
||||
fn test_error_can_be_interpolated_in_a_string(){
|
||||
fn test_error_can_be_interpolated_in_a_string() {
|
||||
f := error('an error')
|
||||
s := 'hi $f'
|
||||
assert s == 'hi Option{ error: "an error" }'
|
||||
|
|
|
@ -269,7 +269,7 @@ fn test_multi_return_opt() {
|
|||
*/
|
||||
|
||||
fn test_optional_val_with_empty_or() {
|
||||
ret_none() or { }
|
||||
ret_none() or {}
|
||||
assert true
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import sqlite
|
||||
|
||||
struct Upper {
|
||||
id int
|
||||
id int
|
||||
sub SubStruct
|
||||
}
|
||||
|
||||
struct SubStruct {
|
||||
id int
|
||||
id int
|
||||
name string
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module main
|
||||
|
||||
import mod1
|
||||
import v.tests.project_with_c_code.mod1
|
||||
|
||||
fn main() {
|
||||
res := mod1.vadd(1, 2)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import mod1
|
||||
import v.tests.project_with_c_code.mod1
|
||||
|
||||
fn test_using_c_code_in_the_same_module_works(){
|
||||
assert 1003 == mod1.vadd(1,2)
|
||||
fn test_using_c_code_in_the_same_module_works() {
|
||||
assert 1003 == mod1.vadd(1, 2)
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@ struct C.MyStruct {
|
|||
fn C.cadd(int, int) int
|
||||
|
||||
pub fn vadd(a int, b int) int {
|
||||
x := C.MyStruct{ 100 }
|
||||
x := C.MyStruct{100}
|
||||
return 900 + x.UppercaseField + C.cadd(a, b)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module main
|
||||
|
||||
import modc
|
||||
import v.tests.project_with_c_code_2.modc
|
||||
|
||||
// passing array of Vtype to C
|
||||
// Vtype wraps a C type
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import modc
|
||||
import v.tests.project_with_c_code_2.modc
|
||||
|
||||
fn test_using_c_code_in_the_same_module_works() {
|
||||
x := modc.new_vtype(123)
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue