File: ascii_test.go

package info (click to toggle)
golang-golang-x-text 0.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 41,604 kB
  • sloc: xml: 1,022; makefile: 6
file content (38 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (7)
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
38
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ianaindex

import (
	"testing"
	"unicode"

	"golang.org/x/text/encoding"
)

func TestASCIIDecoder(t *testing.T) {
	repl := string(unicode.ReplacementChar)
	input := "Comment Candide fut élevé dans un beau château"
	want := "Comment Candide fut " + repl + repl + "lev" + repl + repl + " dans un beau ch" + repl + repl + "teau"
	got, err := asciiEnc.NewDecoder().String(input)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if got != want {
		t.Fatalf("asciiEnc.NewDecoder().String() = %q, want %q", got, want)
	}
}

func TestASCIIEncoder(t *testing.T) {
	repl := string(encoding.ASCIISub)
	input := "Comment Candide fut élevé dans un beau château"
	want := "Comment Candide fut " + repl + "lev" + repl + " dans un beau ch" + repl + "teau"
	got, err := encoding.ReplaceUnsupported(asciiEnc.NewEncoder()).String(input)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if got != want {
		t.Fatalf("asciiEnc.NewEncoder().String() = %q, want %q", got, want)
	}
}