File: sanitize_string_test.go

package info (click to toggle)
golang-github-protonmail-gopenpgp-v3 3.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,028 kB
  • sloc: sh: 87; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 963 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package internal

import (
	"bytes"
	"io"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func expectedOutput(in string) string {
	return SanitizeString(strings.ReplaceAll(in, "\r\n", "\n"))
}

func testStringSanitizeReader(t *testing.T, test string) {
	reader := NewSanitizeReader(bytes.NewReader([]byte(test)))
	byteBuffer := new(bytes.Buffer)
	smallBuff := make([]byte, 3)
	var err error
	for err != io.EOF {
		var n int
		n, err = reader.Read(smallBuff)
		byteBuffer.Write(smallBuff[:n])
	}
	assert.Equal(t, byteBuffer.String(), expectedOutput(test))
}

func TestStringSanitizeReader(t *testing.T) {
	test := "a\xc5zsd\xc5\r\ndf\rdf\xc5df\rsdf\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
	testStringSanitizeReader(t, test)
	testStringSanitizeReader(t, "\r\n\r\n\r\n\r\n\r\n\r\n\r\n")
	testStringSanitizeReader(t, "\n")
	testStringSanitizeReader(t, "\r")
	testStringSanitizeReader(t, "")
	testStringSanitizeReader(t, "\xc5\xc5\xc5\xc5\xc5\xc5\xc5\xc5\xc5")
}