1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/v/fmt/tests/simple_input.vv
2020-03-06 22:12:15 +01:00

205 lines
2.2 KiB
V

fn hello()
{
mut a:= 3 + 3
a = 10
a++
-23
goto lbl
b:= 42
println( 'hello' )
abc()
lbl:
if true {
a = 10
a++
} else {
println('false')
}
}
const (
pi=3.14
)
pub const (
i_am_pub_const=true
)
pub enum PubEnum{
foo bar
}
enum PrivateEnum{
foo bar
}
struct User {
name string
age int
very_long_field bool
}
fn abc() int {
mut u := User{name:'Bob'}
u.age = 20
nums := [1,2,3]
number := nums[0]
return 0
}
fn new_user()
User
{
return User{
name: 'Serious Sam'
age: 19
}
}
[inline]
fn fn_contains_index_expr() {
a := 1 in arr[0..]
b := 1 in arr[..2]
c := 1 in arr[1..3]
d := arr[2]
e := arr[2..]
f := arr[..2]
g := arr[1..3]
}
fn voidfn(){
println('this is a function that does not return anything')
}
fn fn_with_1_arg(arg int) int {
return 0
}
fn fn_with_2a_args(arg1, arg2 int) int {
return 0
}
fn fn_with_2_args_to_be_shorten(arg1 int, arg2 int) int {
return 0
}
fn fn_with_2b_args(arg1 string, arg2 int) int {
return 0
}
fn fn_with_3_args(arg1 string, arg2 int, arg3 User) int {
return 0
}
fn (this User) fn_with_receiver() {
x := if true {1} else {2}
println('')
}
fn get_user() ? User {
return none
}
fn get_user_ptr() & User {
return &User{}
}
fn fn_with_defer() {
defer { close()
}
}
struct Foo {
field1 int
field2 string
pub:
public_field1 int
public_field2 f64
mut:
mut_field string
pub mut:
pub_mut_field string
}
struct Bar {
val int
}
type FooBar = Foo | Bar
const (
reserved_types = {
'i8': true
'i16': true
'int': true
'i64': true
'i128': true
}
)
fn fn_with_assign_stmts() {
a,b := fn_with_multi_return()
}
fn fn_with_multi_return() (int,string) {
return 0,'test'
}
fn unsafe_fn() {
unsafe { malloc(2) }
}
fn fn_with_or() int {
fn_with_optional() or {
return 10
}
return 20
}
fn (f Foo) method_with_or() int {
f.fn_with_optional() or {
return 10
}
return 20
}
fn fn_with_match_expr() {
a := 10
b := match a {
10 {
10
}
5 {
5
}
else {
2
}
}
match b {
10 {
println('10')
}
20 {
println('20')
}
else {}
}
}
fn fn_variadic(arg int, args... string) {
println('Do nothing')
}
fn test_as() {
a := sum_expr() as Bar
}
fn sum_expr() FooBar {
return Bar{ val: 5 }
}