...
1 package currency
2
3 import (
4 "flag"
5 "strings"
6 "testing"
7 "time"
8
9 "golang.org/x/text/internal/gen"
10 "golang.org/x/text/internal/testtext"
11 "golang.org/x/text/language"
12 "golang.org/x/text/message"
13 "golang.org/x/text/unicode/cldr"
14 )
15
16 var draft = flag.String("draft",
17 "contributed",
18 `Minimal draft requirements (approved, contributed, provisional, unconfirmed).`)
19
20 func TestTables(t *testing.T) {
21 testtext.SkipIfNotLong(t)
22
23
24 r := gen.OpenCLDRCoreZip()
25 defer r.Close()
26
27 d := &cldr.Decoder{}
28 d.SetDirFilter("supplemental", "main")
29 d.SetSectionFilter("numbers")
30 data, err := d.DecodeZip(r)
31 if err != nil {
32 t.Fatalf("DecodeZip: %v", err)
33 }
34
35 dr, err := cldr.ParseDraft(*draft)
36 if err != nil {
37 t.Fatalf("filter: %v", err)
38 }
39
40 for _, lang := range data.Locales() {
41 p := message.NewPrinter(language.MustParse(lang))
42
43 ldml := data.RawLDML(lang)
44 if ldml.Numbers == nil || ldml.Numbers.Currencies == nil {
45 continue
46 }
47 for _, c := range ldml.Numbers.Currencies.Currency {
48 syms := cldr.MakeSlice(&c.Symbol)
49 syms.SelectDraft(dr)
50
51 for _, sym := range c.Symbol {
52 cur, err := ParseISO(c.Type)
53 if err != nil {
54 continue
55 }
56 formatter := Symbol
57 switch sym.Alt {
58 case "":
59 case "narrow":
60 formatter = NarrowSymbol
61 default:
62 continue
63 }
64 want := sym.Data()
65 if got := p.Sprint(formatter(cur)); got != want {
66 t.Errorf("%s:%sSymbol(%s) = %s; want %s", lang, strings.Title(sym.Alt), c.Type, got, want)
67 }
68 }
69 }
70 }
71
72 for _, reg := range data.Supplemental().CurrencyData.Region {
73 i := 0
74 for ; regionData[i].Region().String() != reg.Iso3166; i++ {
75 }
76 it := Query(Historical, NonTender, Region(language.MustParseRegion(reg.Iso3166)))
77 for _, cur := range reg.Currency {
78 from, _ := time.Parse("2006-01-02", cur.From)
79 to, _ := time.Parse("2006-01-02", cur.To)
80
81 it.Next()
82 for j, r := range []QueryIter{&iter{regionInfo: ®ionData[i]}, it} {
83 if got, _ := r.From(); from != got {
84 t.Errorf("%d:%s:%s:from: got %v; want %v", j, reg.Iso3166, cur.Iso4217, got, from)
85 }
86 if got, _ := r.To(); to != got {
87 t.Errorf("%d:%s:%s:to: got %v; want %v", j, reg.Iso3166, cur.Iso4217, got, to)
88 }
89 }
90 i++
91 }
92 }
93 }
94
View as plain text