-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroe_test.go
57 lines (52 loc) · 1.05 KB
/
roe_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
package goroe
import (
"fmt"
"strings"
"testing"
)
func helloWorld() ResultOrError[string] {
return Result("hello world")
}
func helloPlanets(planets ...string) []ResultOrError[string] {
returns := make([]ResultOrError[string], len(planets))
for index, planet := range planets {
switch strings.ToUpper(planet) {
case "MERCURY":
fallthrough
case "VENUS":
fallthrough
case "EARTH":
fallthrough
case "MARS":
fallthrough
case "JUPITER":
fallthrough
case "SATURN":
fallthrough
case "NEPTUNE":
fallthrough
case "PLUTO":
returns[index] = Result(fmt.Sprintf("Hello %s", planet))
default:
returns[index] = Errorf[string]("Not a planet")
}
}
return returns
}
func TestHelloWorld(t *testing.T) {
if result, err := helloWorld().Unwrap(); err != nil {
panic(err)
} else {
println(result)
}
}
func TestHelloPlanets(t *testing.T) {
results := helloPlanets("Earth", "Moon")
for _, roe := range results {
if r, err := roe.Unwrap(); err != nil {
println("Error: " + err.Error())
} else {
println(r)
}
}
}