github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/text/encoding/korean/all_test.go (about)

     1  // Copyright 2015 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 korean
     6  
     7  import (
     8  	"testing"
     9  
    10  	"golang.org/x/text/encoding"
    11  	"golang.org/x/text/encoding/internal"
    12  	"golang.org/x/text/transform"
    13  )
    14  
    15  func dec(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
    16  	return "Decode", e.NewDecoder(), nil
    17  }
    18  func enc(e encoding.Encoding) (dir string, t transform.Transformer, err error) {
    19  	return "Encode", e.NewEncoder(), internal.ErrASCIIReplacement
    20  }
    21  
    22  func TestNonRepertoire(t *testing.T) {
    23  	testCases := []struct {
    24  		init      func(e encoding.Encoding) (string, transform.Transformer, error)
    25  		e         encoding.Encoding
    26  		src, want string
    27  	}{
    28  		{dec, EUCKR, "\xfe\xfe", "\ufffd"},
    29  		// {dec, EUCKR, "א", "\ufffd"}, // TODO: why is this different?
    30  
    31  		{enc, EUCKR, "א", ""},
    32  		{enc, EUCKR, "aא", "a"},
    33  		{enc, EUCKR, "\uac00א", "\xb0\xa1"},
    34  		// TODO: should we also handle Jamo?
    35  	}
    36  	for _, tc := range testCases {
    37  		dir, tr, wantErr := tc.init(tc.e)
    38  
    39  		dst, _, err := transform.String(tr, tc.src)
    40  		if err != wantErr {
    41  			t.Errorf("%s %v(%q): got %v; want %v", dir, tc.e, tc.src, err, wantErr)
    42  		}
    43  		if got := string(dst); got != tc.want {
    44  			t.Errorf("%s %v(%q):\ngot  %q\nwant %q", dir, tc.e, tc.src, got, tc.want)
    45  		}
    46  	}
    47  }