tests: run vfmt over some of the tests in vlib/v/tests (#9455)

pull/9493/head
Lukas Neubert 2021-03-27 18:29:57 +01:00 committed by GitHub
parent 3b166d8327
commit 4a10514081
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
156 changed files with 1573 additions and 945 deletions

View File

@ -21,6 +21,13 @@ const (
'vlib/gg/m4/graphic.v' /* has hand crafted meaningful formatting of matrices */, '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/m4_test.v' /* has hand crafted meaningful formatting of matrices */,
'vlib/gg/m4/matrix.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 = [ vfmt_verify_list = [
'cmd/', 'cmd/',
@ -58,7 +65,7 @@ const (
'vlib/v/preludes', 'vlib/v/preludes',
'vlib/v/scanner/', 'vlib/v/scanner/',
'vlib/v/table/', 'vlib/v/table/',
//'vlib/v/tests/', 'vlib/v/tests/',
'vlib/v/token/', 'vlib/v/token/',
'vlib/v/util/', 'vlib/v/util/',
'vlib/v/vcache/', 'vlib/v/vcache/',

View File

@ -6,5 +6,5 @@ fn test_anon_fn_call() {
} }
fn test() string { fn test() string {
return "Test" return 'Test'
} }

View File

@ -8,7 +8,9 @@ fn test_array_append_short_struct() {
contents: 3 contents: 3
} }
println(pages) println(pages)
assert pages == [Page{contents: 3}] assert pages == [Page{
contents: 3
}]
} }
struct Container { struct Container {
@ -18,8 +20,12 @@ pub mut:
fn test_array_insert_or_prepend_short_struct() { fn test_array_insert_or_prepend_short_struct() {
mut a := []Container{} mut a := []Container{}
a.prepend({name: 'a'}) a.prepend(name: 'a')
a.insert(0, {name: 'b'}) a.insert(0, name: 'b')
println(a) println(a)
assert a == [Container{name: 'b'}, Container{name: 'a'}] assert a == [Container{
name: 'b'
}, Container{
name: 'a'
}]
} }

View File

@ -4,7 +4,9 @@ struct Tester {
} }
enum Color { enum Color {
red green blue red
green
blue
} }
fn test_array_equality() { fn test_array_equality() {
@ -76,6 +78,7 @@ fn test_nested_array_equality() {
} }
type Literal = string type Literal = string
type Literals = []Literal type Literals = []Literal
fn (l1 Literal) concat(l2 Literal) Literals { fn (l1 Literal) concat(l2 Literal) Literals {

View File

@ -32,7 +32,7 @@ fn test_array_or_direct() {
} }
fn test_map_or() { fn test_map_or() {
m := { m := map{
'as': 3 'as': 3
'qw': 4 'qw': 4
'kl': 5 'kl': 5
@ -51,9 +51,12 @@ fn test_map_or() {
assert good == 5 assert good == 5
} }
fn get_map_el(key string) ?int { 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] ? r := m[key] ?
return r return r
} }
@ -90,12 +93,8 @@ fn test_propagation() {
testvar2 = 177 testvar2 = 177
int(-67) int(-67)
} }
m := get_arr_el_direct(3) or { m := get_arr_el_direct(3) or { 17 }
17 n := get_arr_el_direct(0) or { -73 }
}
n := get_arr_el_direct(0) or {
-73
}
assert testvar1 == -34 assert testvar1 == -34
assert testvar2 == 99 assert testvar2 == 99
assert e == 7 assert e == 7
@ -114,8 +113,6 @@ fn get_arr_el_nested(i int) ?int {
} }
fn test_nested_array_propagation() { fn test_nested_array_propagation() {
g := get_arr_el_nested(3) or { g := get_arr_el_nested(3) or { 12 }
12
}
assert g == 12 assert g == 12
} }

View File

@ -17,9 +17,9 @@ fn test_array_map_ref() {
mut m := map[string]int{} mut m := map[string]int{}
mut m_ref := &map[string]f64{} mut m_ref := &map[string]f64{}
mut a := []int{len: 10} 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 m_shared := &map[string]f64{}
shared a_shared := &[]f64{cap: 12, len: 9} shared a_shared := &[]f64{len: 9, cap: 12}
// test usage // test usage
m['a'] = 3 m['a'] = 3
unsafe { unsafe {

View File

@ -5,7 +5,9 @@ mut:
// if this is called more than once, the test'll fail // if this is called more than once, the test'll fail
fn (mut c Counter) new_arr(msg string) []int { fn (mut c Counter) new_arr(msg string) []int {
if c.val > 0 { panic(msg) } if c.val > 0 {
panic(msg)
}
c.val++ c.val++
return [1, 3, 2] return [1, 3, 2]
} }

View File

@ -45,7 +45,13 @@ fn test_interpolation_array_to_string() {
fn test_interpolation_array_of_map_to_string() { fn test_interpolation_array_of_map_to_string() {
mut ams := []map[string]string{} mut ams := []map[string]string{}
ams << {'a': 'b', 'c': 'd'} ams << map{
ams << {'e': 'f', 'g': 'h'} 'a': 'b'
'c': 'd'
}
ams << map{
'e': 'f'
'g': 'h'
}
assert '$ams' == "[{'a': 'b', 'c': 'd'}, {'e': 'f', 'g': 'h'}]" assert '$ams' == "[{'a': 'b', 'c': 'd'}, {'e': 'f', 'g': 'h'}]"
} }

View File

@ -1,6 +1,16 @@
const( str = 'abcdefghijklmnopqrstuvwxyz' num = 1234567890 ) const (
struct S1 { s1 string = str } str = 'abcdefghijklmnopqrstuvwxyz'
struct S2 { s2 int = num } num = 1234567890
)
struct S1 {
s1 string = str
}
struct S2 {
s2 int = num
}
type Sum = S1 | S2 type Sum = S1 | S2
fn test_as_cast_with_sumtype_fn_result() { fn test_as_cast_with_sumtype_fn_result() {

View File

@ -1,7 +1,8 @@
struct Moon {} struct Moon {}
struct Mars {} struct Mars {}
type World = Moon | Mars type World = Mars | Moon
fn test_assert_sumtype() { fn test_assert_sumtype() {
w := World(Moon{}) w := World(Moon{})

View File

@ -22,9 +22,7 @@ pub enum PubEnumAttrTest {
two two
} }
[attrone; attrtwo]
[attrone]
[attrtwo]
pub enum EnumMultiAttrTest { pub enum EnumMultiAttrTest {
one one
two two
@ -40,8 +38,7 @@ pub fn test_pub_fn_attribute() {
assert true assert true
} }
[attrone] [attrone; attrtwo]
[attrtwo]
fn test_fn_multi_attribute() { fn test_fn_multi_attribute() {
assert true assert true
} }

View File

@ -41,50 +41,40 @@ fn test_assign_multi_expr() {
assert c == 6 assert c == 6
// test with first value `literal` // test with first value `literal`
d, e, f := if true { d, e, f := if true { 1, 'awesome', [13] } else { 0, 'bad', [0] }
1, 'awesome', [13]
} else {
0, 'bad', [0]
}
assert d == 1 assert d == 1
assert e == 'awesome' assert e == 'awesome'
assert f == [13] assert f == [13]
// test with first value `literal expr` and statement // test with first value `literal expr` and statement
awesome := 'awesome' awesome := 'awesome'
g, h, i := if true { g, h, i := if true { 1 + val1, awesome, [13] } else { int(0), 'bad', [0] }
1 + val1, awesome, [13]
} else {
int(0), 'bad', [0]
}
assert g == 2 assert g == 2
assert h == 'awesome' assert h == 'awesome'
assert i == [13] assert i == [13]
// test with first value `.name` // test with first value `.name`
j, k, l := if true { j, k, l := if true { val1, 'awesome', [13] } else { val2, 'bad', [0] }
val1, 'awesome', [13]
} else {
val2, 'bad', [0]
}
assert j == 1 assert j == 1
assert k == 'awesome' assert k == 'awesome'
assert l == [13] assert l == [13]
// test with first value name and peek != .comma // test with first value name and peek != .comma
m, n, o := if true { m, n, o := if true { val1 + 1, val1, val1 } else { val2, val2, val2 }
val1 + 1, val1, val1
} else {
val2, val2, val2
}
assert m == val1 + 1 assert m == val1 + 1
assert n == val1 assert n == val1
assert o == val1 assert o == val1
// test practical complex expressions // test practical complex expressions
val3 := Object { name: 'initial', value: 19 } val3 := Object{
name: 'initial'
value: 19
}
mut q, mut r, mut s := if true { 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 { } else {
0, '0', Object{} 0, '0', Object{}
} }
@ -97,7 +87,10 @@ fn test_assign_multi_expr() {
q, r, s = if false { q, r, s = if false {
0, '0', Object{} 0, '0', Object{}
} else { } else {
5, '55', Object{ ...val3, value: 555 } 5, '55', Object{
...val3
value: 555
}
} }
assert q == 5 assert q == 5
assert r == '55' assert r == '55'
@ -106,7 +99,7 @@ fn test_assign_multi_expr() {
} }
fn test_issue_9330() { fn test_issue_9330() {
arr := "0.1".split('.') arr := '0.1'.split('.')
a0, a1 := arr[0], arr[1].int() a0, a1 := arr[0], arr[1].int()
assert a0 == '0' assert a0 == '0'
assert a1 == 1 assert a1 == 1
@ -119,5 +112,4 @@ fn test_issue_9330() {
d0, d1 := arr[0].int(), arr[1].f64() d0, d1 := arr[0].int(), arr[1].f64()
assert d0 == 0 assert d0 == 0
assert d1 == 1.0 assert d1 == 1.0
} }

View File

@ -3,12 +3,15 @@ struct Test {}
fn (test Test) v() { fn (test Test) v() {
println('Test.v()') println('Test.v()')
} }
fn (test Test) i() int { fn (test Test) i() int {
return 4 return 4
} }
fn (test Test) s() string { fn (test Test) s() string {
return 'test' return 'test'
} }
fn (test Test) s2() string { fn (test Test) s2() string {
return 'Two' return 'Two'
} }
@ -33,15 +36,13 @@ fn test_for_methods() {
$if method.return_type is string { $if method.return_type is string {
v := test.$method() v := test.$method()
r += v.str() r += v.str()
} } $else $if method.return_type is int {
$else $if method.return_type is int {
// TODO // TODO
// v := test.$method() // v := test.$method()
v := '?' v := '?'
r += v.str() r += v.str()
assert method.name == 'i' assert method.name == 'i'
} } $else {
$else {
// no return type // no return type
test.$method() test.$method()
assert method.name == 'v' assert method.name == 'v'
@ -64,4 +65,3 @@ fn test_methods_arg() {
assert r == '!!!' assert r == '!!!'
} }
} }

View File

@ -26,4 +26,3 @@ fn test_is_or() {
assert g(i8(1)) == 1 assert g(i8(1)) == 1
assert g(1) == 2 assert g(1) == 2
} }

View File

@ -8,9 +8,11 @@ mut:
fn (mut t TestStruct) one_arg(a1 string) { fn (mut t TestStruct) one_arg(a1 string) {
t.one_arg_called = true t.one_arg_called = true
} }
fn (mut t TestStruct) two_args(a2 string, b2 int) { fn (mut t TestStruct) two_args(a2 string, b2 int) {
t.two_args_called = true t.two_args_called = true
} }
fn (mut t TestStruct) three_args(a3 string, b3 int, c3 []string) { fn (mut t TestStruct) three_args(a3 string, b3 int, c3 []string) {
t.three_args_called = true t.three_args_called = true
} }
@ -43,7 +45,7 @@ fn test_comptime_call_method() {
} else if method.name == 'two_args' { } else if method.name == 'two_args' {
t.$method('two', 2) t.$method('two', 2)
} else if method.name == 'three_args' { } else if method.name == 'three_args' {
t.$method('three', 3, ['th' 'ree']) t.$method('three', 3, ['th', 'ree'])
} }
} }
assert t.one_arg_called assert t.one_arg_called

View File

@ -26,7 +26,10 @@ fn test_cross_assign_of_array_in_fn() {
// Test cross assign of map values // Test cross assign of map values
fn test_cross_assign_of_map() { 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'] a['one'], a['two'] = a['two'], a['one']
println(a) println(a)
assert a['one'] == 2 assert a['one'] == 2
@ -39,7 +42,10 @@ fn foo2(mut a map[string]int) {
} }
fn test_cross_assign_of_map_in_fn() { fn test_cross_assign_of_map_in_fn() {
mut a := {'one':1, 'two':2} mut a := map{
'one': 1
'two': 2
}
foo2(mut a) foo2(mut a)
assert a['one'] == 2 assert a['one'] == 2
assert a['two'] == 1 assert a['two'] == 1
@ -53,7 +59,10 @@ mut:
} }
fn test_cross_assign_of_struct() { 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 x.a, x.b = x.b, x.a
// println(x) // println(x)
assert x.a == 2 assert x.a == 2
@ -72,7 +81,10 @@ fn foo3(mut f Foo) {
} }
fn test_cross_assign_of_struct_in_fn() { 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) foo3(mut a)
println(a) println(a)
assert a.a == 2 assert a.a == 2
@ -82,8 +94,14 @@ fn test_cross_assign_of_struct_in_fn() {
// Test cross assign of mixed types // Test cross assign of mixed types
fn test_cross_assign_of_mixed_types() { fn test_cross_assign_of_mixed_types() {
mut a := [0, 1] mut a := [0, 1]
mut m := {'one':1, 'two':2} mut m := map{
mut x := Zoo{a:1, b:2} '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 a[0], m['one'], x.a, a[1], m['two'], x.b = a[1], m['two'], x.b, a[0], m['one'], x.a
@ -101,8 +119,14 @@ fn foo(mut a []int, mut m map[string]int, mut x Zoo) {
fn test_cross_assign_of_mixed_types_in_fn() { fn test_cross_assign_of_mixed_types_in_fn() {
mut a := [0, 1] mut a := [0, 1]
mut m := {'one':1, 'two':2} mut m := map{
mut x := Zoo{a:1, b:2} 'one': 1
'two': 2
}
mut x := Zoo{
a: 1
b: 2
}
foo(mut a, mut m, mut x) foo(mut a, mut m, mut x)
@ -116,8 +140,14 @@ fn test_cross_assign_of_mixed_types_in_fn() {
// Test cross assign of complex types // Test cross assign of complex types
fn test_cross_assign_of_complex_types() { fn test_cross_assign_of_complex_types() {
mut a := [0, 1] mut a := [0, 1]
mut m := {'one':1, 'two':2} mut m := map{
mut x := Zoo{a:1, b:2} '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

View File

@ -46,7 +46,6 @@ fn test_fixed_array_can_be_used_in_declaration() {
assert v[1] == x assert v[1] == x
} }
struct Context { struct Context {
pub mut: pub mut:
vb [8]f64 vb [8]f64
@ -120,4 +119,3 @@ fn test_for_in_fixed_array() {
arr := [1, 2, 3]! arr := [1, 2, 3]!
calc_size(arr) calc_size(arr)
} }

View File

@ -51,5 +51,3 @@ fn test_fn_assignment_array() {
assert a[0] == 12 assert a[0] == 12
assert a[1] == 10 assert a[1] == 10
} }

View File

@ -1,4 +1,3 @@
fn cross_assign_anon_fn_one(a int, b bool) string { fn cross_assign_anon_fn_one(a int, b bool) string {
return 'one' return 'one'
} }

View File

@ -2,10 +2,12 @@ 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) {
println('>process_foo, called for ${foo} === ${*foo}') println('>process_foo, called for $foo === ${*foo}')
} }
fn get_foo() Foo { fn get_foo() Foo {

View File

@ -13,20 +13,19 @@ fn high_fn_no_ret(f fn(int)) {
} }
fn high_fn_array(f fn(a []int) []int) { 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_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 _ = 1
correct := fn (n int) f32 { correct := fn (n int) f32 {
return f32(n * n) return f32(n * n)
} }
return correct 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 // parsing trap
_ = fn (n int) byte { _ = fn (n int) byte {
@ -44,9 +43,11 @@ fn high_fn_return_multi_anons() (fn(int)f32, fn(int)string) {
} }
return correct_first, correct_second 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 return sqr
} }
fn test_high_fn_ret_anons() { fn test_high_fn_ret_anons() {
param := 13 param := 13
func_sqr1 := high_fn_return_single_anon() 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 { fn high_fn_applier(arg int, func fn(a int)string) string {
return func(arg) return func(arg)
} }
fn test_high_fn_applier() { fn test_high_fn_applier() {
arg := 13 arg := 13
expect := '$arg $arg' expect := '$arg $arg'
@ -121,7 +123,7 @@ fn simple_fn1() int {
} }
fn simple_fn2(n f32) (int, string) { fn simple_fn2(n f32) (int, string) {
return int(1 + n), "fish" return int(1 + n), 'fish'
} }
fn test_assigning_fns() { fn test_assigning_fns() {
@ -131,13 +133,13 @@ fn test_assigning_fns() {
func2 := simple_fn2 func2 := simple_fn2
res2_1, res2_2 := func2(13.0) res2_1, res2_2 := func2(13.0)
assert res2_1 == 14.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 return s.len
} }
func3 := anon_func1 func3 := anon_func1
res3 := func3("fish") res3 := func3('fish')
assert res3 == 4 assert res3 == 4
} }

View File

@ -18,9 +18,13 @@ fn test_fn_array_direct_call() {
} }
fn test_fn_map_direct_call() { fn test_fn_map_direct_call() {
a := { a := map{
'aaa': fn()string {return 'aaa'}, 'aaa': fn () string {
'bbb': fn()string {return 'bbb'}, return 'aaa'
}
'bbb': fn () string {
return 'bbb'
}
} }
println(a['aaa']()) println(a['aaa']())
println(a['bbb']()) println(a['bbb']())

View File

@ -14,7 +14,9 @@ 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
} }
@ -30,9 +32,7 @@ fn split_to_two(s string) ?(string, string) {
} }
fn returnable_fail() string { fn returnable_fail() string {
_,_ := split_to_two('bad') or { _, _ := split_to_two('bad') or { return 'ok' }
return 'ok'
}
return 'nok' return 'nok'
} }
@ -41,7 +41,7 @@ fn test_multiple_ret() {
assert returnable_fail() == 'ok' assert returnable_fail() == 'ok'
// good case // good case
res1_1, res1_2 := split_to_two("fish house") or { res1_1, res1_2 := split_to_two('fish house') or {
assert false assert false
return return
} }
@ -50,7 +50,7 @@ fn test_multiple_ret() {
// none case // none case
wrapper1 := fn () (string, string) { wrapper1 := fn () (string, string) {
res2_1, res2_2 := split_to_two("") or { res2_1, res2_2 := split_to_two('') or {
assert err.msg == '' assert err.msg == ''
return 'replaced', 'val' return 'replaced', 'val'
} }

View File

@ -12,12 +12,16 @@ fn test_fn_mut_args_of_array() {
} }
fn init_map(mut n map[string]int) { fn init_map(mut n map[string]int) {
n = {'one': 1} n = map{
'one': 1
}
} }
fn test_fn_mut_args_of_map() { fn test_fn_mut_args_of_map() {
mut m := map[string]int{} mut m := map[string]int{}
init_map(mut m) init_map(mut m)
println(m) println(m)
assert m == {'one': 1} assert m == map{
'one': 1
}
} }

View File

@ -4,7 +4,9 @@ mut:
} }
fn f() shared St { fn f() shared St {
shared x := St{ x: 3.25 } shared x := St{
x: 3.25
}
return x return x
} }
@ -12,19 +14,25 @@ fn g(good bool) ?shared St {
if !good { if !good {
return error('no shared St created') return error('no shared St created')
} }
shared x := St{ x: 12.75 } shared x := St{
x: 12.75
}
return x return x
} }
fn test_shared_fn_return() { fn test_shared_fn_return() {
shared x := f() shared x := f()
val := rlock x { x.x } val := rlock x {
x.x
}
assert val == 3.25 assert val == 3.25
} }
fn shared_opt_propagate(good bool) ?f64 { fn shared_opt_propagate(good bool) ?f64 {
shared x := g(good) ? shared x := g(good) ?
ret := rlock x { x.x } ret := rlock x {
x.x
}
return ret return ret
} }
@ -37,18 +45,26 @@ fn test_shared_opt_propagate() {
fn test_shared_opt_good() { fn test_shared_opt_good() {
shared yy := g(true) or { shared yy := g(true) or {
shared my_default := St{ x: 37.5 } shared my_default := St{
x: 37.5
}
my_default my_default
} }
val := rlock yy { yy.x } val := rlock yy {
yy.x
}
assert val == 12.75 assert val == 12.75
} }
fn test_shared_opt_bad() { fn test_shared_opt_bad() {
shared yy := g(false) or { shared yy := g(false) or {
shared my_default := St{ x: 37.5 } shared my_default := St{
x: 37.5
}
my_default my_default
} }
val := rlock yy { yy.x } val := rlock yy {
yy.x
}
assert val == 37.5 assert val == 37.5
} }

View File

@ -64,7 +64,11 @@ fn test_for_in_fixed_array_of_fixed_array_literal() {
fn test_for_in_map_of_fixed_array() { fn test_for_in_map_of_fixed_array() {
mut rets := []string{} 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 { for k, v in m {
println('$k, $v') println('$k, $v')
@ -78,7 +82,11 @@ fn test_for_in_map_of_fixed_array() {
fn test_for_in_map_of_fixed_array_literal() { fn test_for_in_map_of_fixed_array_literal() {
mut rets := []string{} 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') println('$k, $v')
rets << '$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() { fn test_for_mut_in_map_of_fixed_array() {
mut rets := []string{} 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 { for k, mut v in m {
println('$k, $v') println('$k, $v')

View File

@ -31,7 +31,9 @@ fn foo3(mut m map[string][3]int){
} }
fn test_fn_mut_val_of_map() { fn test_fn_mut_val_of_map() {
mut m := {'hello': [1,2,3]!} mut m := map{
'hello': [1, 2, 3]!
}
foo3(mut m) foo3(mut m)
println(m) println(m)
assert '$m' == "{'hello': [2, 4, 6]}" assert '$m' == "{'hello': [2, 4, 6]}"
@ -44,14 +46,19 @@ fn foo4(mut m map[string][3]int){
} }
fn test_for_in_mut_val_of_map() { fn test_for_in_mut_val_of_map() {
mut m := {'hello':[1,2,3]!} mut m := map{
'hello': [1, 2, 3]!
}
foo4(mut m) foo4(mut m)
println(m) println(m)
assert '$m' == "{'hello': [2, 4, 6]}" assert '$m' == "{'hello': [2, 4, 6]}"
} }
fn test_for_in_mut_val_of_map_direct() { 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 { for _, mut j in m {
j = 3 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() { 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 { for _, mut j in m {
j = [{'c': 3}]! j = [map{
'c': 3
}]!
} }
println(m) println(m)
assert '$m' == "{'foo': [{'c': 3}], 'bar': [{'c': 3}]}" assert '$m' == "{'foo': [{'c': 3}], 'bar': [{'c': 3}]}"

View File

@ -62,7 +62,14 @@ fn test_for_in_fixed_array_label_continue_break() {
fn test_for_in_map_label_continue_break() { fn test_for_in_map_label_continue_break() {
mut rets := []string{} 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 { outer: for k, v in m {
println('$k, $v') println('$k, $v')
rets << '$k, $v' rets << '$k, $v'

View File

@ -44,7 +44,7 @@ fn test_for_char_in_string() {
} }
fn test_for_string_in_map() { fn test_for_string_in_map() {
m := { m := map{
'a': 'b' 'a': 'b'
'c': 'd' 'c': 'd'
} }
@ -54,7 +54,11 @@ fn test_for_string_in_map() {
} }
assert acc == 'a: b, c: d, ' 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') m2.delete('b')
acc = '' acc = ''
for k, v in m2 { for k, v in m2 {

View File

@ -2,6 +2,7 @@ type Node = Expr | string
type Expr = IfExpr | IntegerLiteral type Expr = IfExpr | IntegerLiteral
struct IntegerLiteral {} struct IntegerLiteral {}
struct IfExpr { struct IfExpr {
pos int pos int
} }
@ -11,7 +12,9 @@ struct NodeWrapper {
} }
fn test_nested_sumtype_selector() { fn test_nested_sumtype_selector() {
c := NodeWrapper{Node(Expr(IfExpr{pos: 1}))} c := NodeWrapper{Node(Expr(IfExpr{
pos: 1
}))}
for c.node is Expr { for c.node is Expr {
assert typeof(c.node).name == 'Expr' assert typeof(c.node).name == 'Expr'
break break
@ -28,7 +31,7 @@ mut:
name string name string
} }
type Food = Milk | Eggs type Food = Eggs | Milk
struct FoodWrapper { struct FoodWrapper {
mut: mut:

View File

@ -1,11 +1,18 @@
struct BuildData { x int } struct BuildData {
struct Tensor { x int } x int
}
struct Tensor {
x int
}
fn new_tensor<T>(data BuildData) Tensor { fn new_tensor<T>(data BuildData) Tensor {
println('data: $data') println('data: $data')
x := T(data.x) x := T(data.x)
println(x) println(x)
return Tensor{data.x} return Tensor{data.x}
} }
fn test_generic_function_returning_type_starting_with_t() { fn test_generic_function_returning_type_starting_with_t() {
ft := new_tensor<f64>(x: 123) ft := new_tensor<f64>(x: 123)
println(ft) println(ft)
@ -24,6 +31,7 @@ fn new_t<T>(o T) T {
x := T(o) x := T(o)
return x return x
} }
fn test_generic_function_returning_t_type() { fn test_generic_function_returning_t_type() {
f := new_t<f64>(1.23) f := new_t<f64>(1.23)
i := new_t<int>(456) i := new_t<int>(456)

View File

@ -12,7 +12,7 @@ fn show_result<T, U>(x T, y U) bool {
fn test_generic_fn_upper_name_type() { fn test_generic_fn_upper_name_type() {
assert show_result<int, bool>(1, false) assert show_result<int, bool>(1, false)
assert show_result<string, XX>( "s", XX{}) assert show_result<string, XX>('s', XX{})
assert show_result< XX, string>(XX{}, "s") assert show_result<XX, string>(XX{}, 's')
assert show_result<XX, YY>(XX{}, YY{}) assert show_result<XX, YY>(XX{}, YY{})
} }

View File

@ -1,6 +1,6 @@
module main module main
import genericmodule import v.tests.generics_from_modules.genericmodule
fn test_generic_function_from_another_module() { fn test_generic_function_from_another_module() {
v1 := genericmodule.take<int>(true, 10, 20) v1 := genericmodule.take<int>(true, 10, 20)

View File

@ -11,7 +11,9 @@ fn test_identity() {
assert simple<string>('g') + 'h' == 'gh' assert simple<string>('g') + 'h' == 'gh'
assert simple<[]int>([1])[0] == 1 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
} }
@ -118,7 +120,9 @@ fn test_return_array() {
} }
fn opt<T>(v T) ?T { fn opt<T>(v T) ?T {
if sizeof(T) > 1 {return v} if sizeof(T) > 1 {
return v
}
return none return none
} }
@ -296,7 +300,6 @@ fn test_generic_struct_print_array_as_field() {
data: []string{} data: []string{}
} }
assert foo.str() == 'Foo<array, string>{\n data: []\n}' assert foo.str() == 'Foo<array, string>{\n data: []\n}'
} }
/* /*
@ -361,10 +364,13 @@ fn method_test<T>(mut app T) {
fn test_pass_generic_to_nested_method() { fn test_pass_generic_to_nested_method() {
mut app := App{} mut app := App{}
method_test(mut app) method_test(mut app)
}*/ }
*/
fn generic_return_map<M>() map[string]M { fn generic_return_map<M>() map[string]M {
return {'': M{}} return map{
'': M{}
}
} }
fn test_generic_return_map() { 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 { fn generic_return_nested_map<M>() map[string]map[string]M {
return {'': {'': M{}}} return map{
'': map{
'': M{}
}
}
} }
fn test_generic_return_nested_map() { fn test_generic_return_nested_map() {
@ -384,8 +394,11 @@ fn multi_return<A, B>() (A, B) {
} }
struct Foo1 {} struct Foo1 {}
struct Foo2 {} struct Foo2 {}
struct Foo3 {} struct Foo3 {}
struct Foo4 {} struct Foo4 {}
fn test_multi_return() { fn test_multi_return() {
@ -399,7 +412,7 @@ fn multi_generic_args<T, V>(t T, v V) bool {
} }
fn test_multi_generic_args() { fn test_multi_generic_args() {
assert multi_generic_args("Super", 2021) assert multi_generic_args('Super', 2021)
} }
fn new<T>() T { fn new<T>() T {

View File

@ -19,15 +19,15 @@ fn g(shared a []int, i int) {
} }
fn test_array_thread_void_wait() { 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 := [ t := [
go g(shared a, 0) go g(shared a, 0),
go g(shared a, 3) go g(shared a, 3),
go g(shared a, 6) go g(shared a, 6),
go g(shared a, 2) go g(shared a, 2),
go g(shared a, 1) go g(shared a, 1),
go g(shared a, 5) go g(shared a, 5),
go g(shared a, 4) go g(shared a, 4),
] ]
println('threads started') println('threads started')
t.wait() t.wait()
@ -37,7 +37,7 @@ fn test_array_thread_void_wait() {
} }
fn test_void_thread_decl() { fn test_void_thread_decl() {
shared a := [2 3 9] shared a := [2, 3, 9]
mut t1 := thread(0) mut t1 := thread(0)
mut tarr := []thread{len: 2} mut tarr := []thread{len: 2}
t1 = go g(shared a, 0) t1 = go g(shared a, 0)

View File

@ -18,7 +18,10 @@ fn test_fn_return() {
} }
fn test_map_get() { fn test_map_get() {
mut m := {'xy': 5, 'zu': 7} mut m := map{
'xy': 5
'zu': 7
}
mut res := []int{cap: 2} mut res := []int{cap: 2}
for k in ['jk', 'zu'] { for k in ['jk', 'zu'] {
if x := m[k] { if x := m[k] {

View File

@ -38,7 +38,7 @@ fn test_nested_if_smartcast() {
} }
} }
type Bar = string | Test type Bar = Test | string
type Xya = int | string type Xya = int | string
struct Test { struct Test {
@ -69,10 +69,12 @@ fn test_nested_selector_smartcast() {
} }
type Inner = int | string type Inner = int | string
struct InnerStruct { struct InnerStruct {
x Inner x Inner
} }
type Outer = string | InnerStruct
type Outer = InnerStruct | string
fn test_nested_if_is() { fn test_nested_if_is() {
b := Outer(InnerStruct{Inner(0)}) b := Outer(InnerStruct{Inner(0)})
@ -168,11 +170,13 @@ fn test_mutability() {
} }
} }
type Expr = CallExpr | CTempVarExpr type Expr = CTempVarExpr | CallExpr
struct ExprWrapper { struct ExprWrapper {
mut: mut:
expr Expr expr Expr
} }
struct CallExpr { struct CallExpr {
y int y int
x string x string
@ -196,21 +200,21 @@ fn test_reassign_from_function_with_parameter_selector() {
type Node = Expr | string type Node = Expr | string
fn test_nested_sumtype() { fn test_nested_sumtype() {
c := Node(Expr(CallExpr{y: 1})) c := Node(Expr(CallExpr{
y: 1
}))
if c is Expr { if c is Expr {
if c is CallExpr { if c is CallExpr {
assert c.y == 1 assert c.y == 1
} } else {
else {
assert false assert false
} }
} } else {
else {
assert false assert false
} }
} }
type Food = Milk | Eggs type Food = Eggs | Milk
struct FoodWrapper { struct FoodWrapper {
mut: mut:
@ -240,16 +244,16 @@ struct NodeWrapper {
} }
fn test_nested_sumtype_selector() { 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 Expr {
if c.node is CallExpr { if c.node is CallExpr {
assert c.node.y == 1 assert c.node.y == 1
} } else {
else {
assert false assert false
} }
} } else {
else {
assert false assert false
} }
} }
@ -284,8 +288,12 @@ pub mut:
fn test_nested_pointer_smartcast() { fn test_nested_pointer_smartcast() {
mut s := All_in_one{ mut s := All_in_one{
ptr: &Sum1(Foo1{a: 1}) ptr: &Sum1(Foo1{
ptrs: [&SumAll(Sum2(Bar1{a: 3}))] a: 1
})
ptrs: [&SumAll(Sum2(Bar1{
a: 3
}))]
} }
if mut s.ptr is Sum1 { if mut s.ptr is Sum1 {

View File

@ -1,11 +1,17 @@
module main 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() { fn test_imported_symbols_types() {
// struct init // struct init
p0 := Point{x: 10 y: 20} p0 := Point{
p1 := Point{x: 40 y: 60} x: 10
y: 20
}
p1 := Point{
x: 40
y: 60
}
// array init // array init
l0 := Line{ l0 := Line{
ps: [p0, p1] ps: [p0, p1]
@ -14,7 +20,10 @@ fn test_imported_symbols_types() {
} }
fn test_imported_symbols_functions() { fn test_imported_symbols_functions() {
p0 := Point{x: 20 y: 40} p0 := Point{
x: 20
y: 40
}
// method // method
assert p0.str() == '20 40' assert p0.str() == '20 40'
// function // function

View File

@ -1,5 +1,8 @@
enum Colors { enum Colors {
red green blue yellow red
green
blue
yellow
} }
fn test_in_expression() { fn test_in_expression() {
@ -105,7 +108,7 @@ fn test_in_expression_with_string() {
} }
fn test_in_expression_in_map() { fn test_in_expression_in_map() {
m := { m := map{
'one': 1 'one': 1
'two': 2 'two': 2
'three': 3 'three': 3

View File

@ -21,9 +21,7 @@ fn test_all() {
println('no compiler tests found') println('no compiler tests found')
assert false assert false
} }
paths := vtest.filter_vtest_only(tests, paths := vtest.filter_vtest_only(tests, basepath: dir)
basepath: dir
)
for path in paths { for path in paths {
print(path + ' ') print(path + ' ')
program := path program := path

View File

@ -1,5 +1,10 @@
struct Dog { breed string } struct Dog {
struct Cat { breed string } breed string
}
struct Cat {
breed string
}
interface Animal { interface Animal {
breed string breed string
@ -26,7 +31,9 @@ struct Holder2 {
fn test_auto_str_gen_for_complex_interface_types() { fn test_auto_str_gen_for_complex_interface_types() {
a := Animal(Dog{'hi'}) a := Animal(Dog{'hi'})
h := Holder{a} h := Holder{a}
m := map{'dsa': h} m := map{
'dsa': h
}
h2 := Holder2{m, 'N/A'} h2 := Holder2{m, 'N/A'}
a2 := Animal(h2) a2 := Animal(h2)

View File

@ -39,7 +39,7 @@ fn test_interface_struct() {
name: 'Richard' 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: ') print('Test Boss inside Baz struct: ')
bz1.sp.speak('Hello world!') bz1.sp.speak('Hello world!')
bz2 := Baz{ bz2 := Baz{
@ -59,7 +59,7 @@ fn test_interface_mut_struct() {
name: 'Derek' 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{ mbaz.sp = Cat{
name: 'Dog' name: 'Dog'
breed: 'Not a 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[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"
} }
/* /*

View File

@ -1,7 +1,5 @@
module local module local
pub fn local_fn() bool { pub fn local_fn() bool {
return true return true
} }

View File

@ -2,21 +2,33 @@ type Type = int
type RType = rune type RType = rune
fn test_map_key_alias() { 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[14] = '14'
m_int[Type(15)] = '15' m_int[Type(15)] = '15'
assert m_int.str() == "{12: '12', 2: '2', 14: '14', 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[`g`] = '12'
m_rune[RType(`$`)] = '16' m_rune[RType(`$`)] = '16'
assert m_rune.str() == "{`a`: '12', `l`: '14', `g`: '12', `$`: '16'}" assert m_rune.str() == "{`a`: '12', `l`: '14', `g`: '12', `$`: '16'}"
} }
fn test_map_alias_key_init() { 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'}" 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'}" assert m_rune.str() == "{`a`: '12', `l`: '14'}"
} }

View File

@ -37,9 +37,15 @@ fn test_array_with_fns() {
} }
fn test_map_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.len == 2
assert (a == {'one':foo, 'two':foo2}) == true assert (a == map{
'one': foo
'two': foo2
}) == true
f0 := a['one'] f0 := a['one']
assert f0('xx', '') == 12 assert f0('xx', '') == 12
f1 := a['two'] f1 := a['two']
@ -49,7 +55,9 @@ fn test_map_with_fns() {
assert f2('zzzz', '') == 24 assert f2('zzzz', '') == 24
f3 := a['two'] f3 := a['two']
assert f3('aaaaa', '') == 15 assert f3('aaaaa', '') == 15
mut b := {'one':foo} mut b := map{
'one': foo
}
b['one'] = a['one'] b['one'] = a['one']
f4 := b['one'] f4 := b['one']
assert f4('bbbbbb', '') == 26 assert f4('bbbbbb', '') == 26
@ -70,7 +78,9 @@ fn test_map_and_array_with_fns_typeof_and_direct_call() {
a := [foo3] a := [foo3]
assert typeof(a).name == '[]fn (string) int' assert typeof(a).name == '[]fn (string) int'
assert a[0]('hello') == 15 assert a[0]('hello') == 15
b := {'one': foo3} b := map{
'one': foo3
}
assert typeof(b).name == 'map[string]fn (string) int' assert typeof(b).name == 'map[string]fn (string) int'
assert b['one']('hi') == 12 assert b['one']('hi') == 12
} }
@ -101,8 +111,12 @@ fn bar4(mut m map[string]fn (string) int) int {
} }
fn test_map_of_fns_as_argument() { fn test_map_of_fns_as_argument() {
m1 := {'fn': foo3} m1 := map{
'fn': foo3
}
assert bar3(m1) == 12 assert bar3(m1) == 12
mut m2 := {'fn': foo3} mut m2 := map{
'fn': foo3
}
assert bar4(mut m2) == 22 assert bar4(mut m2) == 22
} }

View File

@ -1,17 +1,25 @@
fn foo(mut m map[string][1][2]map[string]int) { 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() { 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) foo(mut m)
println(m) println(m)
assert '$m' == "{'foo': [[{'bar': 1}, {'baz': 3}]]}" assert '$m' == "{'foo': [[{'bar': 1}, {'baz': 3}]]}"
} }
fn test_innermost_value_of_map_fixed_array() { fn test_innermost_value_of_map_fixed_array() {
mut m := map[string][1][2]map[string]int mut m := map[string][1][2]map[string]int{}
m['foo'] = [[{'bar': 1}, {'baz': 3}]!]! m['foo'] = [[map{
'bar': 1
}, map{
'baz': 3
}]!]!
println(m['foo'][0][0]['bar']) println(m['foo'][0][0]['bar'])
println(m['foo'][0][0]['bar'] == 1) println(m['foo'][0][0]['bar'] == 1)
assert 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() { 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 { for _, mut j in m {
j = [[{'c': 3}]!]! j = [[map{
'c': 3
}]!]!
} }
println(m) println(m)
assert '$m' == "{'foo': [[{'c': 3}]], 'bar': [[{'c': 3}]]}" assert '$m' == "{'foo': [[{'c': 3}]], 'bar': [[{'c': 3}]]}"

View File

@ -1,18 +1,38 @@
fn test_map_equality() { fn test_map_equality() {
a1 := {'a':1, 'b':2} a1 := map{
b1 := {'b':2, 'a':1} 'a': 1
c1 := {'a':2, 'b':1} 'b': 2
}
b1 := map{
'b': 2
'a': 1
}
c1 := map{
'a': 2
'b': 1
}
assert a1 == b1 assert a1 == b1
assert a1 != c1 assert a1 != c1
a2 := {'a':1} a2 := map{
b2 := {'a':1, 'b':2} 'a': 1
}
b2 := map{
'a': 1
'b': 2
}
assert a2 != b2 assert a2 != b2
a3 := {'a':'1', 'b':'2'} a3 := map{
b3 := {'b':'2', 'a':'1'} 'a': '1'
'b': '2'
}
b3 := map{
'b': '2'
'a': '1'
}
assert a3 == b3 assert a3 == b3
} }

View File

@ -1,5 +1,5 @@
fn test_high_order_map_assign() { fn test_high_order_map_assign() {
mut m := map[string]map[string]int mut m := map[string]map[string]int{}
m['hello']['hi'] = 1 m['hello']['hi'] = 1
println(m) println(m)
assert '$m' == "{'hello': {'hi': 1}}" assert '$m' == "{'hello': {'hi': 1}}"

View File

@ -13,7 +13,8 @@ fn test_const_keys() {
} }
enum Enum { enum Enum {
a b a
b
} }
const ( const (

View File

@ -5,28 +5,33 @@ struct Test {
} }
fn test_interpolation_map_to_string() { fn test_interpolation_map_to_string() {
mut a := map[string]string mut a := map[string]string{}
a['1'] = 'one' a['1'] = 'one'
a['2'] = 'two' a['2'] = 'two'
a['3'] = 'three' a['3'] = 'three'
assert '$a' == "{'1': 'one', '2': 'two', '3': 'three'}" assert '$a' == "{'1': 'one', '2': 'two', '3': 'three'}"
mut b := map[string]int mut b := map[string]int{}
b['1'] = 1 b['1'] = 1
b['2'] = 2 b['2'] = 2
b['3'] = 3 b['3'] = 3
assert '$b' == "{'1': 1, '2': 2, '3': 3}" assert '$b' == "{'1': 1, '2': 2, '3': 3}"
mut c := map[string]bool mut c := map[string]bool{}
c['1'] = true c['1'] = true
c['2'] = false c['2'] = false
assert '$c' == "{'1': true, '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') println('d: $d')
assert '$d' == "{'f1': 1.1, 'f2': 2.2, 'f3': 3.3, 'f4': 4.4}" 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['1'] = Test{true, 0, 'abc'}
e['2'] = Test{true, 1, 'def'} e['2'] = Test{true, 1, 'def'}
e['3'] = Test{false, 2, 'ghi'} e['3'] = Test{false, 2, 'ghi'}
@ -37,6 +42,8 @@ fn test_interpolation_map_to_string() {
assert s.contains("}, '2': Test{") assert s.contains("}, '2': Test{")
assert s.contains("y: 'def'") assert s.contains("y: 'def'")
f := {'hello': [1,2,3]!} f := map{
'hello': [1, 2, 3]!
}
assert '$f' == "{'hello': [1, 2, 3]}" assert '$f' == "{'hello': [1, 2, 3]}"
} }

View File

@ -1,6 +1,8 @@
type Test = map[string]string type Test = map[string]string
fn test_index() { fn test_index() {
t := Test({'c': 'abc'}) t := Test(map{
'c': 'abc'
})
assert t['c'] == 'abc' assert t['c'] == 'abc'
} }

View File

@ -1,6 +1,10 @@
fn test_string_int() { fn test_string_int() {
mut m := {'hi':4} mut m := map{
m2:= {'hi':5} 'hi': 4
}
m2 := map{
'hi': 5
}
assert m != m2 assert m != m2
m['hi']++ m['hi']++
assert m == m2 assert m == m2

View File

@ -1,7 +1,8 @@
type SumType = int | string 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, // tests whether an ordinary branch supports multiple statements,
@ -13,7 +14,8 @@ fn test_match_expression_on_sumtype_ordinary_branch(){
c = 1 c = 1
eprintln('hi') eprintln('hi')
'a string' 'a string'
}else{ }
else {
'unknown' 'unknown'
} }
} }
@ -21,7 +23,6 @@ fn test_match_expression_on_sumtype_ordinary_branch(){
assert c == 1 assert c == 1
} }
fn test_match_expression_on_sumtype_else() { fn test_match_expression_on_sumtype_else() {
// tests whether else branches support multiple statements, // tests whether else branches support multiple statements,
// when the other branches are simple default expressions // when the other branches are simple default expressions
@ -30,7 +31,8 @@ fn test_match_expression_on_sumtype_else(){
res := match s { res := match s {
string { string {
'a string' 'a string'
}else{ }
else {
c = 3 c = 3
eprintln('hi') eprintln('hi')
'unknown' 'unknown'

View File

@ -1,7 +1,11 @@
fn test_match_in_map_init() { fn test_match_in_map_init() {
ret := foo() ret := foo()
println(ret) 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 { fn foo() map[string]string {

View File

@ -1,9 +1,19 @@
interface Animal { name string } interface Animal {
struct Dog { name string } name string
struct Cat { name string } }
struct Dog {
name string
}
struct Cat {
name string
}
fn test_interface_match() { fn test_interface_match() {
a := Animal(Dog{name: 'Jet'}) a := Animal(Dog{
name: 'Jet'
})
match a { match a {
Dog { assert true } Dog { assert true }
Cat { assert false } Cat { assert false }

View File

@ -2,6 +2,7 @@ type Node = Expr | string
type Expr = IfExpr | IntegerLiteral type Expr = IfExpr | IntegerLiteral
struct IntegerLiteral {} struct IntegerLiteral {}
struct IfExpr { struct IfExpr {
pos int pos int
} }
@ -11,7 +12,9 @@ struct NodeWrapper {
} }
fn test_nested_sumtype_match_selector() { fn test_nested_sumtype_match_selector() {
c := NodeWrapper{Node(Expr(IfExpr{pos: 1}))} c := NodeWrapper{Node(Expr(IfExpr{
pos: 1
}))}
match c.node { match c.node {
Expr { Expr {
match c.node { match c.node {
@ -30,7 +33,9 @@ fn test_nested_sumtype_match_selector() {
} }
fn test_nested_sumtype_match() { fn test_nested_sumtype_match() {
c := Node(Expr(IfExpr{pos: 1})) c := Node(Expr(IfExpr{
pos: 1
}))
match c { match c {
Expr { Expr {
match c { match c {
@ -58,7 +63,7 @@ mut:
name string name string
} }
type Food = Milk | Eggs type Food = Eggs | Milk
struct FoodWrapper { struct FoodWrapper {
mut: mut:

View File

@ -1,11 +1,20 @@
struct Cat{name string} struct Cat {
struct Dog{name string} name string
}
struct Dog {
name string
}
type Animal = Cat | Dog type Animal = Cat | Dog
const ( const (
cat = Cat{name: 'cat'} cat = Cat{
dog = Dog{name: 'dog'} name: 'cat'
}
dog = Dog{
name: 'dog'
}
) )
fn test_shadow() { fn test_shadow() {

View File

@ -5,10 +5,24 @@ mut:
// this must return a reference, or else you'll get a C error // this must return a reference, or else you'll get a C error
// TODO: add a proper checker check for that case // TODO: add a proper checker check for that case
fn new(x int) &Test { return &Test{ x } } fn new(x int) &Test {
fn (mut t Test) inc() &Test { t.val++ return t } return &Test{x}
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 (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() { fn test_method_call_chains() {
mut x := new(4).inc().inc().inc().inc().add(4).div(2).inc() mut x := new(4).inc().inc().inc().inc().add(4).div(2).inc()

View File

@ -7,7 +7,7 @@ interface Animal {
} }
fn (a Animal) info() string { 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 { fn new_animal(breed string) Animal {

View File

@ -3,7 +3,7 @@ import crypto.sha256
import term { white } import term { white }
import crypto.md5 { sum } import crypto.md5 { sum }
import log as l import log as l
import time as t { now, utc, Time } import time as t { Time, utc }
import math import math
import crypto.sha512 import crypto.sha512
import cli { Command } import cli { Command }

View File

@ -1,5 +1,3 @@
/* /*
module acommentedmodule module acommentedmodule
*/ */

View File

@ -29,7 +29,7 @@ pub fn (a Point) +(b Point) Point {
} }
pub fn (a Point) str() string { pub fn (a Point) str() string {
return '${a.x} ${a.y}' return '$a.x $a.y'
} }
pub fn point_str(a Point) string { pub fn point_str(a Point) string {

View File

@ -3,14 +3,23 @@ module main
import geometry { Point } import geometry { Point }
fn test_operator_overloading() { fn test_operator_overloading() {
one := Point {x:1, y:2} one := Point{
two := Point {x:5, y:1} x: 1
y: 2
}
two := Point{
x: 5
y: 1
}
sum := one + two sum := one + two
assert sum.x == 6 assert sum.x == 6
assert sum.y == 3 assert sum.y == 3
} }
fn test_str_method() { fn test_str_method() {
one := Point {x:1, y:2} one := Point{
x: 1
y: 2
}
assert '$one' == '1 2' assert '$one' == '1 2'
} }

View File

@ -1,4 +1,5 @@
module xxx module xxx
pub fn f() string { pub fn f() string {
return 'x' return 'x'
} }

View File

@ -1,4 +1,5 @@
module yyy module yyy
pub fn f() string { pub fn f() string {
return 'y' return 'y'
} }

View File

@ -1,4 +1,5 @@
module zzz module zzz
pub fn f() string { pub fn f() string {
return 'z' return 'z'
} }

View File

@ -69,7 +69,9 @@ mut:
} }
fn f(mut x St) { fn f(mut x St) {
mut y := St{n: 2} mut y := St{
n: 2
}
a := x a := x
b := y b := y
x.n = 3 x.n = 3
@ -79,7 +81,9 @@ fn f(mut x St) {
} }
fn test_mut_4() { fn test_mut_4() {
mut x := St{ n: 1 } mut x := St{
n: 1
}
f(mut x) f(mut x)
} }
@ -98,7 +102,7 @@ fn test_mut_5() {
vv = ii vv = ii
aa := vv aa := vv
println('$ii $vv $aa') println('$ii $vv $aa')
results << "$ii $vv $aa" results << '$ii $vv $aa'
} }
} }
@ -169,7 +173,10 @@ fn test_mut_9() {
v = v + 1 // v: 1 v = v + 1 // v: 1
mut vv := v // vv: 1, v: 1 mut vv := v // vv: 1, v: 1
vv = vv + v // vv: 2, 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(v)
println(vv) println(vv)
println(foo) println(foo)
@ -270,7 +277,9 @@ fn foo4(mut f Foo) {
} }
fn test_mut_13() { fn test_mut_13() {
mut f := Foo{foo: 1} mut f := Foo{
foo: 1
}
foo4(mut f) foo4(mut f)
} }
@ -318,20 +327,31 @@ fn foo7(mut m map[string]int) {
} }
fn test_mut_16() { fn test_mut_16() {
mut m := map{'one': 100, 'two': 2} mut m := map{
'one': 100
'two': 2
}
foo7(mut m) foo7(mut m)
} }
fn test_mut_17() { fn test_mut_17() {
mut arr := [map{'foo':1}] mut arr := [map{
'foo': 1
}]
for _, mut j in arr { for _, mut j in arr {
mut k := j.clone() mut k := j.clone()
j['foo'] = 0 j['foo'] = 0
unsafe {k['foo'] = 10} unsafe {
k['foo'] = 10
}
println(j) println(j)
println(k) println(k)
assert j == {'foo': 0} assert j == map{
assert k == {'foo': 10} 'foo': 0
}
assert k == map{
'foo': 10
}
} }
} }

View File

@ -62,8 +62,6 @@ fn test_nested_propagation_method() {
mut x := St{ mut x := St{
z: 2.25 z: 2.25
} }
x.aa_propagate() or { x.aa_propagate() or { x.z = 13.0625 }
x.z = 13.0625
}
assert x.z == 13.0625 assert x.z == 13.0625
} }

View File

@ -9,7 +9,11 @@ struct Cat {
type Feline = Cat type Feline = Cat
fn test_offsetof() { fn test_offsetof() {
cat := Cat{name: 'Cthulhu' breed: 'Great Old One' age: 2147483647} cat := Cat{
name: 'Cthulhu'
breed: 'Great Old One'
age: 2147483647
}
unsafe { unsafe {
assert *(&string(byteptr(&cat) + __offsetof(Cat, name))) == 'Cthulhu' assert *(&string(byteptr(&cat) + __offsetof(Cat, name))) == 'Cthulhu'
assert *(&string(byteptr(&cat) + __offsetof(Cat, breed))) == 'Great Old One' 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() { 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 { unsafe {
assert *(&string(byteptr(&fel) + __offsetof(Feline, name))) == 'Cthulhu' assert *(&string(byteptr(&fel) + __offsetof(Feline, name))) == 'Cthulhu'
assert *(&string(byteptr(&fel) + __offsetof(Feline, breed))) == 'Great Old One' assert *(&string(byteptr(&fel) + __offsetof(Feline, breed))) == 'Great Old One'

View File

@ -11,8 +11,12 @@ fn (a Foo) == (b Foo) bool {
} }
fn test_operator_overloading_cmp() { fn test_operator_overloading_cmp() {
a := Foo{i: 38} a := Foo{
b := Foo{i: 38} i: 38
}
b := Foo{
i: 38
}
mut arr := [a, b] mut arr := [a, b]
assert (a > b) == false assert (a > b) == false

View File

@ -41,9 +41,9 @@ fn test_channel_push() {
fn test_thread_wait() { fn test_thread_wait() {
thrs := [ thrs := [
go f(3) go f(3),
go f(-7) go f(-7),
go f(12) go f(12),
] ]
mut res := []int{cap: 3} mut res := []int{cap: 3}
for t in thrs { for t in thrs {
@ -56,4 +56,3 @@ fn test_nested_opt() {
a := f(f(f(-3) or { -7 }) or { 4 }) or { 17 } a := f(f(f(-3) or { -7 }) or { 4 }) or { 17 }
assert a == 4 assert a == 4
} }

View File

@ -36,13 +36,9 @@ fn return_a_string() string {
// //
fn test_optional_int() { fn test_optional_int() {
a := i_0(0) or { a := i_0(0) or { 4999 }
4999
}
assert a == 4999 assert a == 4999
b := i_0(4123) or { b := i_0(4123) or { 4999 }
4999
}
assert b == 4123 assert b == 4123
} }
@ -59,13 +55,9 @@ fn test_optional_bool() {
} }
*/ */
fn test_optional_struct() { fn test_optional_struct() {
sa := struct_0(0) or { sa := struct_0(0) or { Abc{7999} }
Abc{7999}
}
assert sa.x == 7999 assert sa.x == 7999
sb := struct_0(3456) or { sb := struct_0(3456) or { Abc{7999} }
Abc{7999}
}
assert sb.x == 3456 assert sb.x == 3456
} }
@ -75,16 +67,12 @@ fn test_optional_with_statements_before_last_expression() {
Abc{12345} Abc{12345}
} }
assert s.x == 12345 assert s.x == 12345
b := b_0(true) or { b := b_0(true) or { false }
false
}
assert b == true assert b == true
} }
fn test_optional_with_fn_call_as_last_expression() { fn test_optional_with_fn_call_as_last_expression() {
s := string_0(0) or { s := string_0(0) or { return_a_string() }
return_a_string()
}
assert s == 'abcdef' assert s == 'abcdef'
} }
@ -99,46 +87,28 @@ fn test_optional_with_fn_call_last_expr_and_preceding_statements() {
fn test_nested_optional() { fn test_nested_optional() {
a := i_0(1) or { a := i_0(1) or {
b := i_0(0) or { b := i_0(0) or { 3 }
3
}
b b
} }
assert a == 1 assert a == 1
b := i_0(0) or { b := i_0(0) or {
c := i_0(1) or { c := i_0(1) or { 3 }
3
}
c c
} }
assert b == 1 assert b == 1
c := i_0(0) or { c := i_0(0) or {
d := i_0(0) or { d := i_0(0) or { 3 }
3
}
d d
} }
assert c == 3 assert c == 3
} }
fn test_nested_optional_with_opt_fn_call_as_last_value() { fn test_nested_optional_with_opt_fn_call_as_last_value() {
a := i_0(1) or { a := i_0(1) or { i_0(0) or { 3 } }
i_0(0) or {
3
}
}
assert a == 1 assert a == 1
b := i_0(0) or { b := i_0(0) or { i_0(1) or { 3 } }
i_0(1) or {
3
}
}
assert b == 1 assert b == 1
c := i_0(0) or { c := i_0(0) or { i_0(0) or { 3 } }
i_0(0) or {
3
}
}
assert c == 3 assert c == 3
// TODO Enable once optional in boolean expressions are working // TODO Enable once optional in boolean expressions are working
// d := b_0(true) or { // d := b_0(true) or {

View File

@ -1,4 +1,3 @@
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() assert 'Option{ error: "an error" }' == error('an error').str()
} }

View File

@ -1,6 +1,6 @@
module main module main
import mod1 import v.tests.project_with_c_code.mod1
fn main() { fn main() {
res := mod1.vadd(1, 2) res := mod1.vadd(1, 2)

View File

@ -1,4 +1,4 @@
import mod1 import v.tests.project_with_c_code.mod1
fn test_using_c_code_in_the_same_module_works() { fn test_using_c_code_in_the_same_module_works() {
assert 1003 == mod1.vadd(1, 2) assert 1003 == mod1.vadd(1, 2)

View File

@ -1,6 +1,6 @@
module main module main
import modc import v.tests.project_with_c_code_2.modc
// passing array of Vtype to C // passing array of Vtype to C
// Vtype wraps a C type // Vtype wraps a C type

View File

@ -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() { fn test_using_c_code_in_the_same_module_works() {
x := modc.new_vtype(123) x := modc.new_vtype(123)

View File

@ -3,6 +3,7 @@ module modc
#flag -I @VROOT #flag -I @VROOT
#flag @VROOT/impl.o #flag @VROOT/impl.o
#include "header.h" #include "header.h"
struct C.Atype { struct C.Atype {
} }

View File

@ -1,4 +1,4 @@
import mod1.submodule as m import v.tests.project_with_modules_having_submodules.mod1.submodule as m
fn test_mod1_can_still_be_found_through_parent_project_vmod() { fn test_mod1_can_still_be_found_through_parent_project_vmod() {
assert 1051 == m.f() assert 1051 == m.f()

View File

@ -1,11 +1,11 @@
#!/usr/local/bin/v run #!/usr/local/bin/v run
import mod1.submodule as m
import v.tests.project_with_modules_having_submodules.mod1.submodule as m
println('This script is located inside: ' + resource_abs_path('')) println('This script is located inside: ' + resource_abs_path(''))
println('The result of calling m.f is: ' + m.f().str()) println('The result of calling m.f is: ' + m.f().str())
/* /*
NB: this main program v script is under bin/ , NB: this main program v script is under bin/ ,
but it *still* can find mod1, because the parent project has v.mod, but it *still* can find mod1, because the parent project has v.mod,

View File

@ -5,11 +5,10 @@ This submodule just imports its sibling submodules.
Note that they are NOT under 'submodule' itself, Note that they are NOT under 'submodule' itself,
but are in its parent mod1 , and mod1 has a 'v.mod' file. but are in its parent mod1 , and mod1 has a 'v.mod' file.
*/ */
import v.tests.project_with_modules_having_submodules.mod1.mod11
import mod11 import v.tests.project_with_modules_having_submodules.mod1.mod12
import mod12 import v.tests.project_with_modules_having_submodules.mod1.mod13
import mod13 import v.tests.project_with_modules_having_submodules.mod1.mod14
import mod14
pub fn f() int { pub fn f() int {
return 1000 + mod11.f() + mod12.f() + mod13.f() + mod14.f() return 1000 + mod11.f() + mod12.f() + mod13.f() + mod14.f()

View File

@ -1,5 +1,5 @@
import mod1 import v.tests.project_with_modules_having_submodules.mod1
import mod1.submodule import v.tests.project_with_modules_having_submodules.mod1.submodule
fn test_mod1() { fn test_mod1() {
assert 1 == mod1.f() assert 1 == mod1.f()

View File

@ -21,27 +21,35 @@ mut:
} }
fn test_ref() { fn test_ref() {
a := &Abc{ n: 3 } a := &Abc{
n: 3
}
assert a.n == 3 assert a.n == 3
} }
fn test_shared() { fn test_shared() {
shared a := Abc{ n: 4 } shared a := Abc{
res := rlock a { a.n } n: 4
}
res := rlock a {
a.n
}
assert res == 4 assert res == 4
} }
fn test_embed_in_ref_struct() { fn test_embed_in_ref_struct() {
a := &St{ a := &St{Abc{
Abc{ n: 5 } n: 5
} }}
assert a.n == 5 assert a.n == 5
} }
fn test_field_in_ref_struct() { fn test_field_in_ref_struct() {
x := &Qwe{ x := &Qwe{
f: 12.25 f: 12.25
a: Abc{ n: 23 } a: Abc{
n: 23
}
} }
assert x.a.n == 23 assert x.a.n == 23
} }
@ -49,7 +57,9 @@ fn test_field_in_ref_struct() {
fn test_ref_field() { fn test_ref_field() {
y := Rtz{ y := Rtz{
f: -6.25 f: -6.25
a: &Abc{ n: 29 } a: &Abc{
n: 29
}
} }
assert y.a.n == 29 assert y.a.n == 29
} }

View File

@ -42,9 +42,7 @@ fn test_all_v_repl_files() {
panic(err) panic(err)
} }
session.bmark.set_total_expected_steps(session.options.files.len) session.bmark.set_total_expected_steps(session.options.files.len)
mut pool_repl := pool.new_pool_processor( mut pool_repl := pool.new_pool_processor(callback: worker_repl)
callback: worker_repl
)
pool_repl.set_shared_context(session) pool_repl.set_shared_context(session)
$if windows { $if windows {
// See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019 // See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019

View File

@ -35,10 +35,18 @@ fn a_val(a []int) int {
} }
fn test_shared_as_value() { fn test_shared_as_value() {
shared s := St{ a: 5 } shared s := St{
a: 5
}
shared a := [3, 4, 6, 13, -23] shared a := [3, 4, 6, 13, -23]
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} shared m := map{
shared r := Qr{ a: 7 } 'qw': 12.75
'yxcv': -3.125
'poiu': 88.0625
}
shared r := Qr{
a: 7
}
rlock s, r { rlock s, r {
u := r.s_val(s) u := r.s_val(s)
assert u == 35 assert u == 35
@ -58,10 +66,18 @@ fn test_shared_as_value() {
} }
fn test_shared_as_mut() { fn test_shared_as_mut() {
shared s := St{ a: 5 } shared s := St{
a: 5
}
shared a := [3, 4, 6, 13, -23] shared a := [3, 4, 6, 13, -23]
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625} shared m := map{
shared r := Qr{ a: 7 } 'qw': 12.75
'yxcv': -3.125
'poiu': 88.0625
}
shared r := Qr{
a: 7
}
lock s, r { lock s, r {
r.s_mut(mut s) r.s_mut(mut s)
x := r.a * s.a x := r.a * s.a

View File

@ -23,7 +23,12 @@ fn inc_map_elem(shared b map[string]int, k string) {
} }
fn test_autolock_map() { fn test_autolock_map() {
shared m := &{'xy': 1, 'qwe': 2, 'asd': 7, 'iop': 5} shared m := &map{
'xy': 1
'qwe': 2
'asd': 7
'iop': 5
}
t := go inc_map_elem(shared m, 'asd') t := go inc_map_elem(shared m, 'asd')
for _ in 0 .. iterations { for _ in 0 .. iterations {
m['asd']++ m['asd']++
@ -31,4 +36,3 @@ fn test_autolock_map() {
t.wait() t.wait()
assert m['asd'] == 2 * iterations + 7 assert m['asd'] == 2 * iterations + 7
} }

View File

@ -9,24 +9,36 @@ struct Abc {
} }
fn test_shared_struct_in_struct() { fn test_shared_struct_in_struct() {
shared y := Xyz{ n: 7 } shared y := Xyz{
n: 7
}
z := Abc{ z := Abc{
a: y a: y
} }
u := Xyz{ n: 17 } u := Xyz{
n: 17
}
x := Abc{ x := Abc{
a: u a: u
} }
v := Abc{ v := Abc{
a: Xyz{ n: 5 } a: Xyz{
n: 5
}
i: 3 i: 3
} }
shared f := x.a shared f := x.a
shared g := v.a shared g := v.a
shared h := z.a shared h := z.a
a := rlock f { f.n } a := rlock f {
b := rlock g { g.n } f.n
c := rlock h { h.n } }
b := rlock g {
g.n
}
c := rlock h {
h.n
}
assert a == 17 assert a == 17
assert b == 5 assert b == 5
assert c == 7 assert c == 7
@ -48,8 +60,12 @@ fn test_shared_array_in_struct() {
t[2] = -1.125 t[2] = -1.125
} }
shared tt := x.a shared tt := x.a
v := rlock tt { tt[3] } v := rlock tt {
w := rlock tt { tt[2] } tt[3]
}
w := rlock tt {
tt[2]
}
assert v == 13.0625 assert v == 13.0625
assert w == -1.125 assert w == -1.125
assert x.i == 12 assert x.i == 12
@ -62,7 +78,11 @@ struct Hjk {
fn test_shared_map_in_struct() { fn test_shared_map_in_struct() {
x := Hjk{ x := Hjk{
m: {'st': -6.0625, 'xy': 12.125, 'rz': 2.25} m: map{
'st': -6.0625
'xy': 12.125
'rz': 2.25
}
i: 23 i: 23
} }
shared k := x.m shared k := x.m
@ -70,8 +90,12 @@ fn test_shared_map_in_struct() {
k['yxc'] = -23.5 k['yxc'] = -23.5
} }
shared p := x.m shared p := x.m
a := rlock p { p['xy'] } a := rlock p {
b := rlock p { p['yxc'] } p['xy']
}
b := rlock p {
p['yxc']
}
assert a == 12.125 assert a == 12.125
assert b == -23.5 assert b == -23.5
assert x.i == 23 assert x.i == 23
@ -79,11 +103,17 @@ fn test_shared_map_in_struct() {
fn test_array_of_shared() { fn test_array_of_shared() {
mut a := []shared Xyz{cap: 3} mut a := []shared Xyz{cap: 3}
a0 := Xyz{ n: 3 } a0 := Xyz{
n: 3
}
a << a0 a << a0
a1 := Xyz{ n: 7 } a1 := Xyz{
n: 7
}
a << a1 a << a1
a2 := Xyz{ n: 13 } a2 := Xyz{
n: 13
}
a << a2 a << a2
shared p := a[0] shared p := a[0]
shared q := a[2] shared q := a[2]
@ -91,8 +121,12 @@ fn test_array_of_shared() {
q.n = -17 q.n = -17
} }
shared r := a[2] shared r := a[2]
e := rlock p { p.n } e := rlock p {
f := rlock r { r.n } p.n
}
f := rlock r {
r.n
}
assert e == 3 assert e == 3
assert f == -17 assert f == -17
} }

View File

@ -4,7 +4,9 @@ mut:
} }
fn f() St { fn f() St {
x := St{ x: 3.25 } x := St{
x: 3.25
}
return x return x
} }
@ -12,19 +14,25 @@ fn g(good bool) ?St {
if !good { if !good {
return error('no St created') return error('no St created')
} }
x := St{ x: 12.75 } x := St{
x: 12.75
}
return x return x
} }
fn test_shared_fn_return() { fn test_shared_fn_return() {
shared x := f() shared x := f()
val := rlock x { x.x } val := rlock x {
x.x
}
assert val == 3.25 assert val == 3.25
} }
fn shared_opt_propagate(good bool) ?f64 { fn shared_opt_propagate(good bool) ?f64 {
shared x := g(good) ? shared x := g(good) ?
ret := rlock x { x.x } ret := rlock x {
x.x
}
return ret return ret
} }
@ -36,13 +44,25 @@ fn test_shared_opt_propagate() {
} }
fn test_shared_opt_good() { fn test_shared_opt_good() {
shared yy := g(true) or { St{ x: 37.5 } } shared yy := g(true) or {
val := rlock yy { yy.x } St{
x: 37.5
}
}
val := rlock yy {
yy.x
}
assert val == 12.75 assert val == 12.75
} }
fn test_shared_opt_bad() { fn test_shared_opt_bad() {
shared yy := g(false) or { St{ x: 37.5 } } shared yy := g(false) or {
val := rlock yy { yy.x } St{
x: 37.5
}
}
val := rlock yy {
yy.x
}
assert val == 37.5 assert val == 37.5
} }

View File

@ -16,7 +16,7 @@ fn (shared x St) f(shared y St, shared z St) {
fn (shared x St) g(shared y St, shared z St) { fn (shared x St) g(shared y St, shared z St) {
for _ in 0 .. 10000 { for _ in 0 .. 10000 {
rlock x; lock y, z { lock y, z; rlock x {
y.a += x.a y.a += x.a
if y.a > 1000000 { if y.a > 1000000 {
y.a /= 2 y.a /= 2

View File

@ -4,11 +4,19 @@ mut:
} }
fn test_lock_expr() { fn test_lock_expr() {
shared xx := St{ i: 173 } shared xx := St{
shared y := St{ i: -57 } i: 173
}
shared y := St{
i: -57
}
mut m := 0 mut m := 0
m = lock y { y.i } m = lock y {
n := rlock xx { xx.i } y.i
}
n := rlock xx {
xx.i
}
assert m == -57 assert m == -57
assert n == 173 assert n == 173
} }
@ -19,10 +27,18 @@ mut:
} }
fn test_multi_objects() { fn test_multi_objects() {
shared x := Abc{ a: 12.5 } shared x := Abc{
shared y := Abc{ a: -7.5 } a: 12.5
shared z := Abc{ a: 13.125 } }
a, b, c := rlock z, x, y { y.a, z.a, x.a } shared y := Abc{
a: -7.5
}
shared z := Abc{
a: 13.125
}
a, b, c := rlock z, x, y {
y.a, z.a, x.a
}
assert a == -7.5 assert a == -7.5
assert b == 13.125 assert b == 13.125
assert c == 12.5 assert c == 12.5
@ -33,10 +49,18 @@ fn (mut st Abc) getvals(mut a Abc, mut b Abc) (f64, f64, f64) {
} }
fn test_mult_ret_method() { fn test_mult_ret_method() {
shared x := Abc{ a: 12.5 } shared x := Abc{
shared y := Abc{ a: -7.5 } a: 12.5
shared z := Abc{ a: 13.125 } }
a, b, c := lock z, x, y { z.getvals(mut x, mut y) } shared y := Abc{
a: -7.5
}
shared z := Abc{
a: 13.125
}
a, b, c := lock z, x, y {
z.getvals(mut x, mut y)
}
assert a == 12.5 assert a == 12.5
assert b == 13.125 assert b == 13.125
assert c == -7.5 assert c == -7.5

View File

@ -10,7 +10,10 @@ fn incr(shared foo map[string]int, key string, mut sem sync.Semaphore) {
} }
fn test_shared_array() { fn test_shared_array() {
shared foo := {'p': 10, 'q': 0} shared foo := map{
'p': 10
'q': 0
}
lock foo { lock foo {
foo['q'] = 20 foo['q'] = 20
} }
@ -37,8 +40,16 @@ fn test_shared_array() {
} }
fn test_shared_init_syntax() { fn test_shared_init_syntax() {
shared foo := &{'p': 17, 'q': -3, 'qwertz': 10} shared foo := &map{
shared bar := {'wer': 13.75, 'cvbn': -7.25, 'asd': -0.0625} 'p': 17
'q': -3
'qwertz': 10
}
shared bar := map{
'wer': 13.75
'cvbn': -7.25
'asd': -0.0625
}
shared baz := &map[string]int{} shared baz := &map[string]int{}
shared qux := map[string]f64{} shared qux := map[string]f64{}
shared quux := new_map() shared quux := new_map()
@ -64,6 +75,10 @@ fn test_shared_init_syntax() {
} }
fn new_map() map[string]f64 { fn new_map() map[string]f64 {
m := { 'qwe': 34.25, 'yxc': 9.125, 'tzu': -7.5 } m := map{
'qwe': 34.25
'yxc': 9.125
'tzu': -7.5
}
return m return m
} }

View File

@ -7,7 +7,11 @@ mut:
} }
fn (a Large) clone() Large { fn (a Large) clone() Large {
r := Large{ l: a.l, m: a.m h: a.h } r := Large{
l: a.l
m: a.m
h: a.h
}
return r return r
} }
@ -15,9 +19,13 @@ fn (mut a Large) add(b Large) {
oldl := a.l oldl := a.l
a.l += b.l a.l += b.l
oldm := a.m oldm := a.m
if a.l < oldl { a.m++ } if a.l < oldl {
a.m++
}
a.m += b.m a.m += b.m
if a.m < oldm || (a.l < oldl && a.m <= oldm) { a.h++ } if a.m < oldm || (a.l < oldl && a.m <= oldm) {
a.h++
}
a.h += b.h a.h += b.h
} }
@ -37,11 +45,27 @@ fn doub_large(shared a Large, shared b Large, shared c Large, shared d Large, sh
fn test_mixed_order_lock_rlock() { fn test_mixed_order_lock_rlock() {
// initialze objects so that their sum = 1 // initialze objects so that their sum = 1
shared a := Large{ l: 4 } shared a := Large{
shared b := Large{ l: u64(-7), m: u64(-1) h: u64(-1) } l: 4
shared c := Large{ l: 17 } }
shared d := Large{ l: u64(-11), m: u64(-1) h: u64(-1) } shared b := Large{
shared e := Large{ l: u64(-2), m: u64(-1) h: u64(-1) } l: u64(-7)
m: u64(-1)
h: u64(-1)
}
shared c := Large{
l: 17
}
shared d := Large{
l: u64(-11)
m: u64(-1)
h: u64(-1)
}
shared e := Large{
l: u64(-2)
m: u64(-1)
h: u64(-1)
}
// spawn 3 threads for doubling with different orders of objects // spawn 3 threads for doubling with different orders of objects
t1 := go doub_large(shared a, shared b, shared c, shared d, shared e) t1 := go doub_large(shared a, shared b, shared c, shared d, shared e)
t2 := go doub_large(shared e, shared b, shared a, shared c, shared d) t2 := go doub_large(shared e, shared b, shared a, shared c, shared d)
@ -63,4 +87,3 @@ fn test_mixed_order_lock_rlock() {
assert sum.m == 0 assert sum.m == 0
assert sum.h == 4194304 assert sum.h == 4194304
} }

View File

@ -10,9 +10,7 @@ fn t(options TOptions) bool {
} }
fn test_short_struct_as_parameter() { fn test_short_struct_as_parameter() {
if t({ if t(a: 1) {
a: 1
}) {
assert true assert true
return return
} }

View File

@ -4,6 +4,7 @@ import flag
struct S1 { struct S1 {
p voidptr p voidptr
} }
struct S2 { struct S2 {
i int i int
} }

View File

@ -6,11 +6,21 @@ mut:
fn test_array_sort_by_references() { fn test_array_sort_by_references() {
mut a := []&Container{} mut a := []&Container{}
a << &Container{ name: 'a' } a << &Container{
a << &Container{ name: 'b' } name: 'a'
a << &Container{ name: 'c' } }
a << &Container{ name: 'd' } a << &Container{
a << &Container{ name: 'e' } name: 'b'
}
a << &Container{
name: 'c'
}
a << &Container{
name: 'd'
}
a << &Container{
name: 'e'
}
a.sort(a.name > b.name) a.sort(a.name > b.name)
println(a) println(a)

View File

@ -55,31 +55,51 @@ fn test_array_of_strings() {
} }
fn test_map_of_ints() { fn test_map_of_ints() {
aa := {'a': 1, 'b': 2, 'c': 3} aa := map{
'a': 1
'b': 2
'c': 3
}
assert aa.str() == "{'a': 1, 'b': 2, 'c': 3}" assert aa.str() == "{'a': 1, 'b': 2, 'c': 3}"
assert '$aa' == "{'a': 1, 'b': 2, 'c': 3}" assert '$aa' == "{'a': 1, 'b': 2, 'c': 3}"
} }
fn test_map_of_strings() { fn test_map_of_strings() {
aa := {'a': '1', 'b': '2', 'c': '3'} aa := map{
'a': '1'
'b': '2'
'c': '3'
}
assert aa.str() == "{'a': '1', 'b': '2', 'c': '3'}" assert aa.str() == "{'a': '1', 'b': '2', 'c': '3'}"
assert '$aa' == "{'a': '1', 'b': '2', 'c': '3'}" assert '$aa' == "{'a': '1', 'b': '2', 'c': '3'}"
} }
fn test_map_of_floats() { fn test_map_of_floats() {
aa := {'a': 1.1, 'b': 2.2, 'c': 3.3} aa := map{
'a': 1.1
'b': 2.2
'c': 3.3
}
assert aa.str() == "{'a': 1.1, 'b': 2.2, 'c': 3.3}" assert aa.str() == "{'a': 1.1, 'b': 2.2, 'c': 3.3}"
assert '$aa' == "{'a': 1.1, 'b': 2.2, 'c': 3.3}" assert '$aa' == "{'a': 1.1, 'b': 2.2, 'c': 3.3}"
} }
fn test_map_of_runes() { fn test_map_of_runes() {
aa := {'a': `a`, 'b': `b`, 'c': `c`} aa := map{
'a': `a`
'b': `b`
'c': `c`
}
assert aa.str() == "{'a': `a`, 'b': `b`, 'c': `c`}" assert aa.str() == "{'a': `a`, 'b': `b`, 'c': `c`}"
assert '$aa' == "{'a': `a`, 'b': `b`, 'c': `c`}" assert '$aa' == "{'a': `a`, 'b': `b`, 'c': `c`}"
} }
fn test_map_of_bools() { fn test_map_of_bools() {
aa := {'a': true, 'b': false, 'c': true} aa := map{
'a': true
'b': false
'c': true
}
assert aa.str() == "{'a': true, 'b': false, 'c': true}" assert aa.str() == "{'a': true, 'b': false, 'c': true}"
assert '$aa' == "{'a': true, 'b': false, 'c': true}" assert '$aa' == "{'a': true, 'b': false, 'c': true}"
} }
@ -143,16 +163,18 @@ fn test_fixed_array_of_strings() {
struct Wrapper { struct Wrapper {
foo &string foo &string
} }
fn test_struct_with_string_pointer() { fn test_struct_with_string_pointer() {
s := 'test' s := 'test'
w := Wrapper{&s} w := Wrapper{&s}
assert '$w' == 'Wrapper{\n foo: &\'test\'\n}' assert '$w' == "Wrapper{\n foo: &'test'\n}"
assert w.str() == 'Wrapper{\n foo: &\'test\'\n}' assert w.str() == "Wrapper{\n foo: &'test'\n}"
} }
struct Wrapper2 { struct Wrapper2 {
foo &int foo &int
} }
fn test_struct_with_int_pointer() { fn test_struct_with_int_pointer() {
i := 5 i := 5
w := Wrapper2{&i} w := Wrapper2{&i}
@ -163,6 +185,7 @@ fn test_struct_with_int_pointer() {
struct Wrapper3 { struct Wrapper3 {
foo &bool foo &bool
} }
fn test_struct_with_bool_pointer() { fn test_struct_with_bool_pointer() {
b := true b := true
w := Wrapper3{&b} w := Wrapper3{&b}
@ -171,9 +194,11 @@ fn test_struct_with_bool_pointer() {
} }
struct Foo {} struct Foo {}
struct Wrapper4 { struct Wrapper4 {
foo &Foo foo &Foo
} }
fn test_struct_with_struct_pointer() { fn test_struct_with_struct_pointer() {
b := Foo{} b := Foo{}
w := Wrapper4{&b} w := Wrapper4{&b}
@ -190,6 +215,7 @@ fn test_struct_with_nil() {
struct Wrapper5 { struct Wrapper5 {
foo &f32 foo &f32
} }
fn test_struct_with_f32_pointer() { fn test_struct_with_f32_pointer() {
i := f32(5.1) i := f32(5.1)
w := Wrapper5{&i} w := Wrapper5{&i}
@ -197,13 +223,14 @@ fn test_struct_with_f32_pointer() {
assert w.str() == 'Wrapper5{\n foo: &5.1\n}' assert w.str() == 'Wrapper5{\n foo: &5.1\n}'
} }
struct TestStruct { struct TestStruct {
x int x int
} }
struct ArrayWithStruct { struct ArrayWithStruct {
foo []TestStruct foo []TestStruct
} }
fn test_array_with_struct() { fn test_array_with_struct() {
a := ArrayWithStruct{[TestStruct{}]} a := ArrayWithStruct{[TestStruct{}]}
assert a.str() == 'ArrayWithStruct{\n foo: [TestStruct{\n x: 0\n }]\n}' assert a.str() == 'ArrayWithStruct{\n foo: [TestStruct{\n x: 0\n }]\n}'
@ -213,13 +240,17 @@ fn test_array_with_struct() {
struct MapWithStruct { struct MapWithStruct {
foo map[string]TestStruct foo map[string]TestStruct
} }
fn test_map_with_struct() { fn test_map_with_struct() {
a := MapWithStruct{{'test': TestStruct{}}} a := MapWithStruct{map{
assert a.str() == 'MapWithStruct{\n foo: {\'test\': TestStruct{\n x: 0\n }}\n}' 'test': TestStruct{}
assert '$a' == 'MapWithStruct{\n foo: {\'test\': TestStruct{\n x: 0\n }}\n}' }}
assert a.str() == "MapWithStruct{\n foo: {'test': TestStruct{\n x: 0\n }}\n}"
assert '$a' == "MapWithStruct{\n foo: {'test': TestStruct{\n x: 0\n }}\n}"
} }
struct ForGeneric {} struct ForGeneric {}
fn generic_fn_interpolation<T>(p T) string { fn generic_fn_interpolation<T>(p T) string {
return '$p' return '$p'
} }
@ -235,6 +266,7 @@ fn test_generic_auto_str() {
} }
type Alias1 = int type Alias1 = int
fn test_alias_in_array() { fn test_alias_in_array() {
t := [Alias1(1)] t := [Alias1(1)]
assert t.str() == '[1]' assert t.str() == '[1]'
@ -242,6 +274,7 @@ fn test_alias_in_array() {
} }
type Alias2 = int type Alias2 = int
fn test_alias_in_fixed_array() { fn test_alias_in_fixed_array() {
t := [Alias1(1)]! t := [Alias1(1)]!
assert t.str() == '[1]' assert t.str() == '[1]'
@ -255,6 +288,7 @@ fn test_alias_int() {
} }
type Alias3 = string type Alias3 = string
fn test_alias_string() { fn test_alias_string() {
s := 'test' s := 'test'
a := Alias3(s) a := Alias3(s)
@ -263,6 +297,7 @@ fn test_alias_string() {
} }
type TestAlias = TestStruct type TestAlias = TestStruct
fn test_alias_struct() { fn test_alias_struct() {
ts := TestStruct{} ts := TestStruct{}
t := TestAlias(ts) t := TestAlias(ts)
@ -296,7 +331,7 @@ fn create_option_err() ?string {
} }
fn test_option_err() { fn test_option_err() {
assert '$create_option_err()' == "Option(error: this is an error)" assert '$create_option_err()' == 'Option(error: this is an error)'
} }
fn create_option_none() ?string { fn create_option_none() ?string {
@ -312,7 +347,7 @@ fn create_option_string() ?string {
} }
fn test_option_string() { fn test_option_string() {
assert '$create_option_string()' == 'Option(\'this is a string\')' assert '$create_option_string()' == "Option('this is a string')"
} }
fn create_option_int() ?int { fn create_option_int() ?int {
@ -348,7 +383,8 @@ fn test_option_struct() {
// assert '$w' == 'OptionWrapper{\n x: Option(error: \'\')\n}' // assert '$w' == 'OptionWrapper{\n x: Option(error: \'\')\n}'
// } // }
/* TODO: doesn't work yet /*
TODO: doesn't work yet
struct OptionWrapperInt { struct OptionWrapperInt {
x ?int x ?int
} }
@ -360,11 +396,11 @@ fn test_struct_with_option() {
*/ */
struct One { struct One {
value string = "one" value string = 'one'
} }
struct Two { struct Two {
value string = "two" value string = 'two'
} }
fn mr_int_int() (int, int) { fn mr_int_int() (int, int) {

View File

@ -11,7 +11,10 @@ fn test_fixed_array_alias_string() {
} }
fn test_map_alias_string() { fn test_map_alias_string() {
m := {'one': Literal('1'), 'two': Literal('2')} m := map{
'one': Literal('1')
'two': Literal('2')
}
assert '$m'.contains("'one': '1'") assert '$m'.contains("'one': '1'")
assert '$m'.contains("'two': '2'") assert '$m'.contains("'two': '2'")
} }

View File

@ -79,24 +79,30 @@ fn test_array_of_strings_interpolation() {
fn test_array_of_map_interpolation() { fn test_array_of_map_interpolation() {
mut a := []map[string]int{} mut a := []map[string]int{}
a << {'a': int(1), 'b': 2} a << map{
a << {'c': int(3), 'd': 4} 'a': int(1)
'b': 2
}
a << map{
'c': int(3)
'd': 4
}
assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]" assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]"
} }
fn test_array_initialization_with_interpolation() { fn test_array_initialization_with_interpolation() {
sysroot := '/usr' sysroot := '/usr'
a := [ a := [
'abcd' 'abcd',
'$sysroot/xyz' '$sysroot/xyz',
'u$sysroot/vw' 'u$sysroot/vw',
'/rr$sysroot' '/rr$sysroot',
'lmno' 'lmno',
] ]
assert '$a' == "['abcd', '/usr/xyz', 'u/usr/vw', '/rr/usr', 'lmno']" assert '$a' == "['abcd', '/usr/xyz', 'u/usr/vw', '/rr/usr', 'lmno']"
b := [ b := [
'a${sysroot:5}/r' 'a${sysroot:5}/r',
'ert' 'ert',
] ]
assert '$b' == "['a /usr/r', 'ert']" assert '$b' == "['a /usr/r', 'ert']"
c := ['xy', 'r$sysroot', '$sysroot/t', '>$sysroot<'] c := ['xy', 'r$sysroot', '$sysroot/t', '>$sysroot<']

View File

@ -3,7 +3,7 @@ struct Foo {
} }
fn (f &Foo) str() string { fn (f &Foo) str() string {
return '${f.bar}' return '$f.bar'
} }
struct Bar { struct Bar {

View File

@ -3,7 +3,9 @@ fn show(a string) string {
} }
fn test_function_interpolation() { fn test_function_interpolation() {
f := fn()(string, bool) {return 'aaa', true} f := fn () (string, bool) {
return 'aaa', true
}
println(f) println(f)
assert '$f' == 'fn () (string, bool)' assert '$f' == 'fn () (string, bool)'
@ -18,7 +20,9 @@ struct Info {
fn test_function_interpolation_in_struct() { fn test_function_interpolation_in_struct() {
a := Info{ a := Info{
aa: fn()string {return 'aaa'} aa: fn () string {
return 'aaa'
}
bb: 22 bb: 22
} }
println(a) println(a)
@ -26,14 +30,24 @@ fn test_function_interpolation_in_struct() {
} }
fn test_function_interpolation_in_array() { fn test_function_interpolation_in_array() {
f := [fn()string{return 'aaa'}, fn()string{return 'bbb'}] f := [fn () string {
return 'aaa'
}, fn () string {
return 'bbb'
}]
println(f) println(f)
assert '$f' == '[fn () string, fn () string]' assert '$f' == '[fn () string, fn () string]'
} }
fn test_function_interpolation_in_map() { fn test_function_interpolation_in_map() {
m := {'aaa': fn()string{return 'aaa'}, 'bbb': fn()string{return 'bbb'}} m := map{
'aaa': fn () string {
return 'aaa'
}
'bbb': fn () string {
return 'bbb'
}
}
println(m) println(m)
assert '$m'.contains(': fn () string') assert '$m'.contains(': fn () string')
} }

Some files were not shown because too many files have changed in this diff Show More