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. package readline
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. type twidth struct {
  7. r []rune
  8. length int
  9. }
  10. func TestRuneWidth(t *testing.T) {
  11. rs := []twidth{
  12. {[]rune("☭"), 1},
  13. {[]rune("a"), 1},
  14. {[]rune("你"), 2},
  15. {runes.ColorFilter([]rune("☭\033[13;1m你")), 3},
  16. }
  17. for _, r := range rs {
  18. if w := runes.WidthAll(r.r); w != r.length {
  19. t.Fatal("result not expect", r.r, r.length, w)
  20. }
  21. }
  22. }
  23. type tagg struct {
  24. r [][]rune
  25. e [][]rune
  26. length int
  27. }
  28. func TestAggRunes(t *testing.T) {
  29. rs := []tagg{
  30. {
  31. [][]rune{[]rune("ab"), []rune("a"), []rune("abc")},
  32. [][]rune{[]rune("b"), []rune(""), []rune("bc")},
  33. 1,
  34. },
  35. {
  36. [][]rune{[]rune("addb"), []rune("ajkajsdf"), []rune("aasdfkc")},
  37. [][]rune{[]rune("ddb"), []rune("jkajsdf"), []rune("asdfkc")},
  38. 1,
  39. },
  40. {
  41. [][]rune{[]rune("ddb"), []rune("ajksdf"), []rune("aasdfkc")},
  42. [][]rune{[]rune("ddb"), []rune("ajksdf"), []rune("aasdfkc")},
  43. 0,
  44. },
  45. {
  46. [][]rune{[]rune("ddb"), []rune("ddajksdf"), []rune("ddaasdfkc")},
  47. [][]rune{[]rune("b"), []rune("ajksdf"), []rune("aasdfkc")},
  48. 2,
  49. },
  50. }
  51. for _, r := range rs {
  52. same, off := runes.Aggregate(r.r)
  53. if off != r.length {
  54. t.Fatal("result not expect", off)
  55. }
  56. if len(same) != off {
  57. t.Fatal("result not expect", same)
  58. }
  59. if !reflect.DeepEqual(r.r, r.e) {
  60. t.Fatal("result not expect")
  61. }
  62. }
  63. }