intrange_test.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package types
  2. import "testing"
  3. func TestParseNumberMenu(t *testing.T) {
  4. type result struct {
  5. Include IntRanges
  6. Exclude IntRanges
  7. OtherInclude StringSet
  8. OtherExclude StringSet
  9. }
  10. inputs := []string{
  11. "1 2 3 4 5",
  12. "1-10 5-15",
  13. "10-5 90-85",
  14. "1 ^2 ^10-5 99 ^40-38 ^123 60-62",
  15. "abort all none",
  16. "a-b ^a-b ^abort",
  17. "-9223372036854775809-9223372036854775809",
  18. "1\t2 3 4\t\t \t 5",
  19. "1 2,3, 4, 5,6 ,7 ,8",
  20. "",
  21. " \t ",
  22. "A B C D E",
  23. }
  24. expected := []result{
  25. {IntRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, IntRanges{}, make(StringSet), make(StringSet)},
  26. {IntRanges{makeIntRange(1, 10), makeIntRange(5, 15)}, IntRanges{}, make(StringSet), make(StringSet)},
  27. {IntRanges{makeIntRange(5, 10), makeIntRange(85, 90)}, IntRanges{}, make(StringSet), make(StringSet)},
  28. {IntRanges{makeIntRange(1, 1), makeIntRange(99, 99), makeIntRange(60, 62)}, IntRanges{makeIntRange(2, 2), makeIntRange(5, 10), makeIntRange(38, 40), makeIntRange(123, 123)}, make(StringSet), make(StringSet)},
  29. {IntRanges{}, IntRanges{}, MakeStringSet("abort", "all", "none"), make(StringSet)},
  30. {IntRanges{}, IntRanges{}, MakeStringSet("a-b"), MakeStringSet("abort", "a-b")},
  31. {IntRanges{}, IntRanges{}, MakeStringSet("-9223372036854775809-9223372036854775809"), make(StringSet)},
  32. {IntRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5)}, IntRanges{}, make(StringSet), make(StringSet)},
  33. {IntRanges{makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), makeIntRange(8, 8)}, IntRanges{}, make(StringSet), make(StringSet)},
  34. {IntRanges{}, IntRanges{}, make(StringSet), make(StringSet)},
  35. {IntRanges{}, IntRanges{}, make(StringSet), make(StringSet)},
  36. {IntRanges{}, IntRanges{}, MakeStringSet("a", "b", "c", "d", "e"), make(StringSet)},
  37. }
  38. for n, in := range inputs {
  39. res := expected[n]
  40. include, exclude, otherInclude, otherExclude := ParseNumberMenu(in)
  41. if !intRangesEqual(include, res.Include) ||
  42. !intRangesEqual(exclude, res.Exclude) ||
  43. !StringSetEqual(otherInclude, res.OtherInclude) ||
  44. !StringSetEqual(otherExclude, res.OtherExclude) {
  45. t.Fatalf("Test %d Failed: Expected: include=%+v exclude=%+v otherInclude=%+v otherExclude=%+v got include=%+v excluive=%+v otherInclude=%+v otherExclude=%+v",
  46. n+1, res.Include, res.Exclude, res.OtherInclude, res.OtherExclude, include, exclude, otherInclude, otherExclude)
  47. }
  48. }
  49. }