1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package ianaindex
6
7import (
8	"unicode"
9	"testing"
10
11	"golang.org/x/text/encoding"
12)
13
14func TestASCIIDecoder(t *testing.T) {
15	repl := string(unicode.ReplacementChar)
16	input := "Comment Candide fut élevé dans un beau château"
17	want := "Comment Candide fut " + repl + repl + "lev" + repl + repl + " dans un beau ch" + repl + repl + "teau"
18	got, err := asciiEnc.NewDecoder().String(input)
19	if err != nil {
20		t.Fatalf("unexpected error: %v", err)
21	}
22	if got != want {
23		t.Fatalf("asciiEnc.NewDecoder().String() = %q, want %q", got, want)
24	}
25}
26
27func TestASCIIEncoder(t *testing.T) {
28	repl := string(encoding.ASCIISub)
29	input := "Comment Candide fut élevé dans un beau château"
30	want := "Comment Candide fut " + repl + "lev" + repl + " dans un beau ch" + repl + "teau"
31	got, err := encoding.ReplaceUnsupported(asciiEnc.NewEncoder()).String(input)
32	if err != nil {
33		t.Fatalf("unexpected error: %v", err)
34	}
35	if got != want {
36		t.Fatalf("asciiEnc.NewEncoder().String() = %q, want %q", got, want)
37	}
38}
39