fmt: split tests

pull/3969/head
Alexey 2020-03-08 17:57:16 +03:00 committed by GitHub
parent 5f08253f36
commit 83b6292105
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
26 changed files with 348 additions and 419 deletions

View File

@ -1,4 +1,3 @@
[inline]
fn fn_contains_index_expr() {
arr := [1, 2, 3, 4, 5]
a := 1 in arr[0..]

View File

@ -1,6 +1,6 @@
[inline] fn fn_contains_index_expr() {
fn fn_contains_index_expr() {
arr := [1, 2, 3, 4, 5]
a := 1 in arr[ 0.. ]
b := 1 in arr[ ..2 ]

View File

@ -0,0 +1,11 @@
fn unsafe_fn() {
unsafe {
malloc(2)
}
}
fn fn_with_defer() {
defer {
voidfn()
}
}

View File

@ -0,0 +1,7 @@
fn unsafe_fn() {
unsafe { malloc(2) }
}
fn fn_with_defer() {
defer { voidfn() }
}

View File

@ -0,0 +1,7 @@
fn test_as() {
a := sum_expr() as Bar
}
fn test_cast() {
f := f32(0)
}

View File

@ -0,0 +1,7 @@
fn test_as() {
a := sum_expr() as Bar
}
fn test_cast() {
f := f32(0)
}

View File

@ -0,0 +1,12 @@
fn fn_with_if_else() {
if true {
a = 10
a++
} else {
println('false')
}
}
fn fn_with_if_else_oneline() {
x := if true { 1 } else { 2 }
}

View File

@ -0,0 +1,10 @@
fn fn_with_if_else() {
if true {
a = 10
a++
} else { println('false') }
}
fn fn_with_if_else_oneline() {
x := if true { 1 } else { 2 }
}

View File

@ -0,0 +1,7 @@
const (
pi = 3.14
)
pub const (
i_am_pub_const = true
)

View File

@ -0,0 +1,7 @@
const (
pi=3.14
)
pub const (
i_am_pub_const=true
)

View File

@ -0,0 +1,9 @@
pub enum PubEnum {
foo
bar
}
enum PrivateEnum {
foo
bar
}

View File

@ -0,0 +1,5 @@
pub enum PubEnum{
foo
bar
}
enum PrivateEnum { foo bar }

View File

@ -0,0 +1,62 @@
fn fn_variadic(arg int, args ...string) {
println('Do nothing')
}
fn fn_with_assign_stmts() {
a, b := fn_with_multi_return()
}
fn fn_with_multi_return() (int, string) {
return 0, 'test'
}
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, 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() {
println('')
}
fn fn_with_optional() ?int {
if true {
return error('true')
}
return 30
}
fn (f Foo) fn_with_optional() ?int {
if true {
return error('true')
}
return 40
}
fn fn_with_ref_return() &Foo {
return &Foo{}
}
[inline]
fn fn_with_flag() {
println('flag')
}

View File

@ -0,0 +1,57 @@
fn fn_variadic(arg int, args... string) {
println('Do nothing')
}
fn fn_with_assign_stmts() {
a,b := fn_with_multi_return()
}
fn fn_with_multi_return() (int,string) {
return 0,'test'
}
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() {
println('')
}
fn fn_with_optional() ?int {
if true { return error('true') }
return 30
}
fn (f Foo) fn_with_optional() ?int {
if true { return error('true') }
return 40
}
fn fn_with_ref_return() &Foo {
return &Foo{}
}
[inline] fn fn_with_flag() {
println('flag')
}

View File

@ -0,0 +1,4 @@
fn test_goto() {
goto label
label:
}

View File

@ -0,0 +1,4 @@
fn test_goto() {
goto label
label:
}

View File

@ -0,0 +1,9 @@
const (
reserved_types = {
'i8': true
'i16': true
'int': true
'i64': true
'i128': true
}
)

View File

@ -0,0 +1,9 @@
const (
reserved_types = {
'i8': true
'i16': true
'int': true
'i64': true
'i128': true
}
)

View File

@ -0,0 +1,27 @@
fn match_expr() {
a := 10
match a {
10 {
println('10')
}
20 {
println('20')
}
else {}
}
}
fn match_expr_assignment() {
a := 20
b := match a {
10 {
10
}
5 {
5
}
else {
2
}
}
}

View File

@ -0,0 +1,21 @@
fn match_expr() {
a := 10
match a {
10 {
println('10')
}
20 {
println('20')
}
else {}
}
}
fn match_expr_assignment() {
a := 20
b := match a {
10 { 10 }
5 { 5 }
else { 2 }
}
}

View File

@ -0,0 +1,13 @@
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
}

View File

@ -0,0 +1,9 @@
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
}

View File

@ -1,210 +0,0 @@
fn main() {
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
very_long_field bool
mut:
age int
}
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
}
}
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, 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 {
voidfn()
}
}
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 fn_with_optional() ?int {
if true {
return error('true')
}
return 30
}
fn (f Foo) method_with_or() int {
f.fn_with_optional() or {
return 10
}
return 20
}
fn (f Foo) fn_with_optional() ?int {
if true {
return error('true')
}
return 40
}
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
}
}

View File

@ -1,207 +0,0 @@
fn main()
{
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
very_long_field bool
mut:
age int
}
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
}
}
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 { voidfn()
}
}
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 fn_with_optional() ?int {
if true {
return error('true')
}
return 30
}
fn (f Foo) method_with_or() int {
f.fn_with_optional() or {
return 10
}
return 20
}
fn (f Foo) fn_with_optional() ?int {
if true {
return error('true')
}
return 40
}
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 }
}

View File

@ -0,0 +1,24 @@
struct User {
name string
very_long_field bool
age int
}
struct Foo {
field1 int
field2 string
pub:
public_field1 int
public_field2 f64
mut:
mut_field string
pub mut:
pub_mut_field string
}
fn new_user() User {
return User{
name: 'Serious Sam'
age: 19
}
}

View File

@ -0,0 +1,26 @@
struct User {
name string
very_long_field bool
age int
}
struct Foo {
field1 int
field2 string
pub:
public_field1 int
public_field2 f64
mut:
mut_field string
pub mut:
pub_mut_field string
}
fn new_user()
User
{
return User{
name: 'Serious Sam'
age: 19
}
}