You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

51 line
1.2 KiB

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