Browse Source

Added TestSerializeEncodedText

Piotr Czajkowski 3 years ago
parent
commit
efcf2fd298
2 changed files with 16 additions and 1 deletions
  1. 14 0
      app_test.go
  2. 2 1
      encodedText.go

+ 14 - 0
app_test.go

@@ -32,3 +32,17 @@ func TestDecodeEncode(t *testing.T) {
 		}
 	}
 }
+
+func TestSerializeEncodedText(t *testing.T) {
+	expected := `
+---weird---
+Tihs is a lnog loonog tset sneetcne,
+wtih smoe big (biiiiig) wodrs!
+---weird---
+This long looong sentence some test with words`
+
+	encoded := EncodeText("This is a long looong test sentence,\nwith some big (biiiiig) words!")
+	if encoded.String() != expected {
+		t.Errorf("Serialization error!\nShould be:%s\nIs:%s", expected, encoded.String())
+	}
+}

+ 2 - 1
encodedText.go

@@ -2,6 +2,7 @@ package main
 
 import (
 	"fmt"
+	"strings"
 )
 
 type EncodedText struct {
@@ -10,5 +11,5 @@ type EncodedText struct {
 }
 
 func (e EncodedText) String() string {
-	return fmt.Sprintf("\n---weird---\n%s\n---weird---\n%v", e.text, e.encodedWords)
+	return fmt.Sprintf("\n---weird---\n%s\n---weird---\n%v", e.text, strings.Join(e.encodedWords, " "))
 }