Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

68 linhas
1.1 KiB

  1. // Copyright 2015 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 tag
  5. import (
  6. "strings"
  7. "testing"
  8. )
  9. var strdata = []string{
  10. "aa ",
  11. "aaa ",
  12. "aaaa",
  13. "aaab",
  14. "aab ",
  15. "ab ",
  16. "ba ",
  17. "xxxx",
  18. "\xff\xff\xff\xff",
  19. }
  20. var testCases = map[string]int{
  21. "a": 0,
  22. "aa": 0,
  23. "aaa": 1,
  24. "aa ": 0,
  25. "aaaa": 2,
  26. "aaab": 3,
  27. "b": 6,
  28. "ba": 6,
  29. " ": -1,
  30. "aaax": -1,
  31. "bbbb": -1,
  32. "zzzz": -1,
  33. }
  34. func TestIndex(t *testing.T) {
  35. index := Index(strings.Join(strdata, ""))
  36. for k, v := range testCases {
  37. if i := index.Index([]byte(k)); i != v {
  38. t.Errorf("%s: got %d; want %d", k, i, v)
  39. }
  40. }
  41. }
  42. func TestFixCase(t *testing.T) {
  43. tests := []string{
  44. "aaaa", "AbCD", "abcd",
  45. "Zzzz", "AbCD", "Abcd",
  46. "Zzzz", "AbC", "",
  47. "XXX", "ab ", "",
  48. "XXX", "usd", "USD",
  49. "cmn", "AB ", "",
  50. "gsw", "CMN", "cmn",
  51. }
  52. for tc := tests; len(tc) > 0; tc = tc[3:] {
  53. b := []byte(tc[1])
  54. if !FixCase(tc[0], b) {
  55. b = nil
  56. }
  57. if string(b) != tc[2] {
  58. t.Errorf("FixCase(%q, %q) = %q; want %q", tc[0], tc[1], b, tc[2])
  59. }
  60. }
  61. }