| 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 |
"golang.org/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 identifier class. |
| 17 |
func TestClassContains(t *testing.T) { |
| 18 |
tests := []struct { |
| 19 |
name string |
| 20 |
class *class |
| 21 |
allowed []rune |
| 22 |
disallowed []rune |
| 23 |
}{ |
| 24 |
{ |
| 25 |
name: "Identifier", |
| 26 |
class: identifier, |
| 27 |
allowed: []rune("Aa0\u0021\u007e\u00df\u3007"), |
| 28 |
disallowed: []rune("\u2150\u2100\u2200\u3164\u2190\u2600\u303b\u1e9b"), |
| 29 |
}, |
| 30 |
{ |
| 31 |
name: "Freeform", |
| 32 |
class: freeform, |
| 33 |
allowed: []rune("Aa0\u0021\u007e\u00df\u3007 \u2150\u2100\u2200\u2190\u2600\u1e9b"), |
| 34 |
disallowed: []rune("\u3164\u303b"), |
| 35 |
}, |
| 36 |
} |
| 37 |
|
| 38 |
for _, rt := range tests { |
| 39 |
for _, r := range rt.allowed { |
| 40 |
if !rt.class.Contains(r) { |
| 41 |
t.Errorf("Class %s should contain %U", rt.name, r) |
| 42 |
} |
| 43 |
} |
| 44 |
for _, r := range rt.disallowed { |
| 45 |
if rt.class.Contains(r) { |
| 46 |
t.Errorf("Class %s should not contain %U", rt.name, r) |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
} |