tests: small array/struct test notes & tmp fix
parent
ed42b864c1
commit
fd8bb2c95c
|
@ -339,6 +339,19 @@ mut:
|
||||||
b []Test2
|
b []Test2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: default array/struct str methods
|
||||||
|
pub fn (ta []Test2) str() string {
|
||||||
|
mut s := '['
|
||||||
|
for i, t in ta {
|
||||||
|
s += t.str()
|
||||||
|
if i < ta.len-1 {
|
||||||
|
s += ', '
|
||||||
|
}
|
||||||
|
}
|
||||||
|
s += ']'
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
|
||||||
pub fn (t Test2) str() string {
|
pub fn (t Test2) str() string {
|
||||||
return '{$t.one $t.two}'
|
return '{$t.one $t.two}'
|
||||||
}
|
}
|
||||||
|
@ -348,9 +361,6 @@ pub fn (t Test) str() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_struct_print() {
|
fn test_struct_print() {
|
||||||
println('QTODO')
|
|
||||||
|
|
||||||
/*
|
|
||||||
mut a := Test{
|
mut a := Test{
|
||||||
a: 'Test'
|
a: 'Test'
|
||||||
b: []
|
b: []
|
||||||
|
@ -361,10 +371,10 @@ fn test_struct_print() {
|
||||||
}
|
}
|
||||||
a.b << b
|
a.b << b
|
||||||
a.b << b
|
a.b << b
|
||||||
assert a.str() == '{Test [{1 2}, {1 2}] }'
|
println('QTODO: v2 struct .str() methods')
|
||||||
assert b.str() == '{1 2}'
|
// assert a.str() == '{Test [{1 2}, {1 2}] }'
|
||||||
|
// assert b.str() == '{1 2}'
|
||||||
assert a.b.str() == '[{1 2}, {1 2}]'
|
assert a.b.str() == '[{1 2}, {1 2}]'
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_single_element() {
|
fn test_single_element() {
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
struct AA {
|
struct Aa {
|
||||||
mut:
|
mut:
|
||||||
val int
|
val int
|
||||||
nums []int
|
nums []int
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BB {
|
struct Bb {
|
||||||
mut:
|
mut:
|
||||||
a AA
|
a Aa
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CC {
|
struct Cu {
|
||||||
mut:
|
mut:
|
||||||
b BB
|
b Bb
|
||||||
nums []int
|
nums []int
|
||||||
aarr []AA
|
aarr []Aa
|
||||||
num int
|
num int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ fn test_empty_struct() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_struct_levels() {
|
fn test_struct_levels() {
|
||||||
mut c := CC{}
|
mut c := Cu{}
|
||||||
println(c.nums.len)
|
println(c.nums.len)
|
||||||
assert c.nums.len == 0
|
assert c.nums.len == 0
|
||||||
c.nums << 3
|
c.nums << 3
|
||||||
|
@ -82,7 +82,7 @@ fn test_struct_levels() {
|
||||||
assert c.b.a.nums[1] == 2
|
assert c.b.a.nums[1] == 2
|
||||||
c.b.a.nums[0] = 7
|
c.b.a.nums[0] = 7
|
||||||
assert c.b.a.nums[0] == 7
|
assert c.b.a.nums[0] == 7
|
||||||
c.aarr << AA{
|
c.aarr << Aa{
|
||||||
val: 8
|
val: 8
|
||||||
}
|
}
|
||||||
assert c.aarr.len == 1
|
assert c.aarr.len == 1
|
||||||
|
|
|
@ -281,6 +281,7 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr)
|
||||||
name := method_call_expr.name
|
name := method_call_expr.name
|
||||||
c.stmts(method_call_expr.or_block.stmts)
|
c.stmts(method_call_expr.or_block.stmts)
|
||||||
// println('method call $name $method_call_expr.pos.line_nr')
|
// println('method call $name $method_call_expr.pos.line_nr')
|
||||||
|
// TODO: remove this for actual methods, use only for compiler magic
|
||||||
if typ_sym.kind == .array && name in ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice'] {
|
if typ_sym.kind == .array && name in ['filter', 'clone', 'repeat', 'reverse', 'map', 'slice'] {
|
||||||
if name in ['filter', 'map'] {
|
if name in ['filter', 'map'] {
|
||||||
array_info := typ_sym.info as table.Array
|
array_info := typ_sym.info as table.Array
|
||||||
|
@ -344,7 +345,7 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr)
|
||||||
return table.string_type
|
return table.string_type
|
||||||
}
|
}
|
||||||
if typ_sym.kind == .array && name == 'str' {
|
if typ_sym.kind == .array && name == 'str' {
|
||||||
// method_call_expr.receiver_type = table.new_type(c.table.type_idxs['ar_string'])
|
method_call_expr.receiver_type = typ
|
||||||
method_call_expr.return_type = table.string_type
|
method_call_expr.return_type = table.string_type
|
||||||
return table.string_type
|
return table.string_type
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue