You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

68 lines
1.3 KiB

  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. package language
  5. import (
  6. "strings"
  7. "testing"
  8. )
  9. func parseBase(s string) Language {
  10. if s == "" {
  11. return 0
  12. }
  13. return MustParseBase(s)
  14. }
  15. func parseScript(s string) Script {
  16. if s == "" {
  17. return 0
  18. }
  19. return MustParseScript(s)
  20. }
  21. func parseRegion(s string) Region {
  22. if s == "" {
  23. return 0
  24. }
  25. return MustParseRegion(s)
  26. }
  27. func TestBuilder(t *testing.T) {
  28. partChecks(t, func(t *testing.T, tt *parseTest) (id Tag, skip bool) {
  29. tag := Make(tt.in)
  30. b := Builder{}
  31. b.SetTag(Tag{
  32. LangID: parseBase(tt.lang),
  33. ScriptID: parseScript(tt.script),
  34. RegionID: parseRegion(tt.region),
  35. })
  36. if tt.variants != "" {
  37. b.AddVariant(strings.Split(tt.variants, "-")...)
  38. }
  39. for _, e := range tag.Extensions() {
  40. b.AddExt(e)
  41. }
  42. got := b.Make()
  43. if got != tag {
  44. t.Errorf("%s: got %v; want %v", tt.in, got, tag)
  45. }
  46. return got, false
  47. })
  48. }
  49. func TestSetTag(t *testing.T) {
  50. partChecks(t, func(t *testing.T, tt *parseTest) (id Tag, skip bool) {
  51. tag := Make(tt.in)
  52. b := Builder{}
  53. b.SetTag(tag)
  54. got := b.Make()
  55. if got != tag {
  56. t.Errorf("%s: got %v; want %v", tt.in, got, tag)
  57. }
  58. return got, false
  59. })
  60. }