| 1 |
// Copyright 2018 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package language |
| 6 |
|
| 7 |
import ( |
| 8 |
"strings" |
| 9 |
"testing" |
| 10 |
) |
| 11 |
|
| 12 |
func parseBase(s string) Language { |
| 13 |
if s == "" { |
| 14 |
return 0 |
| 15 |
} |
| 16 |
return MustParseBase(s) |
| 17 |
} |
| 18 |
|
| 19 |
func parseScript(s string) Script { |
| 20 |
if s == "" { |
| 21 |
return 0 |
| 22 |
} |
| 23 |
return MustParseScript(s) |
| 24 |
} |
| 25 |
|
| 26 |
func parseRegion(s string) Region { |
| 27 |
if s == "" { |
| 28 |
return 0 |
| 29 |
} |
| 30 |
return MustParseRegion(s) |
| 31 |
} |
| 32 |
|
| 33 |
func TestBuilder(t *testing.T) { |
| 34 |
partChecks(t, func(t *testing.T, tt *parseTest) (id Tag, skip bool) { |
| 35 |
tag := Make(tt.in) |
| 36 |
b := Builder{} |
| 37 |
b.SetTag(Tag{ |
| 38 |
LangID: parseBase(tt.lang), |
| 39 |
ScriptID: parseScript(tt.script), |
| 40 |
RegionID: parseRegion(tt.region), |
| 41 |
}) |
| 42 |
if tt.variants != "" { |
| 43 |
b.AddVariant(strings.Split(tt.variants, "-")...) |
| 44 |
} |
| 45 |
for _, e := range tag.Extensions() { |
| 46 |
b.AddExt(e) |
| 47 |
} |
| 48 |
got := b.Make() |
| 49 |
if got != tag { |
| 50 |
t.Errorf("%s: got %v; want %v", tt.in, got, tag) |
| 51 |
} |
| 52 |
return got, false |
| 53 |
}) |
| 54 |
} |
| 55 |
|
| 56 |
func TestSetTag(t *testing.T) { |
| 57 |
partChecks(t, func(t *testing.T, tt *parseTest) (id Tag, skip bool) { |
| 58 |
tag := Make(tt.in) |
| 59 |
b := Builder{} |
| 60 |
b.SetTag(tag) |
| 61 |
got := b.Make() |
| 62 |
if got != tag { |
| 63 |
t.Errorf("%s: got %v; want %v", tt.in, got, tag) |
| 64 |
} |
| 65 |
return got, false |
| 66 |
}) |
| 67 |
} |