...

Source file src/golang.org/x/text/encoding/ianaindex/ascii_test.go

Documentation: golang.org/x/text/encoding/ianaindex

     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  
     5  package ianaindex
     6  
     7  import (
     8  	"testing"
     9  	"unicode"
    10  
    11  	"golang.org/x/text/encoding"
    12  )
    13  
    14  func 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  
    27  func 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  

View as plain text