v2: lots of minor test fixes
parent
6764c7dd5c
commit
0de853a2ab
|
@ -242,6 +242,8 @@ jobs:
|
||||||
#node hi.js
|
#node hi.js
|
||||||
- name: Test v binaries
|
- name: Test v binaries
|
||||||
run: ./v -silent build-vbinaries
|
run: ./v -silent build-vbinaries
|
||||||
|
- name: v2 self compilation
|
||||||
|
run: .\v.exe -b v2 -o v2.exe cmd/v && .\v2.exe -b v2 -o v3.exe cmd/v
|
||||||
|
|
||||||
windows-msvc:
|
windows-msvc:
|
||||||
runs-on: windows-2019
|
runs-on: windows-2019
|
||||||
|
|
|
@ -117,14 +117,15 @@ pub:
|
||||||
|
|
||||||
pub struct StructDecl {
|
pub struct StructDecl {
|
||||||
pub:
|
pub:
|
||||||
pos token.Position
|
pos token.Position
|
||||||
name string
|
name string
|
||||||
fields []Field
|
fields []Field
|
||||||
is_pub bool
|
is_pub bool
|
||||||
mut_pos int // mut:
|
mut_pos int // mut:
|
||||||
pub_pos int // pub:
|
pub_pos int // pub:
|
||||||
pub_mut_pos int // pub mut:
|
pub_mut_pos int // pub mut:
|
||||||
is_c bool
|
is_c bool
|
||||||
|
default_exprs []ast.Expr
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct InterfaceDecl {
|
pub struct InterfaceDecl {
|
||||||
|
|
|
@ -210,6 +210,7 @@ pub fn (c mut Checker) call_expr(call_expr mut ast.CallExpr) table.Type {
|
||||||
}
|
}
|
||||||
else if !method.is_variadic && call_expr.args.len > no_args {
|
else if !method.is_variadic && call_expr.args.len > no_args {
|
||||||
c.error('too many arguments in call to `${left_type_sym.name}.$method_name` ($call_expr.args.len instead of $no_args)', call_expr.pos)
|
c.error('too many arguments in call to `${left_type_sym.name}.$method_name` ($call_expr.args.len instead of $no_args)', call_expr.pos)
|
||||||
|
return method.return_type
|
||||||
}
|
}
|
||||||
// if method_name == 'clone' {
|
// if method_name == 'clone' {
|
||||||
// println('CLONE nr args=$method.args.len')
|
// println('CLONE nr args=$method.args.len')
|
||||||
|
@ -311,6 +312,7 @@ pub fn (c mut Checker) call_expr(call_expr mut ast.CallExpr) table.Type {
|
||||||
}
|
}
|
||||||
else if !f.is_variadic && call_expr.args.len > f.args.len {
|
else if !f.is_variadic && call_expr.args.len > f.args.len {
|
||||||
c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos)
|
c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos)
|
||||||
|
return f.return_type
|
||||||
}
|
}
|
||||||
// println can print anything
|
// println can print anything
|
||||||
if fn_name == 'println' {
|
if fn_name == 'println' {
|
||||||
|
@ -765,6 +767,9 @@ pub fn (c mut Checker) expr(node ast.Expr) table.Type {
|
||||||
return table.int_type
|
return table.int_type
|
||||||
}
|
}
|
||||||
ast.StringLiteral {
|
ast.StringLiteral {
|
||||||
|
if it.is_c {
|
||||||
|
return table.byteptr_type
|
||||||
|
}
|
||||||
return table.string_type
|
return table.string_type
|
||||||
}
|
}
|
||||||
ast.StringInterLiteral {
|
ast.StringInterLiteral {
|
||||||
|
|
|
@ -1091,7 +1091,7 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||||
escaped_val := it.val.replace_each(['"', '\\"',
|
escaped_val := it.val.replace_each(['"', '\\"',
|
||||||
'\r\n', '\\n',
|
'\r\n', '\\n',
|
||||||
'\n', '\\n'])
|
'\n', '\\n'])
|
||||||
if g.is_c_call {
|
if g.is_c_call || it.is_c {
|
||||||
// In C calls we have to generate C strings
|
// In C calls we have to generate C strings
|
||||||
// `C.printf("hi")` => `printf("hi");`
|
// `C.printf("hi")` => `printf("hi");`
|
||||||
g.write('"$escaped_val"')
|
g.write('"$escaped_val"')
|
||||||
|
@ -2376,7 +2376,7 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
|
||||||
styp = styp.replace('*', '')
|
styp = styp.replace('*', '')
|
||||||
}
|
}
|
||||||
g.str_types << typ
|
g.str_types << typ
|
||||||
g.definitions.writeln('string ${styp}_str($styp* x) { return tos3("TODO_str"); }')
|
g.definitions.writeln('string ${styp}_str($styp x) { return tos3("TODO_str"); }')
|
||||||
}
|
}
|
||||||
if g.autofree && !table.type_is_optional(typ) {
|
if g.autofree && !table.type_is_optional(typ) {
|
||||||
// Create a temporary variable so that the value can be freed
|
// Create a temporary variable so that the value can be freed
|
||||||
|
@ -2395,6 +2395,10 @@ fn (g mut Gen) fn_call(node ast.CallExpr) {
|
||||||
// `println(int_str(10))`
|
// `println(int_str(10))`
|
||||||
// sym := g.table.get_type_symbol(node.args[0].typ)
|
// sym := g.table.get_type_symbol(node.args[0].typ)
|
||||||
g.write('println(${styp}_str(')
|
g.write('println(${styp}_str(')
|
||||||
|
if table.type_is_ptr(typ) {
|
||||||
|
// dereference
|
||||||
|
g.write('*')
|
||||||
|
}
|
||||||
g.expr(node.args[0].expr)
|
g.expr(node.args[0].expr)
|
||||||
g.write('))')
|
g.write('))')
|
||||||
}
|
}
|
||||||
|
|
|
@ -603,7 +603,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Raw string (`s := r'hello \n ')
|
// Raw string (`s := r'hello \n ')
|
||||||
if p.tok.lit == 'r' && p.peek_tok.kind == .string {
|
if p.tok.lit in ['r', 'c'] && p.peek_tok.kind == .string {
|
||||||
// && p.prev_tok.kind != .str_dollar {
|
// && p.prev_tok.kind != .str_dollar {
|
||||||
return p.string_expr()
|
return p.string_expr()
|
||||||
}
|
}
|
||||||
|
@ -1492,6 +1492,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
||||||
p.next() // .
|
p.next() // .
|
||||||
}
|
}
|
||||||
mut name := p.check_name()
|
mut name := p.check_name()
|
||||||
|
mut default_exprs := []ast.Expr
|
||||||
// println('struct decl $name')
|
// println('struct decl $name')
|
||||||
p.check(.lcbr)
|
p.check(.lcbr)
|
||||||
mut ast_fields := []ast.Field
|
mut ast_fields := []ast.Field
|
||||||
|
@ -1533,7 +1534,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
||||||
// Default value
|
// Default value
|
||||||
if p.tok.kind == .assign {
|
if p.tok.kind == .assign {
|
||||||
p.next()
|
p.next()
|
||||||
p.expr(0)
|
default_exprs << p.expr(0)
|
||||||
}
|
}
|
||||||
ast_fields << ast.Field{
|
ast_fields << ast.Field{
|
||||||
name: field_name
|
name: field_name
|
||||||
|
@ -1581,6 +1582,7 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
|
||||||
pub_pos: pub_pos
|
pub_pos: pub_pos
|
||||||
pub_mut_pos: pub_mut_pos
|
pub_mut_pos: pub_mut_pos
|
||||||
is_c: is_c
|
is_c: is_c
|
||||||
|
default_exprs: default_exprs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
fn test_cstring() {
|
fn test_cstring() {
|
||||||
w := c'world'
|
w := c'world'
|
||||||
hlen := C.strlen(c'hello')
|
hlen := C.strlen(c'hello')
|
||||||
|
hlen2 := C.strlen('hello')
|
||||||
wlen := C.strlen(w)
|
wlen := C.strlen(w)
|
||||||
assert hlen == 5
|
assert hlen == 5
|
||||||
|
assert hlen2 == 5
|
||||||
assert wlen == 5
|
assert wlen == 5
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,17 @@ fn variadic_test(name string, groups ...VaTestGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fn_variadic() {
|
fn test_fn_variadic() {
|
||||||
group1 := VaTestGroup{name: 'users'}
|
group1 := VaTestGroup{
|
||||||
group2 := VaTestGroup{name: 'admins'}
|
name: 'users'
|
||||||
variadic_test('joe', group1, group2)
|
}
|
||||||
|
group2 := VaTestGroup{
|
||||||
|
name: 'admins'
|
||||||
|
}
|
||||||
|
variadic_test('joe',group1,group2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// QTODO
|
||||||
// generic
|
// generic
|
||||||
fn variadic_test_generic<T>(a int, b ...T) T {
|
fn variadic_test_generic<T>(a int, b ...T) T {
|
||||||
b1 := b[0]
|
b1 := b[0]
|
||||||
|
@ -25,6 +31,7 @@ fn variadic_test_generic<T>(a int, b ...T) T {
|
||||||
fn test_fn_variadic_generic() {
|
fn test_fn_variadic_generic() {
|
||||||
assert variadic_test_generic(111, 'hello', 'v') == '111 hello v'
|
assert variadic_test_generic(111, 'hello', 'v') == '111 hello v'
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// forwarding
|
// forwarding
|
||||||
fn variadic_forward_a(a ...string) string {
|
fn variadic_forward_a(a ...string) string {
|
||||||
|
@ -39,7 +46,7 @@ fn variadic_forward_b(a ...string) string {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fn_variadic_forward() {
|
fn test_fn_variadic_forward() {
|
||||||
assert variadic_forward_a('a', 'b', 'c') == 'abc'
|
assert variadic_forward_a('a','b','c') == 'abc'
|
||||||
}
|
}
|
||||||
|
|
||||||
fn variadic_test_no_args(name string, groups ...VaTestGroup) {
|
fn variadic_test_no_args(name string, groups ...VaTestGroup) {
|
||||||
|
@ -50,8 +57,7 @@ fn test_fn_variadic_no_args() {
|
||||||
variadic_test_no_args('marko')
|
variadic_test_no_args('marko')
|
||||||
}
|
}
|
||||||
|
|
||||||
struct VaTestStruct {
|
struct VaTestStruct {}
|
||||||
}
|
|
||||||
|
|
||||||
fn (a VaTestStruct) variadic_method(name string, groups ...VaTestGroup) {
|
fn (a VaTestStruct) variadic_method(name string, groups ...VaTestGroup) {
|
||||||
assert groups.len == 2
|
assert groups.len == 2
|
||||||
|
@ -65,9 +71,13 @@ fn (a VaTestStruct) variadic_method_no_args(name string, groups ...VaTestGroup)
|
||||||
|
|
||||||
fn test_fn_variadic_method() {
|
fn test_fn_variadic_method() {
|
||||||
a := VaTestStruct{}
|
a := VaTestStruct{}
|
||||||
group1 := VaTestGroup{name: 'users'}
|
group1 := VaTestGroup{
|
||||||
group2 := VaTestGroup{name: 'admins'}
|
name: 'users'
|
||||||
a.variadic_method('marko', group1, group2)
|
}
|
||||||
|
group2 := VaTestGroup{
|
||||||
|
name: 'admins'
|
||||||
|
}
|
||||||
|
a.variadic_method('marko',group1,group2)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_fn_variadic_method_no_args() {
|
fn test_fn_variadic_method_no_args() {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
fn test_todo() {}
|
||||||
|
|
||||||
|
/*
|
||||||
fn simple<T>(p T) string {
|
fn simple<T>(p T) string {
|
||||||
tname := nameof(T)
|
tname := nameof(T)
|
||||||
println("Hello generic, I'm an [$tname]")
|
println("Hello generic, I'm an [$tname]")
|
||||||
|
@ -14,3 +16,4 @@ fn test_nameof_on_various_types_in_generic() {
|
||||||
assert simple(FunkyStruct{}) == "FunkyStruct"
|
assert simple(FunkyStruct{}) == "FunkyStruct"
|
||||||
assert simple(test_nameof_on_various_types_in_generic) == "fn ()"
|
assert simple(test_nameof_on_various_types_in_generic) == "fn ()"
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
|
@ -97,7 +97,7 @@ fn test_struct_str() {
|
||||||
u := User{
|
u := User{
|
||||||
'Bob',30}
|
'Bob',30}
|
||||||
println(u) // make sure the struct is printable
|
println(u) // make sure the struct is printable
|
||||||
// assert u.str() == '{name:"Bob", age:30}' // TODO
|
// assert u.str() == '{name:"Bob", age:30}' // QTODO
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_at() {
|
fn test_at() {
|
||||||
|
@ -236,7 +236,6 @@ fn foo_config(c Config) {}
|
||||||
fn foo2(u User) {}
|
fn foo2(u User) {}
|
||||||
|
|
||||||
fn test_config() {
|
fn test_config() {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
foo_config({
|
foo_config({
|
||||||
n: 10
|
n: 10
|
||||||
|
@ -247,4 +246,4 @@ fn test_config() {
|
||||||
name: 'Peter'
|
name: 'Peter'
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue