MCPcopy Create free account
hub / github.com/golang/text / TestReplacement

Function TestReplacement

encoding/encoding_test.go:54–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

52}
53
54func TestReplacement(t *testing.T) {
55 for _, direction := range []string{"Decode", "Encode"} {
56 enc, want := (transform.Transformer)(nil), ""
57 if direction == "Decode" {
58 enc = encoding.Replacement.NewDecoder()
59 want = "\ufffd"
60 } else {
61 enc = encoding.Replacement.NewEncoder()
62 want = "AB\x00CD\ufffdYZ"
63 }
64 sr := strings.NewReader("AB\x00CD\x80YZ")
65 g, err := io.ReadAll(transform.NewReader(sr, enc))
66 if err != nil {
67 t.Errorf("%s: ReadAll: %v", direction, err)
68 continue
69 }
70 if got := string(g); got != want {
71 t.Errorf("%s:\ngot %q\nwant %q", direction, got, want)
72 continue
73 }
74 }
75}
76
77func TestUTF8Validator(t *testing.T) {
78 testCases := []struct {

Callers

nothing calls this directly

Calls 3

NewReaderFunction · 0.92
NewDecoderMethod · 0.65
NewEncoderMethod · 0.65

Tested by

no test coverage detected