-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSpec.String.go
133 lines (118 loc) · 2.89 KB
/
Spec.String.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package spec
import ()
func (spec *Spec) String() (s string) {
s += SPEC_HEADER + "\n"
s += SECTION_TITLE
s += spec.Title + "\n\n"
s += SECTION_SHORT
s += spec.Short + "\n\n"
s += SECTION_LONG
s += spec.Long + "\n\n"
for _, syntax := range spec.Syntaxes {
s += SECTION_SYNTAX
s += syntax.Class + "\n"
s += syntax.Properties + "\n\n"
}
for _, arg := range spec.Arguments {
if len(arg.Types) == 1 {
// Use dense format when there is only 1 argument
s += SECTION_ARGUMENT
s += arg.Name + " " + arg.Types[0].Type + "\n"
if arg.Description != "" {
s += arg.Description + "\n"
}
s += "\n"
} else {
// Use long format when there are multiple arguments
s += SECTION_ARGUMENT_NAME
s += arg.Name + "\n"
if arg.Description != "" {
s += arg.Description + "\n"
}
s += "\n"
for _, typ := range arg.Types {
s += SECTION_ARGUMENT_TYPE
s += typ.Type + "\n"
if typ.Description != "" {
s += typ.Description + "\n"
}
s += "\n"
}
}
}
for _, example := range spec.Examples {
s += example.String() + "\n\n"
}
for _, exampleThatFails := range spec.ExamplesThatFail {
s += exampleThatFails.String() + "\n\n"
}
for _, exampleLib := range spec.ExampleLibraries {
s += exampleLib.String() + "\n\n"
}
for _, exampleLibThatFails := range spec.ExampleLibrariesThatFail {
s += exampleLibThatFails.String() + "\n\n"
}
return s
}
func (example Example) String() (s string) {
s += SECTION_EXAMPLE
s += SEPARATOR_START
s += example.Description + "\n"
s += SEPARATOR_CODE
s += example.Code + "\n"
s += SEPARATOR
s += example.Exp + "\n"
s += SEPARATOR_END
return s
}
func (exampleThatFails ExampleThatFails) String() (s string) {
s += SECTION_EXAMPLE_THAT_FAILS
s += SEPARATOR_START
s += exampleThatFails.Description + "\n"
s += SEPARATOR_CODE
s += exampleThatFails.Code + "\n"
s += SEPARATOR
s += exampleThatFails.ExpErr + "\n"
s += SEPARATOR_END
return s
}
func (exampleLib ExampleLibrary) String() (s string) {
s += SECTION_EXAMPLE_LIBRARY
s += SEPARATOR_START
s += exampleLib.Description + "\n"
s += SEPARATOR_CODE
for _, lib := range exampleLib.Libraries {
s += "[" + lib.Filename + "]\n"
s += lib.Source + "\n"
s += SEPARATOR
}
if exampleLib.GlobalCode != "" {
s += exampleLib.GlobalCode + "\n"
s += SEPARATOR
}
s += exampleLib.Code + "\n"
s += SEPARATOR
s += exampleLib.Exp + "\n"
s += SEPARATOR_END
return s
}
func (exampleLib ExampleLibraryThatFails) String() (s string) {
s += SECTION_EXAMPLE_LIBRARY_THAT_FAILS
s += SEPARATOR_START
s += exampleLib.Description + "\n"
s += SEPARATOR_CODE
for _, lib := range exampleLib.Libraries {
s += "[" + lib.Filename + "]\n"
s += lib.Source + "\n"
s += SEPARATOR
}
if exampleLib.GlobalCode != "" {
s += exampleLib.GlobalCode + "\n"
s += SEPARATOR
}
s += exampleLib.Code + "\n"
s += SEPARATOR
s += exampleLib.ExpErr + "\n"
s += SEPARATOR_END
return s
}