-
Notifications
You must be signed in to change notification settings - Fork 11
/
symbol_test.go
100 lines (92 loc) · 3.18 KB
/
symbol_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
package scryfall
import (
"context"
"fmt"
"net/http"
"reflect"
"testing"
)
func TestListCardSymbols(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"object": "list", "has_more": false, "data": [{"object": "card_symbol", "symbol": "{T}", "loose_variant": null, "english": "tap this permanent", "transposable": false, "represents_mana": false, "appears_in_mana_costs": false, "cmc": 0, "funny": false, "colors": []}, {"object": "card_symbol", "symbol": "{Q}", "loose_variant": null, "english": "untap this permanent", "transposable": false, "represents_mana": false, "appears_in_mana_costs": false, "cmc": 0, "funny": false, "colors": []}, {"object": "card_symbol", "symbol": "{W/U}", "loose_variant": null, "english": "one white or blue mana", "transposable": true, "represents_mana": true, "appears_in_mana_costs": true, "cmc": 1, "funny": false, "colors": ["W", "U"]}]}`)
})
client, ts, err := setupTestServer("/symbology", handler)
if err != nil {
t.Fatalf("Error setting up test server: %v", err)
}
defer ts.Close()
ctx := context.Background()
cardSymbols, err := client.ListCardSymbols(ctx)
if err != nil {
t.Fatalf("Error listing card symbols: %v", err)
}
want := []CardSymbol{
{
Symbol: "{T}",
LooseVariant: nil,
English: "tap this permanent",
Transposable: false,
RepresentsMana: false,
CMC: 0,
AppearsInManaCosts: false,
Funny: false,
Colors: []Color{},
},
{
Symbol: "{Q}",
LooseVariant: nil,
English: "untap this permanent",
Transposable: false,
RepresentsMana: false,
CMC: 0,
AppearsInManaCosts: false,
Funny: false,
Colors: []Color{},
},
{
Symbol: "{W/U}",
LooseVariant: nil,
English: "one white or blue mana",
Transposable: true,
RepresentsMana: true,
CMC: 1,
AppearsInManaCosts: true,
Funny: false,
Colors: []Color{ColorWhite, ColorBlue},
},
}
if !reflect.DeepEqual(cardSymbols, want) {
t.Errorf("got: %#v want: %#v", cardSymbols, want)
}
}
func TestParseManaCost(t *testing.T) {
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
cost := r.URL.Query().Get("cost")
if cost != "RUx" {
w.WriteHeader(http.StatusBadRequest)
return
}
fmt.Fprintln(w, `{"object": "mana_cost", "cost": "{X}{U}{R}", "colors": ["U", "R"], "cmc": 2, "colorless": false, "monocolored": false, "multicolored": true}`)
})
client, ts, err := setupTestServer("/symbology/parse-mana", handler)
if err != nil {
t.Fatalf("Error setting up test server: %v", err)
}
defer ts.Close()
ctx := context.Background()
manaCost, err := client.ParseManaCost(ctx, "RUx")
if err != nil {
t.Fatalf("Error parsing mana cost: %v", err)
}
want := ManaCost{
Cost: "{X}{U}{R}",
CMC: 2,
Colorless: false,
Monocolored: false,
Multicolored: true,
Colors: []Color{ColorBlue, ColorRed},
}
if !reflect.DeepEqual(manaCost, want) {
t.Errorf("got: %#v want: %#v", manaCost, want)
}
}