-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_test.go
121 lines (108 loc) · 3.75 KB
/
example_test.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
package cask
import "fmt"
func Example_one() {
// for this example we will load the cask from our testdata directory
content := string(getTestdata("example-one.rb"))
// example
c := NewCask(content)
err := c.Parse()
if err == nil {
fmt.Println("Token:", c.Token)
for i, v := range c.Variants {
fmt.Printf("Variant #%d:\n", i+1)
fmt.Printf("%10s: %s\n", "version", v.GetVersion())
fmt.Printf("%10s: %s\n", "sha256", v.GetSHA256())
fmt.Printf("%10s: %s\n", "url", v.GetURL())
fmt.Printf("%10s: %s\n", "appcast", v.GetAppcast().URL)
fmt.Printf("%10s: %v\n", "names", v.GetNames())
fmt.Printf("%10s: %s\n", "homepage", v.GetHomepage())
// artifacts
fmt.Printf("%10s: ", "artifacts")
if len(v.GetArtifacts()) > 0 {
for i, a := range v.GetArtifacts() {
if i == 0 {
fmt.Printf("%s\n", a.String())
} else {
fmt.Printf("%12s%s\n", "", a.String())
}
}
} else {
fmt.Printf("%v\n", v.GetArtifacts())
}
// macOS
fmt.Printf("%10s: %s [minimum]\n", "macOS", v.MinimumSupportedMacOS)
fmt.Printf("%12s%s [maximum]\n", "", v.MaximumSupportedMacOS)
}
}
// Output:
// Token: example-one
// Variant #1:
// version: 2.0.0
// sha256: f22abd6773ab232869321ad4b1e47ac0c908febf4f3a2bd10c8066140f741261
// url: https://example.com/app_2.0.0.dmg
// appcast: https://example.com/sparkle/2/appcast.xml
// names: [Example Example One]
// homepage: https://example.com/
// artifacts: app, Example 2.0.app => Example.app
// app, Example 2.0 Uninstaller.app
// binary, #{appdir}/Example 2.0.app/Contents/MacOS/example-one => example
// macOS: macOS High Sierra (10.13) [minimum]
// macOS High Sierra (10.13) [maximum]
}
func Example_two() {
// for this example we will load the cask from our testdata directory
content := string(getTestdata("example-two.rb"))
// example
c := NewCask(content)
err := c.Parse()
if err == nil {
fmt.Println("Token:", c.Token)
for i, v := range c.Variants {
fmt.Printf("Variant #%d:\n", i+1)
fmt.Printf("%10s: %s\n", "version", v.GetVersion())
fmt.Printf("%10s: %s\n", "sha256", v.GetSHA256())
fmt.Printf("%10s: %s\n", "url", v.GetURL())
fmt.Printf("%10s: %s\n", "appcast", v.GetAppcast().URL)
fmt.Printf("%10s: %v\n", "names", v.GetNames())
fmt.Printf("%10s: %s\n", "homepage", v.GetHomepage())
// artifacts
fmt.Printf("%10s: ", "artifacts")
if len(v.GetArtifacts()) > 0 {
for i, a := range v.GetArtifacts() {
if i == 0 {
fmt.Printf("%s\n", a.String())
} else {
fmt.Printf("%12s%s\n", "", a.String())
}
}
} else {
fmt.Printf("%v\n", v.GetArtifacts())
}
// macOS
fmt.Printf("%10s: %s [minimum]\n", "macOS", v.MinimumSupportedMacOS)
fmt.Printf("%12s%s [maximum]\n", "", v.MaximumSupportedMacOS)
}
}
// Output:
// Token: example-two
// Variant #1:
// version: 1.5.0
// sha256: 1f4dc096d58f7d21e3875671aee6f29b120ab84218fa47db2cb53bc9eb5b4dac
// url: https://example.com/app_1.5.0.pkg
// appcast: https://example.com/sparkle/1/el_capitan.xml
// names: [Example Example Two]
// homepage: https://example.com/
// artifacts: pkg, app_1.5.0.pkg, allow_untrusted: true
// macOS: Mac OS X Tiger (10.4) [minimum]
// OS X El Capitan (10.11) [maximum]
// Variant #2:
// version: 2.0.0
// sha256: f22abd6773ab232869321ad4b1e47ac0c908febf4f3a2bd10c8066140f741261
// url: https://example.com/app_2.0.0.pkg
// appcast: https://example.com/sparkle/2/appcast.xml
// names: [Example Example Two]
// homepage: https://example.com/
// artifacts: pkg, app_2.0.0.pkg, allow_untrusted: true
// macOS: macOS High Sierra (10.13) [minimum]
// macOS High Sierra (10.13) [maximum]
}