github.com/Ptt-official-app/go-bbs@v0.12.0/big5_test.go (about)

     1  // Copyright 2020 Pichu Chen, The PTT APP Authors
     2  
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package bbs
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  )
    21  
    22  func TestUtf8ToBig5(t *testing.T) {
    23  	type args struct {
    24  		input string
    25  	}
    26  	tests := []struct {
    27  		name     string
    28  		args     args
    29  		expected string
    30  	}{
    31  		// TODO: Add test cases.
    32  		{
    33  			name:     "test0",
    34  			args:     args{input: "新的目錄"},
    35  			expected: "\xb7\x73\xaa\xba\xa5\xd8\xbf\xfd",
    36  		},
    37  		{
    38  			name:     "test1",
    39  			args:     args{input: "ピリカピリララ"},
    40  			expected: "\xc7\xd0\xc7\xe6\xc7\xa7\xc7\xd0\xc7\xe6\xc7\xe5\xc7\xe5",
    41  		},
    42  	}
    43  	for _, tt := range tests {
    44  		t.Run(tt.name, func(t *testing.T) {
    45  			if got := Utf8ToBig5(tt.args.input); !reflect.DeepEqual(got, []byte(tt.expected)) {
    46  				t.Errorf("Utf8ToBig5() = %v, expected %v", got, tt.expected)
    47  			}
    48  		})
    49  	}
    50  }
    51  
    52  func TestBig5ToUtf8(t *testing.T) {
    53  	type args struct {
    54  		input string
    55  	}
    56  	tests := []struct {
    57  		name     string
    58  		args     args
    59  		expected string
    60  	}{
    61  		// TODO: Add test cases.
    62  		{
    63  			name:     "test0",
    64  			args:     args{input: "\xb7\x73\xaa\xba\xa5\xd8\xbf\xfd"},
    65  			expected: "新的目錄",
    66  		},
    67  		{
    68  			name:     "test1",
    69  			args:     args{input: "\xc7\xd0\xc7\xe6\xc7\xa7\xc7\xd0\xc7\xe6\xc7\xe5\xc7\xe5"},
    70  			expected: "ピリカピリララ",
    71  		},
    72  	}
    73  	for _, tt := range tests {
    74  		t.Run(tt.name, func(t *testing.T) {
    75  			if got := Big5ToUtf8([]byte(tt.args.input)); !reflect.DeepEqual(got, tt.expected) {
    76  				t.Errorf("Big5ToUtf8() = %v, expected %v", got, tt.expected)
    77  			}
    78  		})
    79  	}
    80  }