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/',
|
||||
|
|
|
@ -6,5 +6,5 @@ fn test_anon_fn_call() {
|
|||
}
|
||||
|
||||
fn test() string {
|
||||
return "Test"
|
||||
return 'Test'
|
||||
}
|
||||
|
|
|
@ -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'
|
||||
}]
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ struct Tester {
|
|||
}
|
||||
|
||||
enum Color {
|
||||
red green blue
|
||||
red
|
||||
green
|
||||
blue
|
||||
}
|
||||
|
||||
fn test_array_equality() {
|
||||
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -41,50 +41,40 @@ fn test_assign_multi_expr() {
|
|||
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{}
|
||||
}
|
||||
|
@ -97,7 +87,10 @@ fn test_assign_multi_expr() {
|
|||
q, r, s = if false {
|
||||
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 := '?'
|
||||
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
|
||||
|
|
|
@ -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,7 +59,10 @@ 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)
|
||||
assert x.a == 2
|
||||
|
@ -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
|
||||
|
||||
|
@ -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() {
|
||||
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,8 +140,14 @@ 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
|
||||
|
||||
|
|
|
@ -46,7 +46,6 @@ fn test_fixed_array_can_be_used_in_declaration() {
|
|||
assert v[1] == x
|
||||
}
|
||||
|
||||
|
||||
struct Context {
|
||||
pub mut:
|
||||
vb [8]f64
|
||||
|
@ -120,4 +119,3 @@ fn test_for_in_fixed_array() {
|
|||
arr := [1, 2, 3]!
|
||||
calc_size(arr)
|
||||
}
|
||||
|
||||
|
|
|
@ -51,5 +51,3 @@ fn test_fn_assignment_array() {
|
|||
assert a[0] == 12
|
||||
assert a[1] == 10
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
fn cross_assign_anon_fn_one(a int, b bool) string {
|
||||
return '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 {
|
||||
|
|
|
@ -13,20 +13,19 @@ fn high_fn_no_ret(f fn(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_return_single_anon() (fn(int)f32) {
|
||||
fn high_fn_return_single_anon() fn (int) f32 {
|
||||
_ = 1
|
||||
correct := fn (n int) f32 {
|
||||
return f32(n * n)
|
||||
}
|
||||
return correct
|
||||
}
|
||||
|
||||
fn high_fn_return_multi_anons() (fn (int) f32, fn (int) string) {
|
||||
// parsing trap
|
||||
_ = 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
|
||||
}
|
||||
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'
|
||||
|
@ -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 {
|
||||
return s.len
|
||||
}
|
||||
func3 := anon_func1
|
||||
res3 := func3("fish")
|
||||
res3 := func3('fish')
|
||||
assert res3 == 4
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,13 @@ fn test_fn_array_direct_call() {
|
|||
}
|
||||
|
||||
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']())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ fn test_multiple_ret() {
|
|||
|
||||
// none case
|
||||
wrapper1 := fn () (string, string) {
|
||||
res2_1, res2_2 := split_to_two("") or {
|
||||
res2_1, res2_2 := split_to_two('') or {
|
||||
assert err.msg == ''
|
||||
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 }
|
||||
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 }
|
||||
shared my_default := St{
|
||||
x: 37.5
|
||||
}
|
||||
my_default
|
||||
}
|
||||
val := rlock yy { yy.x }
|
||||
val := rlock yy {
|
||||
yy.x
|
||||
}
|
||||
assert val == 37.5
|
||||
}
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -31,7 +31,9 @@ fn foo3(mut m map[string][3]int){
|
|||
}
|
||||
|
||||
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]}"
|
||||
|
@ -44,14 +46,19 @@ fn foo4(mut m map[string][3]int){
|
|||
}
|
||||
|
||||
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,11 +1,18 @@
|
|||
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}
|
||||
}
|
||||
|
||||
fn test_generic_function_returning_type_starting_with_t() {
|
||||
ft := new_tensor<f64>(x: 123)
|
||||
println(ft)
|
||||
|
@ -24,6 +31,7 @@ fn new_t<T>(o T) T {
|
|||
x := T(o)
|
||||
return x
|
||||
}
|
||||
|
||||
fn test_generic_function_returning_t_type() {
|
||||
f := new_t<f64>(1.23)
|
||||
i := new_t<int>(456)
|
||||
|
|
|
@ -12,7 +12,7 @@ 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<string, XX>('s', XX{})
|
||||
assert show_result<XX, string>(XX{}, 's')
|
||||
assert show_result<XX, YY>(XX{}, YY{})
|
||||
}
|
||||
|
|
|
@ -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,7 +11,9 @@ 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
|
||||
}
|
||||
|
@ -118,7 +120,9 @@ fn test_return_array() {
|
|||
}
|
||||
|
||||
fn opt<T>(v T) ?T {
|
||||
if sizeof(T) > 1 {return v}
|
||||
if sizeof(T) > 1 {
|
||||
return v
|
||||
}
|
||||
return none
|
||||
}
|
||||
|
||||
|
@ -296,7 +300,6 @@ fn test_generic_struct_print_array_as_field() {
|
|||
data: []string{}
|
||||
}
|
||||
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() {
|
||||
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() {
|
||||
|
@ -384,8 +394,11 @@ fn multi_return<A, B>() (A, B) {
|
|||
}
|
||||
|
||||
struct Foo1 {}
|
||||
|
||||
struct Foo2 {}
|
||||
|
||||
struct Foo3 {}
|
||||
|
||||
struct Foo4 {}
|
||||
|
||||
fn test_multi_return() {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -18,7 +18,10 @@ fn test_fn_return() {
|
|||
}
|
||||
|
||||
fn test_map_get() {
|
||||
mut m := {'xy': 5, 'zu': 7}
|
||||
mut m := map{
|
||||
'xy': 5
|
||||
'zu': 7
|
||||
}
|
||||
mut res := []int{cap: 2}
|
||||
for k in ['jk', 'zu'] {
|
||||
if x := m[k] {
|
||||
|
|
|
@ -38,7 +38,7 @@ fn test_nested_if_smartcast() {
|
|||
}
|
||||
}
|
||||
|
||||
type Bar = string | Test
|
||||
type Bar = Test | string
|
||||
type Xya = int | string
|
||||
|
||||
struct Test {
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -284,8 +288,12 @@ pub mut:
|
|||
|
||||
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 {
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
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}
|
||||
p0 := Point{
|
||||
x: 10
|
||||
y: 20
|
||||
}
|
||||
p1 := Point{
|
||||
x: 40
|
||||
y: 60
|
||||
}
|
||||
// array init
|
||||
l0 := Line{
|
||||
ps: [p0, p1]
|
||||
|
@ -14,7 +20,10 @@ fn test_imported_symbols_types() {
|
|||
}
|
||||
|
||||
fn test_imported_symbols_functions() {
|
||||
p0 := Point{x: 20 y: 40}
|
||||
p0 := Point{
|
||||
x: 20
|
||||
y: 40
|
||||
}
|
||||
// method
|
||||
assert p0.str() == '20 40'
|
||||
// function
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
enum Colors {
|
||||
red green blue yellow
|
||||
red
|
||||
green
|
||||
blue
|
||||
yellow
|
||||
}
|
||||
|
||||
fn test_in_expression() {
|
||||
|
@ -105,7 +108,7 @@ fn test_in_expression_with_string() {
|
|||
}
|
||||
|
||||
fn test_in_expression_in_map() {
|
||||
m := {
|
||||
m := map{
|
||||
'one': 1
|
||||
'two': 2
|
||||
'three': 3
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
struct Dog { breed string }
|
||||
struct Cat { breed string }
|
||||
struct Dog {
|
||||
breed string
|
||||
}
|
||||
|
||||
struct Cat {
|
||||
breed string
|
||||
}
|
||||
|
||||
interface Animal {
|
||||
breed string
|
||||
|
@ -26,7 +31,9 @@ struct Holder2 {
|
|||
fn test_auto_str_gen_for_complex_interface_types() {
|
||||
a := Animal(Dog{'hi'})
|
||||
h := Holder{a}
|
||||
m := map{'dsa': h}
|
||||
m := map{
|
||||
'dsa': h
|
||||
}
|
||||
h2 := Holder2{m, 'N/A'}
|
||||
a2 := Animal(h2)
|
||||
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
@ -101,8 +111,12 @@ fn bar4(mut m map[string]fn (string) int) int {
|
|||
}
|
||||
|
||||
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}}"
|
||||
|
|
|
@ -13,7 +13,8 @@ fn test_const_keys() {
|
|||
}
|
||||
|
||||
enum Enum {
|
||||
a b
|
||||
a
|
||||
b
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
@ -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'})
|
||||
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,7 +1,8 @@
|
|||
|
||||
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() {
|
||||
// tests whether an ordinary branch supports multiple statements,
|
||||
|
@ -13,7 +14,8 @@ fn test_match_expression_on_sumtype_ordinary_branch(){
|
|||
c = 1
|
||||
eprintln('hi')
|
||||
'a string'
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
'unknown'
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +23,6 @@ fn test_match_expression_on_sumtype_ordinary_branch(){
|
|||
assert c == 1
|
||||
}
|
||||
|
||||
|
||||
fn test_match_expression_on_sumtype_else() {
|
||||
// tests whether else branches support multiple statements,
|
||||
// when the other branches are simple default expressions
|
||||
|
@ -30,7 +31,8 @@ fn test_match_expression_on_sumtype_else(){
|
|||
res := match s {
|
||||
string {
|
||||
'a string'
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
c = 3
|
||||
eprintln('hi')
|
||||
'unknown'
|
||||
|
|
|
@ -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,9 +1,19 @@
|
|||
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'})
|
||||
a := Animal(Dog{
|
||||
name: 'Jet'
|
||||
})
|
||||
match a {
|
||||
Dog { assert true }
|
||||
Cat { 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() {
|
||||
|
|
|
@ -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,7 +7,7 @@ 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 {
|
||||
|
|
|
@ -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 }
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
/*
|
||||
module acommentedmodule
|
||||
|
||||
|
||||
*/
|
||||
|
|
|
@ -29,7 +29,7 @@ pub fn (a Point) +(b Point) Point {
|
|||
}
|
||||
|
||||
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}
|
||||
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}
|
||||
one := Point{
|
||||
x: 1
|
||||
y: 2
|
||||
}
|
||||
assert '$one' == '1 2'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module xxx
|
||||
|
||||
pub fn f() string {
|
||||
return 'x'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module yyy
|
||||
|
||||
pub fn f() string {
|
||||
return 'y'
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
module zzz
|
||||
|
||||
pub fn f() string {
|
||||
return 'z'
|
||||
}
|
||||
|
|
|
@ -69,7 +69,9 @@ mut:
|
|||
}
|
||||
|
||||
fn f(mut x St) {
|
||||
mut y := St{n: 2}
|
||||
mut y := St{
|
||||
n: 2
|
||||
}
|
||||
a := x
|
||||
b := y
|
||||
x.n = 3
|
||||
|
@ -79,7 +81,9 @@ fn f(mut x St) {
|
|||
}
|
||||
|
||||
fn test_mut_4() {
|
||||
mut x := St{ n: 1 }
|
||||
mut x := St{
|
||||
n: 1
|
||||
}
|
||||
f(mut x)
|
||||
}
|
||||
|
||||
|
@ -98,7 +102,7 @@ fn test_mut_5() {
|
|||
vv = ii
|
||||
aa := vv
|
||||
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
|
||||
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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
|
|
@ -9,7 +9,11 @@ struct Cat {
|
|||
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,8 +11,12 @@ 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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
fn test_error_can_be_converted_to_string() {
|
||||
assert 'Option{ error: "an error" }' == error('an error').str()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module main
|
||||
|
||||
import mod1
|
||||
import v.tests.project_with_c_code.mod1
|
||||
|
||||
fn main() {
|
||||
res := mod1.vadd(1, 2)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -3,6 +3,7 @@ module modc
|
|||
#flag -I @VROOT
|
||||
#flag @VROOT/impl.o
|
||||
#include "header.h"
|
||||
|
||||
struct C.Atype {
|
||||
}
|
||||
|
||||
|
|
|
@ -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() {
|
||||
assert 1051 == m.f()
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#!/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('The result of calling m.f is: ' + m.f().str())
|
||||
|
||||
|
||||
/*
|
||||
NB: this main program v script is under bin/ ,
|
||||
but it *still* can find mod1, because the parent project has v.mod,
|
||||
|
|
|
@ -5,11 +5,10 @@ This submodule just imports its sibling submodules.
|
|||
Note that they are NOT under 'submodule' itself,
|
||||
but are in its parent mod1 , and mod1 has a 'v.mod' file.
|
||||
*/
|
||||
|
||||
import mod11
|
||||
import mod12
|
||||
import mod13
|
||||
import mod14
|
||||
import v.tests.project_with_modules_having_submodules.mod1.mod11
|
||||
import v.tests.project_with_modules_having_submodules.mod1.mod12
|
||||
import v.tests.project_with_modules_having_submodules.mod1.mod13
|
||||
import v.tests.project_with_modules_having_submodules.mod1.mod14
|
||||
|
||||
pub fn f() int {
|
||||
return 1000 + mod11.f() + mod12.f() + mod13.f() + mod14.f()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import mod1
|
||||
import mod1.submodule
|
||||
import v.tests.project_with_modules_having_submodules.mod1
|
||||
import v.tests.project_with_modules_having_submodules.mod1.submodule
|
||||
|
||||
fn test_mod1() {
|
||||
assert 1 == mod1.f()
|
||||
|
|
|
@ -21,27 +21,35 @@ mut:
|
|||
}
|
||||
|
||||
fn test_ref() {
|
||||
a := &Abc{ n: 3 }
|
||||
a := &Abc{
|
||||
n: 3
|
||||
}
|
||||
assert a.n == 3
|
||||
}
|
||||
|
||||
fn test_shared() {
|
||||
shared a := Abc{ n: 4 }
|
||||
res := rlock a { a.n }
|
||||
shared a := Abc{
|
||||
n: 4
|
||||
}
|
||||
res := rlock a {
|
||||
a.n
|
||||
}
|
||||
assert res == 4
|
||||
}
|
||||
|
||||
fn test_embed_in_ref_struct() {
|
||||
a := &St{
|
||||
Abc{ n: 5 }
|
||||
}
|
||||
a := &St{Abc{
|
||||
n: 5
|
||||
}}
|
||||
assert a.n == 5
|
||||
}
|
||||
|
||||
fn test_field_in_ref_struct() {
|
||||
x := &Qwe{
|
||||
f: 12.25
|
||||
a: Abc{ n: 23 }
|
||||
a: Abc{
|
||||
n: 23
|
||||
}
|
||||
}
|
||||
assert x.a.n == 23
|
||||
}
|
||||
|
@ -49,7 +57,9 @@ fn test_field_in_ref_struct() {
|
|||
fn test_ref_field() {
|
||||
y := Rtz{
|
||||
f: -6.25
|
||||
a: &Abc{ n: 29 }
|
||||
a: &Abc{
|
||||
n: 29
|
||||
}
|
||||
}
|
||||
assert y.a.n == 29
|
||||
}
|
||||
|
|
|
@ -42,9 +42,7 @@ fn test_all_v_repl_files() {
|
|||
panic(err)
|
||||
}
|
||||
session.bmark.set_total_expected_steps(session.options.files.len)
|
||||
mut pool_repl := pool.new_pool_processor(
|
||||
callback: worker_repl
|
||||
)
|
||||
mut pool_repl := pool.new_pool_processor(callback: worker_repl)
|
||||
pool_repl.set_shared_context(session)
|
||||
$if windows {
|
||||
// See: https://docs.microsoft.com/en-us/cpp/build/reference/fs-force-synchronous-pdb-writes?view=vs-2019
|
||||
|
|
|
@ -35,10 +35,18 @@ fn a_val(a []int) int {
|
|||
}
|
||||
|
||||
fn test_shared_as_value() {
|
||||
shared s := St{ a: 5 }
|
||||
shared s := St{
|
||||
a: 5
|
||||
}
|
||||
shared a := [3, 4, 6, 13, -23]
|
||||
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
|
||||
shared r := Qr{ a: 7 }
|
||||
shared m := map{
|
||||
'qw': 12.75
|
||||
'yxcv': -3.125
|
||||
'poiu': 88.0625
|
||||
}
|
||||
shared r := Qr{
|
||||
a: 7
|
||||
}
|
||||
rlock s, r {
|
||||
u := r.s_val(s)
|
||||
assert u == 35
|
||||
|
@ -58,10 +66,18 @@ fn test_shared_as_value() {
|
|||
}
|
||||
|
||||
fn test_shared_as_mut() {
|
||||
shared s := St{ a: 5 }
|
||||
shared s := St{
|
||||
a: 5
|
||||
}
|
||||
shared a := [3, 4, 6, 13, -23]
|
||||
shared m := {'qw': 12.75, 'yxcv': -3.125, 'poiu': 88.0625}
|
||||
shared r := Qr{ a: 7 }
|
||||
shared m := map{
|
||||
'qw': 12.75
|
||||
'yxcv': -3.125
|
||||
'poiu': 88.0625
|
||||
}
|
||||
shared r := Qr{
|
||||
a: 7
|
||||
}
|
||||
lock s, r {
|
||||
r.s_mut(mut s)
|
||||
x := r.a * s.a
|
||||
|
|
|
@ -23,7 +23,12 @@ fn inc_map_elem(shared b map[string]int, k string) {
|
|||
}
|
||||
|
||||
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')
|
||||
for _ in 0 .. iterations {
|
||||
m['asd']++
|
||||
|
@ -31,4 +36,3 @@ fn test_autolock_map() {
|
|||
t.wait()
|
||||
assert m['asd'] == 2 * iterations + 7
|
||||
}
|
||||
|
||||
|
|
|
@ -9,24 +9,36 @@ struct Abc {
|
|||
}
|
||||
|
||||
fn test_shared_struct_in_struct() {
|
||||
shared y := Xyz{ n: 7 }
|
||||
shared y := Xyz{
|
||||
n: 7
|
||||
}
|
||||
z := Abc{
|
||||
a: y
|
||||
}
|
||||
u := Xyz{ n: 17 }
|
||||
u := Xyz{
|
||||
n: 17
|
||||
}
|
||||
x := Abc{
|
||||
a: u
|
||||
}
|
||||
v := Abc{
|
||||
a: Xyz{ n: 5 }
|
||||
a: Xyz{
|
||||
n: 5
|
||||
}
|
||||
i: 3
|
||||
}
|
||||
shared f := x.a
|
||||
shared g := v.a
|
||||
shared h := z.a
|
||||
a := rlock f { f.n }
|
||||
b := rlock g { g.n }
|
||||
c := rlock h { h.n }
|
||||
a := rlock f {
|
||||
f.n
|
||||
}
|
||||
b := rlock g {
|
||||
g.n
|
||||
}
|
||||
c := rlock h {
|
||||
h.n
|
||||
}
|
||||
assert a == 17
|
||||
assert b == 5
|
||||
assert c == 7
|
||||
|
@ -48,8 +60,12 @@ fn test_shared_array_in_struct() {
|
|||
t[2] = -1.125
|
||||
}
|
||||
shared tt := x.a
|
||||
v := rlock tt { tt[3] }
|
||||
w := rlock tt { tt[2] }
|
||||
v := rlock tt {
|
||||
tt[3]
|
||||
}
|
||||
w := rlock tt {
|
||||
tt[2]
|
||||
}
|
||||
assert v == 13.0625
|
||||
assert w == -1.125
|
||||
assert x.i == 12
|
||||
|
@ -62,7 +78,11 @@ struct Hjk {
|
|||
|
||||
fn test_shared_map_in_struct() {
|
||||
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
|
||||
}
|
||||
shared k := x.m
|
||||
|
@ -70,8 +90,12 @@ fn test_shared_map_in_struct() {
|
|||
k['yxc'] = -23.5
|
||||
}
|
||||
shared p := x.m
|
||||
a := rlock p { p['xy'] }
|
||||
b := rlock p { p['yxc'] }
|
||||
a := rlock p {
|
||||
p['xy']
|
||||
}
|
||||
b := rlock p {
|
||||
p['yxc']
|
||||
}
|
||||
assert a == 12.125
|
||||
assert b == -23.5
|
||||
assert x.i == 23
|
||||
|
@ -79,11 +103,17 @@ fn test_shared_map_in_struct() {
|
|||
|
||||
fn test_array_of_shared() {
|
||||
mut a := []shared Xyz{cap: 3}
|
||||
a0 := Xyz{ n: 3 }
|
||||
a0 := Xyz{
|
||||
n: 3
|
||||
}
|
||||
a << a0
|
||||
a1 := Xyz{ n: 7 }
|
||||
a1 := Xyz{
|
||||
n: 7
|
||||
}
|
||||
a << a1
|
||||
a2 := Xyz{ n: 13 }
|
||||
a2 := Xyz{
|
||||
n: 13
|
||||
}
|
||||
a << a2
|
||||
shared p := a[0]
|
||||
shared q := a[2]
|
||||
|
@ -91,8 +121,12 @@ fn test_array_of_shared() {
|
|||
q.n = -17
|
||||
}
|
||||
shared r := a[2]
|
||||
e := rlock p { p.n }
|
||||
f := rlock r { r.n }
|
||||
e := rlock p {
|
||||
p.n
|
||||
}
|
||||
f := rlock r {
|
||||
r.n
|
||||
}
|
||||
assert e == 3
|
||||
assert f == -17
|
||||
}
|
||||
|
|
|
@ -4,7 +4,9 @@ mut:
|
|||
}
|
||||
|
||||
fn f() St {
|
||||
x := St{ x: 3.25 }
|
||||
x := St{
|
||||
x: 3.25
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
|
@ -12,19 +14,25 @@ fn g(good bool) ?St {
|
|||
if !good {
|
||||
return error('no St created')
|
||||
}
|
||||
x := St{ x: 12.75 }
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -36,13 +44,25 @@ fn test_shared_opt_propagate() {
|
|||
}
|
||||
|
||||
fn test_shared_opt_good() {
|
||||
shared yy := g(true) or { St{ x: 37.5 } }
|
||||
val := rlock yy { yy.x }
|
||||
shared yy := g(true) or {
|
||||
St{
|
||||
x: 37.5
|
||||
}
|
||||
}
|
||||
val := rlock yy {
|
||||
yy.x
|
||||
}
|
||||
assert val == 12.75
|
||||
}
|
||||
|
||||
fn test_shared_opt_bad() {
|
||||
shared yy := g(false) or { St{ x: 37.5 } }
|
||||
val := rlock yy { yy.x }
|
||||
shared yy := g(false) or {
|
||||
St{
|
||||
x: 37.5
|
||||
}
|
||||
}
|
||||
val := rlock yy {
|
||||
yy.x
|
||||
}
|
||||
assert val == 37.5
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
for _ in 0 .. 10000 {
|
||||
rlock x; lock y, z {
|
||||
lock y, z; rlock x {
|
||||
y.a += x.a
|
||||
if y.a > 1000000 {
|
||||
y.a /= 2
|
||||
|
|
|
@ -4,11 +4,19 @@ mut:
|
|||
}
|
||||
|
||||
fn test_lock_expr() {
|
||||
shared xx := St{ i: 173 }
|
||||
shared y := St{ i: -57 }
|
||||
shared xx := St{
|
||||
i: 173
|
||||
}
|
||||
shared y := St{
|
||||
i: -57
|
||||
}
|
||||
mut m := 0
|
||||
m = lock y { y.i }
|
||||
n := rlock xx { xx.i }
|
||||
m = lock y {
|
||||
y.i
|
||||
}
|
||||
n := rlock xx {
|
||||
xx.i
|
||||
}
|
||||
assert m == -57
|
||||
assert n == 173
|
||||
}
|
||||
|
@ -19,10 +27,18 @@ mut:
|
|||
}
|
||||
|
||||
fn test_multi_objects() {
|
||||
shared x := Abc{ a: 12.5 }
|
||||
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 }
|
||||
shared x := Abc{
|
||||
a: 12.5
|
||||
}
|
||||
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 b == 13.125
|
||||
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() {
|
||||
shared x := Abc{ a: 12.5 }
|
||||
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) }
|
||||
shared x := Abc{
|
||||
a: 12.5
|
||||
}
|
||||
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 b == 13.125
|
||||
assert c == -7.5
|
||||
|
|
|
@ -10,7 +10,10 @@ fn incr(shared foo map[string]int, key string, mut sem sync.Semaphore) {
|
|||
}
|
||||
|
||||
fn test_shared_array() {
|
||||
shared foo := {'p': 10, 'q': 0}
|
||||
shared foo := map{
|
||||
'p': 10
|
||||
'q': 0
|
||||
}
|
||||
lock foo {
|
||||
foo['q'] = 20
|
||||
}
|
||||
|
@ -37,8 +40,16 @@ fn test_shared_array() {
|
|||
}
|
||||
|
||||
fn test_shared_init_syntax() {
|
||||
shared foo := &{'p': 17, 'q': -3, 'qwertz': 10}
|
||||
shared bar := {'wer': 13.75, 'cvbn': -7.25, 'asd': -0.0625}
|
||||
shared foo := &map{
|
||||
'p': 17
|
||||
'q': -3
|
||||
'qwertz': 10
|
||||
}
|
||||
shared bar := map{
|
||||
'wer': 13.75
|
||||
'cvbn': -7.25
|
||||
'asd': -0.0625
|
||||
}
|
||||
shared baz := &map[string]int{}
|
||||
shared qux := map[string]f64{}
|
||||
shared quux := new_map()
|
||||
|
@ -64,6 +75,10 @@ fn test_shared_init_syntax() {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -7,7 +7,11 @@ mut:
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -15,9 +19,13 @@ fn (mut a Large) add(b Large) {
|
|||
oldl := a.l
|
||||
a.l += b.l
|
||||
oldm := a.m
|
||||
if a.l < oldl { a.m++ }
|
||||
if a.l < oldl {
|
||||
a.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
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
// initialze objects so that their sum = 1
|
||||
shared a := Large{ l: 4 }
|
||||
shared b := Large{ 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) }
|
||||
shared a := Large{
|
||||
l: 4
|
||||
}
|
||||
shared b := Large{
|
||||
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
|
||||
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)
|
||||
|
@ -63,4 +87,3 @@ fn test_mixed_order_lock_rlock() {
|
|||
assert sum.m == 0
|
||||
assert sum.h == 4194304
|
||||
}
|
||||
|
||||
|
|
|
@ -10,9 +10,7 @@ fn t(options TOptions) bool {
|
|||
}
|
||||
|
||||
fn test_short_struct_as_parameter() {
|
||||
if t({
|
||||
a: 1
|
||||
}) {
|
||||
if t(a: 1) {
|
||||
assert true
|
||||
return
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import flag
|
|||
struct S1 {
|
||||
p voidptr
|
||||
}
|
||||
|
||||
struct S2 {
|
||||
i int
|
||||
}
|
||||
|
|
|
@ -6,11 +6,21 @@ mut:
|
|||
fn test_array_sort_by_references() {
|
||||
mut a := []&Container{}
|
||||
|
||||
a << &Container{ name: 'a' }
|
||||
a << &Container{ name: 'b' }
|
||||
a << &Container{ name: 'c' }
|
||||
a << &Container{ name: 'd' }
|
||||
a << &Container{ name: 'e' }
|
||||
a << &Container{
|
||||
name: 'a'
|
||||
}
|
||||
a << &Container{
|
||||
name: 'b'
|
||||
}
|
||||
a << &Container{
|
||||
name: 'c'
|
||||
}
|
||||
a << &Container{
|
||||
name: 'd'
|
||||
}
|
||||
a << &Container{
|
||||
name: 'e'
|
||||
}
|
||||
|
||||
a.sort(a.name > b.name)
|
||||
println(a)
|
||||
|
|
|
@ -55,31 +55,51 @@ fn test_array_of_strings() {
|
|||
}
|
||||
|
||||
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' == "{'a': 1, 'b': 2, 'c': 3}"
|
||||
}
|
||||
|
||||
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' == "{'a': '1', 'b': '2', 'c': '3'}"
|
||||
}
|
||||
|
||||
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' == "{'a': 1.1, 'b': 2.2, 'c': 3.3}"
|
||||
}
|
||||
|
||||
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' == "{'a': `a`, 'b': `b`, 'c': `c`}"
|
||||
}
|
||||
|
||||
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' == "{'a': true, 'b': false, 'c': true}"
|
||||
}
|
||||
|
@ -143,16 +163,18 @@ fn test_fixed_array_of_strings() {
|
|||
struct Wrapper {
|
||||
foo &string
|
||||
}
|
||||
|
||||
fn test_struct_with_string_pointer() {
|
||||
s := 'test'
|
||||
w := Wrapper{&s}
|
||||
assert '$w' == 'Wrapper{\n foo: &\'test\'\n}'
|
||||
assert w.str() == 'Wrapper{\n foo: &\'test\'\n}'
|
||||
assert '$w' == "Wrapper{\n foo: &'test'\n}"
|
||||
assert w.str() == "Wrapper{\n foo: &'test'\n}"
|
||||
}
|
||||
|
||||
struct Wrapper2 {
|
||||
foo &int
|
||||
}
|
||||
|
||||
fn test_struct_with_int_pointer() {
|
||||
i := 5
|
||||
w := Wrapper2{&i}
|
||||
|
@ -163,6 +185,7 @@ fn test_struct_with_int_pointer() {
|
|||
struct Wrapper3 {
|
||||
foo &bool
|
||||
}
|
||||
|
||||
fn test_struct_with_bool_pointer() {
|
||||
b := true
|
||||
w := Wrapper3{&b}
|
||||
|
@ -171,9 +194,11 @@ fn test_struct_with_bool_pointer() {
|
|||
}
|
||||
|
||||
struct Foo {}
|
||||
|
||||
struct Wrapper4 {
|
||||
foo &Foo
|
||||
}
|
||||
|
||||
fn test_struct_with_struct_pointer() {
|
||||
b := Foo{}
|
||||
w := Wrapper4{&b}
|
||||
|
@ -190,6 +215,7 @@ fn test_struct_with_nil() {
|
|||
struct Wrapper5 {
|
||||
foo &f32
|
||||
}
|
||||
|
||||
fn test_struct_with_f32_pointer() {
|
||||
i := f32(5.1)
|
||||
w := Wrapper5{&i}
|
||||
|
@ -197,13 +223,14 @@ fn test_struct_with_f32_pointer() {
|
|||
assert w.str() == 'Wrapper5{\n foo: &5.1\n}'
|
||||
}
|
||||
|
||||
|
||||
struct TestStruct {
|
||||
x int
|
||||
}
|
||||
|
||||
struct ArrayWithStruct {
|
||||
foo []TestStruct
|
||||
}
|
||||
|
||||
fn test_array_with_struct() {
|
||||
a := ArrayWithStruct{[TestStruct{}]}
|
||||
assert a.str() == 'ArrayWithStruct{\n foo: [TestStruct{\n x: 0\n }]\n}'
|
||||
|
@ -213,13 +240,17 @@ fn test_array_with_struct() {
|
|||
struct MapWithStruct {
|
||||
foo map[string]TestStruct
|
||||
}
|
||||
|
||||
fn test_map_with_struct() {
|
||||
a := MapWithStruct{{'test': TestStruct{}}}
|
||||
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}'
|
||||
a := MapWithStruct{map{
|
||||
'test': TestStruct{}
|
||||
}}
|
||||
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 {}
|
||||
|
||||
fn generic_fn_interpolation<T>(p T) string {
|
||||
return '$p'
|
||||
}
|
||||
|
@ -235,6 +266,7 @@ fn test_generic_auto_str() {
|
|||
}
|
||||
|
||||
type Alias1 = int
|
||||
|
||||
fn test_alias_in_array() {
|
||||
t := [Alias1(1)]
|
||||
assert t.str() == '[1]'
|
||||
|
@ -242,6 +274,7 @@ fn test_alias_in_array() {
|
|||
}
|
||||
|
||||
type Alias2 = int
|
||||
|
||||
fn test_alias_in_fixed_array() {
|
||||
t := [Alias1(1)]!
|
||||
assert t.str() == '[1]'
|
||||
|
@ -255,6 +288,7 @@ fn test_alias_int() {
|
|||
}
|
||||
|
||||
type Alias3 = string
|
||||
|
||||
fn test_alias_string() {
|
||||
s := 'test'
|
||||
a := Alias3(s)
|
||||
|
@ -263,6 +297,7 @@ fn test_alias_string() {
|
|||
}
|
||||
|
||||
type TestAlias = TestStruct
|
||||
|
||||
fn test_alias_struct() {
|
||||
ts := TestStruct{}
|
||||
t := TestAlias(ts)
|
||||
|
@ -296,7 +331,7 @@ fn create_option_err() ?string {
|
|||
}
|
||||
|
||||
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 {
|
||||
|
@ -312,7 +347,7 @@ fn create_option_string() ?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 {
|
||||
|
@ -348,7 +383,8 @@ fn test_option_struct() {
|
|||
// assert '$w' == 'OptionWrapper{\n x: Option(error: \'\')\n}'
|
||||
// }
|
||||
|
||||
/* TODO: doesn't work yet
|
||||
/*
|
||||
TODO: doesn't work yet
|
||||
struct OptionWrapperInt {
|
||||
x ?int
|
||||
}
|
||||
|
@ -360,11 +396,11 @@ fn test_struct_with_option() {
|
|||
*/
|
||||
|
||||
struct One {
|
||||
value string = "one"
|
||||
value string = 'one'
|
||||
}
|
||||
|
||||
struct Two {
|
||||
value string = "two"
|
||||
value string = 'two'
|
||||
}
|
||||
|
||||
fn mr_int_int() (int, int) {
|
||||
|
|
|
@ -11,7 +11,10 @@ fn test_fixed_array_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("'two': '2'")
|
||||
}
|
||||
|
|
|
@ -79,24 +79,30 @@ fn test_array_of_strings_interpolation() {
|
|||
|
||||
fn test_array_of_map_interpolation() {
|
||||
mut a := []map[string]int{}
|
||||
a << {'a': int(1), 'b': 2}
|
||||
a << {'c': int(3), 'd': 4}
|
||||
a << map{
|
||||
'a': int(1)
|
||||
'b': 2
|
||||
}
|
||||
a << map{
|
||||
'c': int(3)
|
||||
'd': 4
|
||||
}
|
||||
assert '$a' == "[{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]"
|
||||
}
|
||||
|
||||
fn test_array_initialization_with_interpolation() {
|
||||
sysroot := '/usr'
|
||||
a := [
|
||||
'abcd'
|
||||
'$sysroot/xyz'
|
||||
'u$sysroot/vw'
|
||||
'/rr$sysroot'
|
||||
'lmno'
|
||||
'abcd',
|
||||
'$sysroot/xyz',
|
||||
'u$sysroot/vw',
|
||||
'/rr$sysroot',
|
||||
'lmno',
|
||||
]
|
||||
assert '$a' == "['abcd', '/usr/xyz', 'u/usr/vw', '/rr/usr', 'lmno']"
|
||||
b := [
|
||||
'a${sysroot:5}/r'
|
||||
'ert'
|
||||
'a${sysroot:5}/r',
|
||||
'ert',
|
||||
]
|
||||
assert '$b' == "['a /usr/r', 'ert']"
|
||||
c := ['xy', 'r$sysroot', '$sysroot/t', '>$sysroot<']
|
||||
|
|
|
@ -3,7 +3,7 @@ struct Foo {
|
|||
}
|
||||
|
||||
fn (f &Foo) str() string {
|
||||
return '${f.bar}'
|
||||
return '$f.bar'
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
|
|
|
@ -3,7 +3,9 @@ fn show(a string) string {
|
|||
}
|
||||
|
||||
fn test_function_interpolation() {
|
||||
f := fn()(string, bool) {return 'aaa', true}
|
||||
f := fn () (string, bool) {
|
||||
return 'aaa', true
|
||||
}
|
||||
println(f)
|
||||
assert '$f' == 'fn () (string, bool)'
|
||||
|
||||
|
@ -18,7 +20,9 @@ struct Info {
|
|||
|
||||
fn test_function_interpolation_in_struct() {
|
||||
a := Info{
|
||||
aa: fn()string {return 'aaa'}
|
||||
aa: fn () string {
|
||||
return 'aaa'
|
||||
}
|
||||
bb: 22
|
||||
}
|
||||
println(a)
|
||||
|
@ -26,14 +30,24 @@ fn test_function_interpolation_in_struct() {
|
|||
}
|
||||
|
||||
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)
|
||||
assert '$f' == '[fn () string, fn () string]'
|
||||
}
|
||||
|
||||
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)
|
||||
assert '$m'.contains(': fn () string')
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue