github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/golang/text/secure/precis/class_test.go (about)

     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 precis
     6  
     7  import (
     8  	"testing"
     9  
    10  	"github.com/insionng/yougam/libraries/x/text/runes"
    11  )
    12  
    13  // Compile-time regression test to ensure that Class is a Set
    14  var _ runes.Set = (*class)(nil)
    15  
    16  // Ensure that certain characters are (or are not) in the identifer class.
    17  func TestClassContains(t *testing.T) {
    18  	tests := []struct {
    19  		class      *class
    20  		allowed    []rune
    21  		disallowed []rune
    22  	}{
    23  		{
    24  			class:      identifier,
    25  			allowed:    []rune("Aa0\u0021\u007e\u00df\u3007"),
    26  			disallowed: []rune("\u2150\u2100\u2200\u3164\u2190\u2600\u303b"),
    27  		},
    28  		{
    29  			class:      freeform,
    30  			allowed:    []rune("Aa0\u0021\u007e\u00df\u3007 \u2150\u2100\u2200\u2190\u2600"),
    31  			disallowed: []rune("\u3164\u303b"),
    32  		},
    33  	}
    34  
    35  	for _, rt := range tests {
    36  		for _, r := range rt.allowed {
    37  			if !rt.class.Contains(r) {
    38  				t.Errorf("Class %d should contain \"%U\"", rt.class, r)
    39  			}
    40  		}
    41  		for _, r := range rt.disallowed {
    42  			if rt.class.Contains(r) {
    43  				t.Errorf("Class %d should not contain \"%U\"", rt.class, r)
    44  			}
    45  		}
    46  	}
    47  }