| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
package encoding |
| 16 |
|
| 17 |
import ( |
| 18 |
"testing" |
| 19 |
) |
| 20 |
|
| 21 |
type mapRange struct { |
| 22 |
first byte |
| 23 |
last byte |
| 24 |
r rune |
| 25 |
} |
| 26 |
|
| 27 |
var mapRanges = []mapRange{ |
| 28 |
{0, 3, '\x00'}, |
| 29 |
{4, 4, RuneError}, |
| 30 |
{5, 5, '\x09'}, |
| 31 |
{6, 6, RuneError}, |
| 32 |
{7, 7, '\x7f'}, |
| 33 |
{8, 10, RuneError}, |
| 34 |
{11, 19, '\x0b'}, |
| 35 |
{20, 20, RuneError}, |
| 36 |
{21, 21, '\u0085'}, |
| 37 |
{22, 22, '\x08'}, |
| 38 |
{23, 23, RuneError}, |
| 39 |
{24, 25, '\x18'}, |
| 40 |
{26, 27, RuneError}, |
| 41 |
{28, 31, '\x1c'}, |
| 42 |
{32, 36, RuneError}, |
| 43 |
{37, 37, '\x0a'}, |
| 44 |
{38, 38, '\x17'}, |
| 45 |
{39, 39, '\x1b'}, |
| 46 |
{40, 44, RuneError}, |
| 47 |
{45, 47, '\x05'}, |
| 48 |
{48, 49, RuneError}, |
| 49 |
{50, 50, '\x16'}, |
| 50 |
{51, 54, RuneError}, |
| 51 |
{55, 55, '\x04'}, |
| 52 |
{56, 59, RuneError}, |
| 53 |
{60, 61, '\x14'}, |
| 54 |
{62, 62, RuneError}, |
| 55 |
{63, 63, '\x1a'}, |
| 56 |
{64, 64, '\x20'}, |
| 57 |
{65, 65, '\xa0'}, |
| 58 |
{66, 74, RuneError}, |
| 59 |
{75, 75, '.'}, |
| 60 |
{76, 76, '<'}, |
| 61 |
{77, 77, '('}, |
| 62 |
{78, 78, '+'}, |
| 63 |
{79, 79, '|'}, |
| 64 |
{80, 80, '&'}, |
| 65 |
{81, 89, RuneError}, |
| 66 |
{90, 90, '!'}, |
| 67 |
{91, 91, '$'}, |
| 68 |
{92, 92, '*'}, |
| 69 |
{93, 93, ')'}, |
| 70 |
{94, 94, ';'}, |
| 71 |
{95, 95, '\u00ac'}, |
| 72 |
{96, 96, '\x2d'}, |
| 73 |
{97, 97, '\x2f'}, |
| 74 |
{98, 105, RuneError}, |
| 75 |
{106, 106, '\u00a6'}, |
| 76 |
{107, 107, '\x2c'}, |
| 77 |
{108, 108, '%'}, |
| 78 |
{109, 109, '\x5f'}, |
| 79 |
{110, 111, '\x3e'}, |
| 80 |
{112, 120, RuneError}, |
| 81 |
{121, 121, '\x60'}, |
| 82 |
{122, 122, ':'}, |
| 83 |
{123, 123, '#'}, |
| 84 |
{124, 124, '@'}, |
| 85 |
{125, 125, '\x27'}, |
| 86 |
{126, 126, '='}, |
| 87 |
{127, 127, '\x22'}, |
| 88 |
{128, 128, RuneError}, |
| 89 |
{129, 137, 'a'}, |
| 90 |
{138, 142, RuneError}, |
| 91 |
{143, 143, '\u00b1'}, |
| 92 |
{144, 144, RuneError}, |
| 93 |
{145, 153, 'j'}, |
| 94 |
{154, 160, RuneError}, |
| 95 |
{161, 161, '~'}, |
| 96 |
{162, 169, 's'}, |
| 97 |
{170, 175, RuneError}, |
| 98 |
{176, 176, '\x5e'}, |
| 99 |
{177, 185, RuneError}, |
| 100 |
{186, 186, '['}, |
| 101 |
{187, 187, ']'}, |
| 102 |
{188, 191, RuneError}, |
| 103 |
{192, 192, '{'}, |
| 104 |
{193, 201, 'A'}, |
| 105 |
{202, 202, '\u00ad'}, |
| 106 |
{203, 207, RuneError}, |
| 107 |
{208, 208, '}'}, |
| 108 |
{209, 217, 'J'}, |
| 109 |
{218, 223, RuneError}, |
| 110 |
{224, 224, '\x5c'}, |
| 111 |
{226, 233, 'S'}, |
| 112 |
{234, 239, RuneError}, |
| 113 |
{240, 249, '0'}, |
| 114 |
{250, 255, RuneError}, |
| 115 |
} |
| 116 |
|
| 117 |
func TestEBCDICvsASCII(t *testing.T) { |
| 118 |
t.Logf("EBCDIC/ASCII identity values") |
| 119 |
for _, rng := range mapRanges { |
| 120 |
if rng.r == RuneError { |
| 121 |
continue |
| 122 |
} |
| 123 |
for j := 0; j <= int(rng.last-rng.first); j++ { |
| 124 |
b := rng.first + byte(j) |
| 125 |
r := rng.r + rune(j) |
| 126 |
verifyMap(t, EBCDIC, b, r) |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
func TestEBDICvsInvalid(t *testing.T) { |
| 131 |
t.Logf("EBCDIC invalid transforms") |
| 132 |
for _, rng := range mapRanges { |
| 133 |
if rng.r != RuneError { |
| 134 |
continue |
| 135 |
} |
| 136 |
for j := 0; j <= int(rng.last-rng.first); j++ { |
| 137 |
b := rng.first + byte(j) |
| 138 |
verifyToUTF(t, EBCDIC, b, RuneError) |
| 139 |
} |
| 140 |
} |
| 141 |
} |
| 142 |
|
| 143 |
func TestEBDICvsLargeUTF(t *testing.T) { |
| 144 |
t.Logf("Large UTF maps to subst char") |
| 145 |
verifyFromUTF(t, EBCDIC, '\x3F', '㿿') |
| 146 |
} |