v2 / vlib / v / fmt / tests / empty_lines_keep.vv
99 lines · 82 sloc · 1.5 KB · f09826e928f9612bab9299faefff7cf34a503362
Raw
1// Keep empty lines between types
2type Expr = IfExpr | IntegerLiteral
3
4type Node2 = Expr | string
5type MyInt = int
6
7// Keep empty lines in const blocks
8const _ = SomeStruct{
9 val: 'Multiline field exprs should cause no problems'
10}
11const _ = 1
12
13const _ = 'Keep this empty line before'
14// Comment before a field
15const _ = 2
16
17// The empty line above should stay too
18const _ = 3
19
20// This comment doesn't really belong anywhere
21
22const _ = 'A multiline string with a StringInterLiteral...
23 ${foo}
24 ...and the ending brace on a newline had a wrong pos.last_line.
25 '
26const _ = 4
27
28fn keep_single_empty_line() {
29 println('a')
30 println('b')
31
32 println('c')
33
34 dump('d')
35
36 d := 0
37
38 if true {
39 println('e')
40 }
41
42 dump('f')
43 f := 0
44 arr << MyStruct{}
45
46 arr2 := [1, 2]
47}
48
49fn prevent_empty_line_after_multi_line_statements() {
50 // line1
51 /*
52 block1
53 */
54 /*
55 block2
56 */
57 if test {
58 println('a')
59 }
60 println('b')
61 for test {
62 println('c')
63 }
64 c := fn (s string) {
65 println('s')
66 }
67}
68
69fn between_orm_blocks() {
70 sql db {
71 insert upper_1 into Upper
72 }
73
74 upper_s := sql db {
75 select from Upper where id == 1
76 }
77}
78
79fn no_empty_lines() {
80 _ := $embed_file('testy.v')
81 mut files := map[string][]FileData{}
82 code := 'foo
83bar'
84 params[0] = IfExpr{
85 ...params[0]
86 typ: params[0].typ.set_nr_muls(1)
87 }
88 env_value = environ()[env_lit] or {
89 return error('the environment variable "${env_lit}" does not exist.')
90 }
91 assert '${mr_one_two()}' == "(One{
92 value: 'one'
93}, Two{
94 value: 'two'
95})"
96 r := m[key]!
97 compile_time_env := $env('ENV_VAR')
98 func()
99}
100