...

Source file src/unicode/script_test.go

Documentation: unicode

		 1  // Copyright 2009 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 unicode_test
		 6  
		 7  import (
		 8  	"testing"
		 9  	. "unicode"
		10  )
		11  
		12  type T struct {
		13  	rune	 rune
		14  	script string
		15  }
		16  
		17  var inCategoryTest = []T{
		18  	{0x0081, "Cc"},
		19  	{0x200B, "Cf"},
		20  	{0xf0000, "Co"},
		21  	{0xdb80, "Cs"},
		22  	{0x0236, "Ll"},
		23  	{0x1d9d, "Lm"},
		24  	{0x07cf, "Lo"},
		25  	{0x1f8a, "Lt"},
		26  	{0x03ff, "Lu"},
		27  	{0x0bc1, "Mc"},
		28  	{0x20df, "Me"},
		29  	{0x07f0, "Mn"},
		30  	{0x1bb2, "Nd"},
		31  	{0x10147, "Nl"},
		32  	{0x2478, "No"},
		33  	{0xfe33, "Pc"},
		34  	{0x2011, "Pd"},
		35  	{0x301e, "Pe"},
		36  	{0x2e03, "Pf"},
		37  	{0x2e02, "Pi"},
		38  	{0x0022, "Po"},
		39  	{0x2770, "Ps"},
		40  	{0x00a4, "Sc"},
		41  	{0xa711, "Sk"},
		42  	{0x25f9, "Sm"},
		43  	{0x2108, "So"},
		44  	{0x2028, "Zl"},
		45  	{0x2029, "Zp"},
		46  	{0x202f, "Zs"},
		47  	// Unifieds.
		48  	{0x04aa, "L"},
		49  	{0x0009, "C"},
		50  	{0x1712, "M"},
		51  	{0x0031, "N"},
		52  	{0x00bb, "P"},
		53  	{0x00a2, "S"},
		54  	{0x00a0, "Z"},
		55  }
		56  
		57  var inPropTest = []T{
		58  	{0x0046, "ASCII_Hex_Digit"},
		59  	{0x200F, "Bidi_Control"},
		60  	{0x2212, "Dash"},
		61  	{0xE0001, "Deprecated"},
		62  	{0x00B7, "Diacritic"},
		63  	{0x30FE, "Extender"},
		64  	{0xFF46, "Hex_Digit"},
		65  	{0x2E17, "Hyphen"},
		66  	{0x2FFB, "IDS_Binary_Operator"},
		67  	{0x2FF3, "IDS_Trinary_Operator"},
		68  	{0xFA6A, "Ideographic"},
		69  	{0x200D, "Join_Control"},
		70  	{0x0EC4, "Logical_Order_Exception"},
		71  	{0x2FFFF, "Noncharacter_Code_Point"},
		72  	{0x065E, "Other_Alphabetic"},
		73  	{0x2065, "Other_Default_Ignorable_Code_Point"},
		74  	{0x0BD7, "Other_Grapheme_Extend"},
		75  	{0x0387, "Other_ID_Continue"},
		76  	{0x212E, "Other_ID_Start"},
		77  	{0x2094, "Other_Lowercase"},
		78  	{0x2040, "Other_Math"},
		79  	{0x216F, "Other_Uppercase"},
		80  	{0x0027, "Pattern_Syntax"},
		81  	{0x0020, "Pattern_White_Space"},
		82  	{0x06DD, "Prepended_Concatenation_Mark"},
		83  	{0x300D, "Quotation_Mark"},
		84  	{0x2EF3, "Radical"},
		85  	{0x1f1ff, "Regional_Indicator"},
		86  	{0x061F, "STerm"}, // Deprecated alias of Sentence_Terminal
		87  	{0x061F, "Sentence_Terminal"},
		88  	{0x2071, "Soft_Dotted"},
		89  	{0x003A, "Terminal_Punctuation"},
		90  	{0x9FC3, "Unified_Ideograph"},
		91  	{0xFE0F, "Variation_Selector"},
		92  	{0x0020, "White_Space"},
		93  }
		94  
		95  func TestCategories(t *testing.T) {
		96  	notTested := make(map[string]bool)
		97  	for k := range Categories {
		98  		notTested[k] = true
		99  	}
	 100  	for _, test := range inCategoryTest {
	 101  		if _, ok := Categories[test.script]; !ok {
	 102  			t.Fatal(test.script, "not a known category")
	 103  		}
	 104  		if !Is(Categories[test.script], test.rune) {
	 105  			t.Errorf("IsCategory(%U, %s) = false, want true", test.rune, test.script)
	 106  		}
	 107  		delete(notTested, test.script)
	 108  	}
	 109  	for k := range notTested {
	 110  		t.Error("category not tested:", k)
	 111  	}
	 112  }
	 113  
	 114  func TestProperties(t *testing.T) {
	 115  	notTested := make(map[string]bool)
	 116  	for k := range Properties {
	 117  		notTested[k] = true
	 118  	}
	 119  	for _, test := range inPropTest {
	 120  		if _, ok := Properties[test.script]; !ok {
	 121  			t.Fatal(test.script, "not a known prop")
	 122  		}
	 123  		if !Is(Properties[test.script], test.rune) {
	 124  			t.Errorf("IsCategory(%U, %s) = false, want true", test.rune, test.script)
	 125  		}
	 126  		delete(notTested, test.script)
	 127  	}
	 128  	for k := range notTested {
	 129  		t.Error("property not tested:", k)
	 130  	}
	 131  }
	 132  

View as plain text