MCPcopy Create free account
hub / github.com/WICG/webpackage / TestVariants

Function TestVariants

go/bundle/encoder_test.go:21–57  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

19}
20
21func TestVariants(t *testing.T) {
22 variants, err := parseVariants("Accept-Encoding;gzip;br, Accept-Language;en;fr;ja")
23 if err != nil {
24 t.Errorf("parseListOfStringLists unexpectedly failed: %v", err)
25 }
26 if nk, err := variants.numberOfPossibleKeys(); nk != 6 || err != nil {
27 t.Errorf("numberOfPossibleKeys: got: (%v, %v) want: (%v, %v)", nk, err, 6, nil)
28 }
29
30 cases := []struct {
31 index int
32 variantKey []string
33 }{
34 {0, []string{"gzip", "en"}},
35 {1, []string{"gzip", "fr"}},
36 {2, []string{"gzip", "ja"}},
37 {3, []string{"br", "en"}},
38 {4, []string{"br", "fr"}},
39 {5, []string{"br", "ja"}},
40 {-1, []string{"gzip", "es"}},
41 {-1, []string{}},
42 {-1, []string{"gzip"}},
43 {-1, []string{"gzip", "en", "foo"}},
44 }
45 for _, c := range cases {
46 if i := variants.indexInPossibleKeys(c.variantKey); i != c.index {
47 t.Errorf("indexInPossibleKeys: got: %v want: %v", i, c.index)
48 }
49
50 if c.index != -1 {
51 key := variants.possibleKeyAt(c.index)
52 if !reflect.DeepEqual(key, c.variantKey) {
53 t.Errorf("possibleKeyAt(%d): got: %v\nwant: %v", c.index, key, c.variantKey)
54 }
55 }
56 }
57}
58
59func TestIndexSectionWithVariants(t *testing.T) {
60 url := urlMustParse("https://example.com/")

Callers

nothing calls this directly

Calls 4

parseVariantsFunction · 0.85
numberOfPossibleKeysMethod · 0.80
indexInPossibleKeysMethod · 0.80
possibleKeyAtMethod · 0.80

Tested by

no test coverage detected