app_test.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package weirdtext
  2. import (
  3. "testing"
  4. )
  5. type testCase struct {
  6. text string
  7. count int
  8. }
  9. func TestDecodeEncode(t *testing.T) {
  10. testCases := []testCase{
  11. {"This is a long looong test sentence,\nwith some big (biiiiig) words!", 8},
  12. {"Pre-translation generally means applying the TM(s) to one or more files as whole instead of moving segment by segment.", 11},
  13. {"Szła dzieweczka do laseczka\nDo zielonego, do zielonego, do zielonego.\nNapotkała myśliweczka\nBardzo szwarnego, bardzo szwarnego, bardzo szwarnego.", 14},
  14. {"新型コロナウィルス感染症拡大防止のため,一部在宅勤務等による接触機会削減を実施しています。電話,FAX,郵便,メールフォーム等でのお問い合わせにつきましては,対応にお時間をいただく場合がありますので,予めご了承ください。また,一般の方の建物内への立入は,当面の間ご遠慮いただいております。みなさまにはご不便をおかけしますが,なにとぞご理解・ご協力のほどよろしくお願い申し上げます。", 10},
  15. {"Lorem ipsum dolor sit amet, est in aliquip aperiam. Sea te feugiat labores voluptatibus, pri ea affert ubique noluisse! No usu dolorum mentitum, sed eros nihil singulis ad? Has liber putent percipit et, vel te iriure intellegat. Eu dicam placerat has, id eos omittam facilisi, pertinacia constituto te has?", 28},
  16. {"Λορεμ ιπσθμ δολορ σιτ αμετ, λορεμ λαβοραμθσ ει μελ, cονσετετθρ δεφινιτιονεσ αν εοσ. Εα ηαρθμ cονcλθδατθρqθε περ? Νε ηισ vιvενδθμ μανδαμθσ! Αδ τραcτατοσ δισπθτανδο ιθσ, θτ εστ λαθδεμ μινιμθμ ιντελλεγαμ.", 17},
  17. {"Szła dzieweczka do laseczka\nDo zielunego, do zielonego, do zielonego.\nNapotkała myśliweczka\nBardzo szwarnego, bardzo szwarnego, bardzo szwarnego.", 14},
  18. }
  19. for _, item := range testCases {
  20. encoded := EncodeText(item.text)
  21. if encoded.Text == item.text {
  22. t.Errorf("Encoded text '%s' should be different than provided text '%s'!", encoded.Text, item.text)
  23. }
  24. count := len(encoded.EncodedWords)
  25. if count != item.count {
  26. t.Errorf("There should be %d encoded words instead of %d! %v", item.count, count, encoded.EncodedWords)
  27. }
  28. decodedText := DecodeText(encoded)
  29. if decodedText != item.text {
  30. t.Errorf("Decoded text '%s' should be same as expected text '%s'!", decodedText, item.text)
  31. }
  32. }
  33. }
  34. func TestSerializeDeserializeEncodedText(t *testing.T) {
  35. expected := "This is a long looong test sentence,\nwith some big (biiiiig) words!"
  36. encoded := EncodeText(expected)
  37. serialized := encoded.String()
  38. toDecode := EncodedText{}
  39. err := toDecode.FromString(serialized)
  40. if err != nil {
  41. t.Errorf("Error deserializing encoded text: %s", err)
  42. }
  43. decodedText := DecodeText(toDecode)
  44. if decodedText != expected {
  45. t.Errorf("Decoded text '%s' should be same as expected text '%s'!", decodedText, expected)
  46. }
  47. }