203 lines
16 KiB
Go
203 lines
16 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
||
// Use of this source code is governed by a MIT-style
|
||
// license that can be found in the LICENSE file.
|
||
|
||
package charset
|
||
|
||
import (
|
||
"reflect"
|
||
"strings"
|
||
"testing"
|
||
)
|
||
|
||
type escapeControlTest struct {
|
||
name string
|
||
text string
|
||
status EscapeStatus
|
||
result string
|
||
}
|
||
|
||
var escapeControlTests = []escapeControlTest{
|
||
{
|
||
name: "<empty>",
|
||
},
|
||
{
|
||
name: "single line western",
|
||
text: "single line western",
|
||
result: "single line western",
|
||
status: EscapeStatus{HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "multi line western",
|
||
text: "single line western\nmulti line western\n",
|
||
result: "single line western\nmulti line western\n",
|
||
status: EscapeStatus{HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "multi line western non-breaking space",
|
||
text: "single lineย western\nmulti lineย western\n",
|
||
result: `single line<span class="escaped-code-point" data-escaped="[U+00A0]"><span class="char">ย </span></span>western` + "\n" + `multi line<span class="escaped-code-point" data-escaped="[U+00A0]"><span class="char">ย </span></span>western` + "\n",
|
||
status: EscapeStatus{Escaped: true, HasLTRScript: true, HasSpaces: true},
|
||
},
|
||
{
|
||
name: "mixed scripts: western + japanese",
|
||
text: "ๆฅๅฑ็งใใใกใ
ใThen some western.",
|
||
result: "ๆฅๅฑ็งใใใกใ
ใThen some western.",
|
||
status: EscapeStatus{HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "japanese",
|
||
text: "ๆฅๅฑ็งใใใกใ
ใ",
|
||
result: "ๆฅๅฑ็งใใใกใ
ใ",
|
||
status: EscapeStatus{HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "hebrew",
|
||
text: "ืขื ืชืงืืคืช ืืืื ืืขืชืืงื ืืื ืืขืืกืืง ืืืชืืืืงื ืชืืืืชื ืืืื: ืืื ืฉืืืฉื ืืืืกืฃ ืฉื ื ืืกืืืืช ืืืืฉืื ืงืจืงืข, ืืืืืืกืื ืืื'. ืคืจืืฆืช ืืืจื ืฉื ืืืืื ืื, ืคืจื ืืชืจืืืืชืืื ืืืืืืืช ืืืืข ืืืชืืื, ืืืืชื ืืืืืื ืืืชืืืืงื ืืฉืืขืฆืื, ืืชืืงืฃ ืขืจืื ืืจืืื ื. ืืืกื ืฉื ืืืง ืืืืืื ืื ืืงืืืื ืื ืืืชืืืืงื ืืื ืืชื - ืืืฉื, ืืืช ืฉืืกืฃ ืกืืืื ืคืืชืืืจืก ืืืืื ื ืื ืืืชืืืืงื ืืื ืืืกืืก ืืื ืืืืจืื. ืืืืื ืื ื ืืฉืืื ืืืืฆืจื ืืืฉื ืืืืืื ืืืชืืืืช, ืืื ืืจืืฉืื ืื ืฉืขืกืงื ืืืชืืืืงื ืืฉื ืขืฆืื, ืืืืืจ ืืชืืื ืืืงืจื ืขืืื ื ืืืืคืฉื ืืื ืจืง ืืขืืจ ืฉืืืืฉื. ืขื ืืืช, ืืฆืื",
|
||
result: "ืขื ืชืงืืคืช ืืืื ืืขืชืืงื ืืื ืืขืืกืืง ืืืชืืืืงื ืชืืืืชื ืืืื: ืืื ืฉืืืฉื ืืืืกืฃ ืฉื ื ืืกืืืืช ืืืืฉืื ืงืจืงืข, ืืืืืืกืื ืืื'. ืคืจืืฆืช ืืืจื ืฉื ืืืืื ืื, ืคืจื ืืชืจืืืืชืืื ืืืืืืืช ืืืืข ืืืชืืื, ืืืืชื ืืืืืื ืืืชืืืืงื ืืฉืืขืฆืื, ืืชืืงืฃ ืขืจืื ืืจืืื ื. ืืืกื ืฉื ืืืง ืืืืืื ืื ืืงืืืื ืื ืืืชืืืืงื ืืื ืืชื - ืืืฉื, ืืืช ืฉืืกืฃ ืกืืืื ืคืืชืืืจืก ืืืืื ื ืื ืืืชืืืืงื ืืื ืืืกืืก ืืื ืืืืจืื. ืืืืื ืื ื ืืฉืืื ืืืืฆืจื ืืืฉื ืืืืืื ืืืชืืืืช, ืืื ืืจืืฉืื ืื ืฉืขืกืงื ืืืชืืืืงื ืืฉื ืขืฆืื, ืืืืืจ ืืชืืื ืืืงืจื ืขืืื ื ืืืืคืฉื ืืื ืจืง ืืขืืจ ืฉืืืืฉื. ืขื ืืืช, ืืฆืื",
|
||
status: EscapeStatus{HasRTLScript: true},
|
||
},
|
||
{
|
||
name: "more hebrew",
|
||
text: `ืืชืงืืคื ืืืืืจืช ืืืชืจ, ืืฉืชืืฉื ืืืืื ืื ืืฉืืืช ืกืืืื ืืชืงืืืช ืืืชืจ, ืฉืื ืืืฆืื ืืืกืคืจืื ืืคื 22 ืืืชืืืช ืืืืคืืืช ืืืืื ื. ืืกืืืื ืืืกืคืจืื ืืื 1 ื-9 ื ืงืืขื ืชืฉืข ืืืืชืืืช ืืจืืฉืื ืืช, ืืชืืกืคืช ืืจืฉ ( ' ) ืืฆื ืืืื ืฉื ืืืืช, ืืืขืื; ืชืฉืข ืืืืชืืืช ืืืืืช ืืืฆืื ืืช ืืขืฉืจืืช ื-10 ืขื 90, ืืืืืืช ืืช ืืืืืช. ืืกืืืื ืืกืคืจืืช ืืื 1000 ื-900,000, ืืฉืชืืฉื ืืืืื ืื ืืืืชื ืืืชืืืช, ืื ืืืกืืคื ืืืืชืืืช ืืช ืืืจืฉ ืืืืงื ืืฆื ืฉืืื ืฉื ืืืืชืืืช, ืืืื. ืืืืืืื ืืืขืื, ืื ืจืื ืืฉืชืืฉื ืืืืื ืื ืืฉื ื ืชืืื ืืืงืื ืืื.
|
||
|
||
ืืืชืืืืงืื ืืืืื ืืจืืฉืื ืืืืื ืืขืชืืงื, ืืืฉ ืืืืืจืื ืืชืืืืืช ืืื ืืฉืืช, ืืื ืชืืืก (624 ืืคื ื"ืก - 546 ืืคื ื"ืก ืืงืืจืื).[1] ืื ืืืื ืื ืืฉืืื ืืกืื ืืื ืื ืฉืืื ืืืื ืืจืืฉืื ืฉืืืืื ืืฉืคื ืืชืืื, ืืื ืจืง ืืืื ืืืชื. ืชืืืก ืืืืื ืฉืืฉืจืื ืืงืืืืื ืืืชืืื ืืฆื ืืื ืฉื ืฉืืงื ืืืืืช ืงืืขืื ืืขืื ืืืกืื ืฉืืืื (ืืฉืคื ืชืืืก ืืจืืฉืื), ืฉืืืืืืช ืืืื ืืช ืขื ืงืืืจ ืืืขืื ืืื ืืืืืช ืืฉืจื (ืืฉืคื ืชืืืก ืืฉื ื), ืฉืืงืืืจ ืืืืง ืืช ืืืขืื ืืฉื ื ืืืงืื ืฉืืืื, ืืฉืืืืืืช ืืืกืืก ืืืฉืืืฉ ืฉืืื-ืฉืืงืืื ืฉืืืช ืื ืืื. ืืืืืกืืช ืื ืื ืฉืืืืช ืืืืืืช ืืืืื ืฉื ืืคืืจืืืืืช ืืขืืจืช ืืืืืช ืฆืืื ืืืงืืืขืช ืืืงืืื ืฉื ืกืคืื ื ืื ืจืืืช ืื ืืืืฃ.
|
||
|
||
ืืฉื ืื 582 ืืคื ื"ืก ืขื 496 ืืคื ื"ืก, ืืงืืจืื, ืื ืืชืืืืงืื ืืฉืื ืืืืืื - ืคืืชืืืจืก. ืืืงืืจืืช ืืจืืฉืื ืืื ืขืืื ืืืขืืื, ืืืืืกืืืจืืื ืื ืืชืงืฉืื ืืืคืจืื ืืช ืืขืืืืืช ืืฉืืืช ืืืกืชืืจืื ืืืืืืืช ืฉื ืงืฉืจื ืื. ืืืืข ืฉืกืืืื ืืชืงืืฆื ืืืกืืืื ืืคืืชืืืจืืืช ืืขืื ืืช ืคืกืืื-ืืชืืืืช ืฉืืืืื ื ืฉ"ืืื ืืกืคืจ", ืื ืืืชืจ ืืืืง ืืื ื ืืชื ืืืืืืช, ืืืืืกื ืืืกืคืจืื ืืฉืืขืืืืช ืืืกืืืืช. ืืื ืื ืจืื ืืคืืชืืืจืืื ืืืขื ืืื ืืช ืืช ืืืืคืื ืืืคืืืื ืืื, ืืืืจื ืืช ืืืืืฆืข ืืืจืืชืืื, ืืืืืฆืข ืืืืืืืจื ืืืืืืฆืข ืืืจืืื ื ืืืืืขื ืืืืฉืืื ืืฉืืืื ื ืืกืคืื. ื ืืชื ืืืืจ ืฉืืคืืชืืืจืืื ืืืื ืืช ืืืืชื ืฉื ืืฉืืจืฉ ืืจืืืืขื ืฉื 2, ืฉืืื ืื ืืืืืกืื ืืจืืืืข ืฉืืืจื ืฆืืขืืชืื 1, ืื ืจืฆืืื ืื, ืื ืชืืืืชื ืืืืชื ืืืขืฉื ืจืง ืฉืืงืืขืื "ืืกืจื ืืืื ืืฉืืชืคืช", ืืืืฉื ืืืกืคืจ ืืื ืจืฆืืื ืื ืืืืืจ ืืืชืจ.[2] ืืืืืจ ืจืืฉืื ืืงืืืื ืฉื ืงืืขืื ืืกืจื ืืืื ืืฉืืชืคืช ืืืคืืข ืืืืืืื "ืชืืืืืืืก" ืฉื ืืคืืืื, ืื ืจืขืืื ืื ืืื ืืืืจ ืขืื ืงืืื ืืื, ืืืื ืืืืืฉืืช ืืคื ื"ืก ืืืืคืืกืืก, ืื ืืืกืืืื ืืคืืชืืืจืืืช, ืืืืื ืืคืืชืืืจืก ืขืฆืื.[3]`,
|
||
result: `ืืชืงืืคื ืืืืืจืช ืืืชืจ, ืืฉืชืืฉื ืืืืื ืื ืืฉืืืช ืกืืืื ืืชืงืืืช ืืืชืจ, ืฉืื ืืืฆืื ืืืกืคืจืื ืืคื 22 ืืืชืืืช ืืืืคืืืช ืืืืื ื. ืืกืืืื ืืืกืคืจืื ืืื 1 ื-9 ื ืงืืขื ืชืฉืข ืืืืชืืืช ืืจืืฉืื ืืช, ืืชืืกืคืช ืืจืฉ ( ' ) ืืฆื ืืืื ืฉื ืืืืช, ืืืขืื; ืชืฉืข ืืืืชืืืช ืืืืืช ืืืฆืื ืืช ืืขืฉืจืืช ื-10 ืขื 90, ืืืืืืช ืืช ืืืืืช. ืืกืืืื ืืกืคืจืืช ืืื 1000 ื-900,000, ืืฉืชืืฉื ืืืืื ืื ืืืืชื ืืืชืืืช, ืื ืืืกืืคื ืืืืชืืืช ืืช ืืืจืฉ ืืืืงื ืืฆื ืฉืืื ืฉื ืืืืชืืืช, ืืืื. ืืืืืืื ืืืขืื, ืื ืจืื ืืฉืชืืฉื ืืืืื ืื ืืฉื ื ืชืืื ืืืงืื ืืื.
|
||
|
||
ืืืชืืืืงืื ืืืืื ืืจืืฉืื ืืืืื ืืขืชืืงื, ืืืฉ ืืืืืจืื ืืชืืืืืช ืืื ืืฉืืช, ืืื ืชืืืก (624 ืืคื ื"ืก - 546 ืืคื ื"ืก ืืงืืจืื).[1] ืื ืืืื ืื ืืฉืืื ืืกืื ืืื ืื ืฉืืื ืืืื ืืจืืฉืื ืฉืืืืื ืืฉืคื ืืชืืื, ืืื ืจืง ืืืื ืืืชื. ืชืืืก ืืืืื ืฉืืฉืจืื ืืงืืืืื ืืืชืืื ืืฆื ืืื ืฉื ืฉืืงื ืืืืืช ืงืืขืื ืืขืื ืืืกืื ืฉืืืื (ืืฉืคื ืชืืืก ืืจืืฉืื), ืฉืืืืืืช ืืืื ืืช ืขื ืงืืืจ ืืืขืื ืืื ืืืืืช ืืฉืจื (ืืฉืคื ืชืืืก ืืฉื ื), ืฉืืงืืืจ ืืืืง ืืช ืืืขืื ืืฉื ื ืืืงืื ืฉืืืื, ืืฉืืืืืืช ืืืกืืก ืืืฉืืืฉ ืฉืืื-ืฉืืงืืื ืฉืืืช ืื ืืื. ืืืืืกืืช ืื ืื ืฉืืืืช ืืืืืืช ืืืืื ืฉื ืืคืืจืืืืืช ืืขืืจืช ืืืืืช ืฆืืื ืืืงืืืขืช ืืืงืืื ืฉื ืกืคืื ื ืื ืจืืืช ืื ืืืืฃ.
|
||
|
||
ืืฉื ืื 582 ืืคื ื"ืก ืขื 496 ืืคื ื"ืก, ืืงืืจืื, ืื ืืชืืืืงืื ืืฉืื ืืืืืื - ืคืืชืืืจืก. ืืืงืืจืืช ืืจืืฉืื ืืื ืขืืื ืืืขืืื, ืืืืืกืืืจืืื ืื ืืชืงืฉืื ืืืคืจืื ืืช ืืขืืืืืช ืืฉืืืช ืืืกืชืืจืื ืืืืืืืช ืฉื ืงืฉืจื ืื. ืืืืข ืฉืกืืืื ืืชืงืืฆื ืืืกืืืื ืืคืืชืืืจืืืช ืืขืื ืืช ืคืกืืื-ืืชืืืืช ืฉืืืืื ื ืฉ"ืืื ืืกืคืจ", ืื ืืืชืจ ืืืืง ืืื ื ืืชื ืืืืืืช, ืืืืืกื ืืืกืคืจืื ืืฉืืขืืืืช ืืืกืืืืช. ืืื ืื ืจืื ืืคืืชืืืจืืื ืืืขื ืืื ืืช ืืช ืืืืคืื ืืืคืืืื ืืื, ืืืืจื ืืช ืืืืืฆืข ืืืจืืชืืื, ืืืืืฆืข ืืืืืืืจื ืืืืืืฆืข ืืืจืืื ื ืืืืืขื ืืืืฉืืื ืืฉืืืื ื ืืกืคืื. ื ืืชื ืืืืจ ืฉืืคืืชืืืจืืื ืืืื ืืช ืืืืชื ืฉื ืืฉืืจืฉ ืืจืืืืขื ืฉื 2, ืฉืืื ืื ืืืืืกืื ืืจืืืืข ืฉืืืจื ืฆืืขืืชืื 1, ืื ืจืฆืืื ืื, ืื ืชืืืืชื ืืืืชื ืืืขืฉื ืจืง ืฉืืงืืขืื "ืืกืจื ืืืื ืืฉืืชืคืช", ืืืืฉื ืืืกืคืจ ืืื ืจืฆืืื ืื ืืืืืจ ืืืชืจ.[2] ืืืืืจ ืจืืฉืื ืืงืืืื ืฉื ืงืืขืื ืืกืจื ืืืื ืืฉืืชืคืช ืืืคืืข ืืืืืืื "ืชืืืืืืืก" ืฉื ืืคืืืื, ืื ืจืขืืื ืื ืืื ืืืืจ ืขืื ืงืืื ืืื, ืืืื ืืืืืฉืืช ืืคื ื"ืก ืืืืคืืกืืก, ืื ืืืกืืืื ืืคืืชืืืจืืืช, ืืืืื ืืคืืชืืืจืก ืขืฆืื.[3]`,
|
||
status: EscapeStatus{HasRTLScript: true},
|
||
},
|
||
{
|
||
name: "Mixed RTL+LTR",
|
||
text: `Many computer programs fail to display bidirectional text correctly.
|
||
For example, the Hebrew name Sarah (ืฉืจื) is spelled: sin (ืฉ) (which appears rightmost),
|
||
then resh (ืจ), and finally heh (ื) (which should appear leftmost).`,
|
||
result: `Many computer programs fail to display bidirectional text correctly.
|
||
For example, the Hebrew name Sarah (ืฉืจื) is spelled: sin (ืฉ) (which appears rightmost),
|
||
then resh (ืจ), and finally heh (ื) (which should appear leftmost).`,
|
||
status: EscapeStatus{
|
||
HasRTLScript: true,
|
||
HasLTRScript: true,
|
||
},
|
||
},
|
||
{
|
||
name: "Mixed RTL+LTR+BIDI",
|
||
text: `Many computer programs fail to display bidirectional text correctly.
|
||
For example, the Hebrew name Sarah ` + "\u2067" + `ืฉืจื` + "\u2066\n" +
|
||
`sin (ืฉ) (which appears rightmost), then resh (ืจ), and finally heh (ื) (which should appear leftmost).`,
|
||
result: `Many computer programs fail to display bidirectional text correctly.
|
||
For example, the Hebrew name Sarah <span class="escaped-code-point" data-escaped="[U+2067]"><span class="char">` + "\u2067" + `</span></span>ืฉืจื<span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066" + `</span></span>` + "\n" +
|
||
`sin (ืฉ) (which appears rightmost), then resh (ืจ), and finally heh (ื) (which should appear leftmost).`,
|
||
status: EscapeStatus{
|
||
Escaped: true,
|
||
HasBIDI: true,
|
||
HasRTLScript: true,
|
||
HasLTRScript: true,
|
||
},
|
||
},
|
||
{
|
||
name: "Accented characters",
|
||
text: string([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}),
|
||
result: string([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba}),
|
||
status: EscapeStatus{HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "Program",
|
||
text: "string([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})",
|
||
result: "string([]byte{0xc3, 0xa1, 0xc3, 0xa9, 0xc3, 0xad, 0xc3, 0xb3, 0xc3, 0xba})",
|
||
status: EscapeStatus{HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "CVE testcase",
|
||
text: "if access_level != \"user\u202E \u2066// Check if admin\u2069 \u2066\" {",
|
||
result: `if access_level != "user<span class="escaped-code-point" data-escaped="[U+202E]"><span class="char">` + "\u202e" + `</span></span> <span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066" + `</span></span>// Check if admin<span class="escaped-code-point" data-escaped="[U+2069]"><span class="char">` + "\u2069" + `</span></span> <span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066" + `</span></span>" {`,
|
||
status: EscapeStatus{Escaped: true, HasBIDI: true, BadBIDI: true, HasLTRScript: true},
|
||
},
|
||
{
|
||
name: "Mixed testcase with fail",
|
||
text: `Many computer programs fail to display bidirectional text correctly.
|
||
For example, the Hebrew name Sarah ` + "\u2067" + `ืฉืจื` + "\u2066\n" +
|
||
`sin (ืฉ) (which appears rightmost), then resh (ืจ), and finally heh (ื) (which should appear leftmost).` +
|
||
"\nif access_level != \"user\u202E \u2066// Check if admin\u2069 \u2066\" {\n",
|
||
result: `Many computer programs fail to display bidirectional text correctly.
|
||
For example, the Hebrew name Sarah <span class="escaped-code-point" data-escaped="[U+2067]"><span class="char">` + "\u2067" + `</span></span>ืฉืจื<span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066" + `</span></span>` + "\n" +
|
||
`sin (ืฉ) (which appears rightmost), then resh (ืจ), and finally heh (ื) (which should appear leftmost).` +
|
||
"\n" + `if access_level != "user<span class="escaped-code-point" data-escaped="[U+202E]"><span class="char">` + "\u202e" + `</span></span> <span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066" + `</span></span>// Check if admin<span class="escaped-code-point" data-escaped="[U+2069]"><span class="char">` + "\u2069" + `</span></span> <span class="escaped-code-point" data-escaped="[U+2066]"><span class="char">` + "\u2066" + `</span></span>" {` + "\n",
|
||
status: EscapeStatus{Escaped: true, HasBIDI: true, BadBIDI: true, HasLTRScript: true, HasRTLScript: true},
|
||
},
|
||
}
|
||
|
||
func TestEscapeControlString(t *testing.T) {
|
||
for _, tt := range escapeControlTests {
|
||
t.Run(tt.name, func(t *testing.T) {
|
||
status, result := EscapeControlString(tt.text)
|
||
if !reflect.DeepEqual(status, tt.status) {
|
||
t.Errorf("EscapeControlString() status = %v, wanted= %v", status, tt.status)
|
||
}
|
||
if result != tt.result {
|
||
t.Errorf("EscapeControlString()\nresult= %v,\nwanted= %v", result, tt.result)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
func TestEscapeControlBytes(t *testing.T) {
|
||
for _, tt := range escapeControlTests {
|
||
t.Run(tt.name, func(t *testing.T) {
|
||
status, result := EscapeControlBytes([]byte(tt.text))
|
||
if !reflect.DeepEqual(status, tt.status) {
|
||
t.Errorf("EscapeControlBytes() status = %v, wanted= %v", status, tt.status)
|
||
}
|
||
if string(result) != tt.result {
|
||
t.Errorf("EscapeControlBytes()\nresult= %v,\nwanted= %v", result, tt.result)
|
||
}
|
||
})
|
||
}
|
||
}
|
||
|
||
func TestEscapeControlReader(t *testing.T) {
|
||
// lets add some control characters to the tests
|
||
tests := make([]escapeControlTest, 0, len(escapeControlTests)*3)
|
||
copy(tests, escapeControlTests)
|
||
for _, test := range escapeControlTests {
|
||
test.name += " (+Control)"
|
||
test.text = "\u001E" + test.text
|
||
test.result = `<span class="escaped-code-point" data-escaped="[U+001E]"><span class="char">` + "\u001e" + `</span></span>` + test.result
|
||
test.status.Escaped = true
|
||
test.status.HasControls = true
|
||
tests = append(tests, test)
|
||
}
|
||
|
||
for _, test := range escapeControlTests {
|
||
test.name += " (+Mark)"
|
||
test.text = "\u0300" + test.text
|
||
test.result = `<span class="escaped-code-point" data-escaped="[U+0300]"><span class="char">` + "\u0300" + `</span></span>` + test.result
|
||
test.status.Escaped = true
|
||
test.status.HasMarks = true
|
||
tests = append(tests, test)
|
||
}
|
||
|
||
for _, tt := range tests {
|
||
t.Run(tt.name, func(t *testing.T) {
|
||
input := strings.NewReader(tt.text)
|
||
output := &strings.Builder{}
|
||
status, err := EscapeControlReader(input, output)
|
||
result := output.String()
|
||
if err != nil {
|
||
t.Errorf("EscapeControlReader(): err = %v", err)
|
||
}
|
||
|
||
if !reflect.DeepEqual(status, tt.status) {
|
||
t.Errorf("EscapeControlReader() status = %v, wanted= %v", status, tt.status)
|
||
}
|
||
if result != tt.result {
|
||
t.Errorf("EscapeControlReader()\nresult= %v,\nwanted= %v", result, tt.result)
|
||
}
|
||
})
|
||
}
|
||
}
|