File tree 1 file changed +79
-0
lines changed
1 file changed +79
-0
lines changed Original file line number Diff line number Diff line change
1
+ package ast
2
+
3
+ import "testing"
4
+
5
+ func TestPrefix (t * testing.T ) {
6
+ tt := []struct {
7
+ name string
8
+ input string
9
+ emptyNewline bool
10
+
11
+ want string
12
+ }{
13
+ {
14
+ name : "empty string" ,
15
+ },
16
+ {
17
+ name : `empty string with empty newline` ,
18
+ emptyNewline : true ,
19
+
20
+ want : "\n " ,
21
+ },
22
+ {
23
+ name : "simple attribute" ,
24
+ input : `value => 3.1415` ,
25
+
26
+ want : `
27
+ value => 3.1415
28
+ ` ,
29
+ },
30
+ {
31
+ name : "simple attribute with newline" ,
32
+ input : `value => 3.1415
33
+ ` ,
34
+
35
+ want : `
36
+ value => 3.1415
37
+ ` ,
38
+ },
39
+ {
40
+ name : "simple attribute with comment" ,
41
+ input : `// comment
42
+ value => 3.1415` ,
43
+
44
+ want : `
45
+ // comment
46
+ value => 3.1415
47
+ ` ,
48
+ },
49
+ {
50
+ name : "block" ,
51
+ input : `add_field {
52
+ // comment
53
+ value => 3.1415
54
+ }
55
+
56
+ add_tag => [ "foobar" ]
57
+ ` ,
58
+
59
+ want : `
60
+ add_field {
61
+ // comment
62
+ value => 3.1415
63
+ }
64
+
65
+ add_tag => [ "foobar" ]
66
+ ` ,
67
+ },
68
+ }
69
+
70
+ for _ , tc := range tt {
71
+ t .Run (tc .name , func (t * testing.T ) {
72
+ got := prefix (tc .input , tc .emptyNewline )
73
+
74
+ if tc .want != got {
75
+ t .Errorf ("want %q, got %q" , tc .want , got )
76
+ }
77
+ })
78
+ }
79
+ }
You can’t perform that action at this time.
0 commit comments