stop_test.go 984 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package main
  2. import (
  3. "reflect"
  4. "testing"
  5. )
  6. func TestTruncateStop(t *testing.T) {
  7. tests := []struct {
  8. name string
  9. pieces []string
  10. stop string
  11. expected []string
  12. }{
  13. {
  14. name: "Single word",
  15. pieces: []string{"hello", "world"},
  16. stop: "world",
  17. expected: []string{"hello"},
  18. },
  19. {
  20. name: "Partial",
  21. pieces: []string{"hello", "wor"},
  22. stop: "or",
  23. expected: []string{"hello", "w"},
  24. },
  25. {
  26. name: "Suffix",
  27. pieces: []string{"Hello", " there", "!"},
  28. stop: "!",
  29. expected: []string{"Hello", " there"},
  30. },
  31. {
  32. name: "Middle",
  33. pieces: []string{"hello", " wor"},
  34. stop: "llo w",
  35. expected: []string{"he"},
  36. },
  37. }
  38. for _, tt := range tests {
  39. t.Run(tt.name, func(t *testing.T) {
  40. result := truncateStop(tt.pieces, tt.stop)
  41. if !reflect.DeepEqual(result, tt.expected) {
  42. t.Errorf("truncateStop(%v, %s): have %v; want %v", tt.pieces, tt.stop, result, tt.expected)
  43. }
  44. })
  45. }
  46. }