From 959cc2ea0300f3229e3dabf5358df894cdb82480 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 27 Jun 2019 14:28:12 +0200 Subject: [PATCH] some more tests --- compiler/fn.v | 1 - json/json_test.v | 21 +++++++++++++++++++++ tests/fn_test.v | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 json/json_test.v create mode 100644 tests/fn_test.v diff --git a/compiler/fn.v b/compiler/fn.v index 03be7b7f67..5381dac554 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -493,7 +493,6 @@ fn (p mut Parser) async_fn_call(f Fn, method_ph int, receiver_var, receiver_type } fn (p mut Parser) fn_call(f Fn, method_ph int, receiver_var, receiver_type string) { - //if !f.is_public && !f.is_c && f.pkg != p.pkg && f.pkg != 'builtin' { if !f.is_public && !f.is_c && !p.is_test && f.pkg != p.pkg { p.error('function `$f.name` is private') } diff --git a/json/json_test.v b/json/json_test.v new file mode 100644 index 0000000000..18fc7d3b22 --- /dev/null +++ b/json/json_test.v @@ -0,0 +1,21 @@ +import json + +struct User { + age int + nums []int +} + +fn test_parse_user() { + s := '{"age": 10, "nums": [1,2,3]}' + u := json.decode(User, s) or { + exit(1) + return + } + assert u.age == 10 + assert u.nums.len == 3 + assert u.nums[0] == 1 + assert u.nums[1] == 2 + assert u.nums[2] == 3 +} + + diff --git a/tests/fn_test.v b/tests/fn_test.v new file mode 100644 index 0000000000..fdf540efcb --- /dev/null +++ b/tests/fn_test.v @@ -0,0 +1,43 @@ +type myfn fn (int) string + +type myfn2 fn (a int, b int) int + +type myfn3 fn (int, int) + +fn myfn4(string) + +fn foobar() + +fn slopediv(num u32, den u32) int + +type f1 fn () + +type f2 fn (voidptr) + +type f3 fn (voidptr, voidptr) + +type f4 fn (voidptr) int + +type f5 fn (int, int) int + +type f6 fn (int, int) + +fn C.atoi(byteptr) int + +fn foo() { +} + +type actionf_v fn () + +type actionf_p1 fn (voidptr) + +type actionf_p2 fn (voidptr, voidptr) + +fn myprint(s string, ..) { + println('my print') +} + +fn test_fns() { + // no asserts for now, just test function declarations above +} +