...

Source file src/golang.org/x/text/internal/export/idna/gen9.0.0_test.go

Documentation: golang.org/x/text/internal/export/idna

     1  // Copyright 2016 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  //go:build !go1.10
     6  
     7  package idna
     8  
     9  import (
    10  	"testing"
    11  	"unicode"
    12  
    13  	"golang.org/x/text/internal/gen"
    14  	"golang.org/x/text/internal/testtext"
    15  	"golang.org/x/text/internal/ucd"
    16  )
    17  
    18  func TestTables(t *testing.T) {
    19  	testtext.SkipIfNotLong(t)
    20  
    21  	lookup := func(r rune) info {
    22  		v, _ := trie.lookupString(string(r))
    23  		return info(v)
    24  	}
    25  
    26  	ucd.Parse(gen.OpenUnicodeFile("idna", "", "IdnaMappingTable.txt"), func(p *ucd.Parser) {
    27  		r := p.Rune(0)
    28  		x := lookup(r)
    29  		if got, want := x.category(), catFromEntry(p); got != want {
    30  			t.Errorf("%U:category: got %x; want %x", r, got, want)
    31  		}
    32  
    33  		mapped := false
    34  		switch p.String(1) {
    35  		case "mapped", "disallowed_STD3_mapped", "deviation":
    36  			mapped = true
    37  		}
    38  		if x.isMapped() != mapped {
    39  			t.Errorf("%U:isMapped: got %v; want %v", r, x.isMapped(), mapped)
    40  		}
    41  		if !mapped {
    42  			return
    43  		}
    44  		want := string(p.Runes(2))
    45  		got := string(x.appendMapping(nil, string(r)))
    46  		if got != want {
    47  			t.Errorf("%U:mapping: got %+q; want %+q", r, got, want)
    48  		}
    49  
    50  		if x.isMapped() {
    51  			return
    52  		}
    53  		wantMark := unicode.In(r, unicode.Mark)
    54  		gotMark := x.isModifier()
    55  		if gotMark != wantMark {
    56  			t.Errorf("IsMark(%U) = %v; want %v", r, gotMark, wantMark)
    57  		}
    58  	})
    59  
    60  	ucd.Parse(gen.OpenUCDFile("UnicodeData.txt"), func(p *ucd.Parser) {
    61  		r := p.Rune(0)
    62  		x := lookup(r)
    63  		got := x.isViramaModifier()
    64  
    65  		const cccVirama = 9
    66  		want := p.Int(ucd.CanonicalCombiningClass) == cccVirama
    67  		if got != want {
    68  			t.Errorf("IsVirama(%U) = %v; want %v", r, got, want)
    69  		}
    70  	})
    71  
    72  	ucd.Parse(gen.OpenUCDFile("extracted/DerivedJoiningType.txt"), func(p *ucd.Parser) {
    73  		r := p.Rune(0)
    74  		x := lookup(r)
    75  		if x.isMapped() {
    76  			return
    77  		}
    78  		got := x.joinType()
    79  		want := joinType[p.String(1)]
    80  		if got != want {
    81  			t.Errorf("JoinType(%U) = %x; want %x", r, got, want)
    82  		}
    83  	})
    84  }
    85  

View as plain text