File: unicodeclass_test.go

package info (click to toggle)
golang-github-mattn-go-unicodeclass 0.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 88 kB
  • sloc: makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,134 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package unicodeclass

import (
	"bufio"
	"reflect"
	"strings"
	"testing"
)

func TestIs(t *testing.T) {
	tests := []struct {
		r    rune
		want Class
	}{
		{'1', Word},
		{'a', Word},
		{'世', CJKIdeographs},
		{',', Punctation},
		{' ', Blank},
	}
	for _, test := range tests {
		got := Is(test.r)
		if got != test.want {
			t.Fatalf("want %v but %v: %q(%d)", test.want, got, string(test.r), test.r)
		}
	}
}

func TestUnicodeSplit(t *testing.T) {
	scan := bufio.NewScanner(strings.NewReader("本日は晴天なり"))
	scan.Split(SplitClass)
	var got []string
	for scan.Scan() {
		got = append(got, scan.Text())
	}
	want := []string{"本日", "は", "晴天", "なり"}
	if !reflect.DeepEqual(got, want) {
		t.Fatalf("want %v but %v", want, got)
	}
}

func TestSplit(t *testing.T) {
	tests := []struct {
		s    string
		want []string
	}{
		{"本日は晴天なり", []string{"本日", "は", "晴天", "なり"}},
		{"佐藤B作", []string{"佐藤", "B", "作"}},
	}
	for _, test := range tests {
		got := Split(test.s)
		if !reflect.DeepEqual(got, test.want) {
			t.Fatalf("want %v but %v for %q", test.want, got, test.s)
		}
	}
}