| 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 width |
| 6 |
|
| 7 |
import ( |
| 8 |
"testing" |
| 9 |
|
| 10 |
"golang.org/x/text/internal/testtext" |
| 11 |
) |
| 12 |
|
| 13 |
const ( |
| 14 |
loSurrogate = 0xD800 |
| 15 |
hiSurrogate = 0xDFFF |
| 16 |
) |
| 17 |
|
| 18 |
func TestTables(t *testing.T) { |
| 19 |
testtext.SkipIfNotLong(t) |
| 20 |
|
| 21 |
runes := map[rune]Kind{} |
| 22 |
getWidthData(func(r rune, tag elem, _ rune) { |
| 23 |
runes[r] = tag.kind() |
| 24 |
}) |
| 25 |
for r := rune(0); r < 0x10FFFF; r++ { |
| 26 |
if loSurrogate <= r && r <= hiSurrogate { |
| 27 |
continue |
| 28 |
} |
| 29 |
p := LookupRune(r) |
| 30 |
if got, want := p.Kind(), runes[r]; got != want { |
| 31 |
t.Errorf("Kind of %U was %s; want %s.", r, got, want) |
| 32 |
} |
| 33 |
want, mapped := foldRune(r) |
| 34 |
if got := p.Folded(); (got == 0) == mapped || got != 0 && got != want { |
| 35 |
t.Errorf("Folded(%U) = %U; want %U", r, got, want) |
| 36 |
} |
| 37 |
want, mapped = widenRune(r) |
| 38 |
if got := p.Wide(); (got == 0) == mapped || got != 0 && got != want { |
| 39 |
t.Errorf("Wide(%U) = %U; want %U", r, got, want) |
| 40 |
} |
| 41 |
want, mapped = narrowRune(r) |
| 42 |
if got := p.Narrow(); (got == 0) == mapped || got != 0 && got != want { |
| 43 |
t.Errorf("Narrow(%U) = %U; want %U", r, got, want) |
| 44 |
} |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
// TestAmbiguous verifies that ambiguous runes with a mapping always map to |
| 49 |
// a halfwidth rune. |
| 50 |
func TestAmbiguous(t *testing.T) { |
| 51 |
for r, m := range mapRunes { |
| 52 |
if m.e != tagAmbiguous { |
| 53 |
continue |
| 54 |
} |
| 55 |
if k := mapRunes[m.r].e.kind(); k != EastAsianHalfwidth { |
| 56 |
t.Errorf("Rune %U is ambiguous and maps to a rune of type %v", r, k) |
| 57 |
} |
| 58 |
} |
| 59 |
} |