test_utils.go 743 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package gse
  2. import (
  3. "fmt"
  4. "testing"
  5. )
  6. func printTokens(tokens []*Token, numTokens int) (output string) {
  7. for iToken := 0; iToken < numTokens; iToken++ {
  8. for _, word := range tokens[iToken].text {
  9. output += fmt.Sprint(string(word))
  10. }
  11. output += " "
  12. }
  13. return
  14. }
  15. func toWords(strings ...string) []Text {
  16. words := []Text{}
  17. for _, s := range strings {
  18. words = append(words, []byte(s))
  19. }
  20. return words
  21. }
  22. func bytesToString(bytes []Text) (output string) {
  23. for _, b := range bytes {
  24. output += (string(b) + "/")
  25. }
  26. return
  27. }
  28. func expect(t *testing.T, expect string, actual interface{}) {
  29. actualString := fmt.Sprint(actual)
  30. if expect != actualString {
  31. t.Errorf("期待值=\"%s\", 实际=\"%s\"", expect, actualString)
  32. }
  33. }