aboutsummaryrefslogtreecommitdiffstats
path: root/skate/map_test.go
blob: a439d3352c02fd9bbe95782f6b6948a72f74ab74 (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package skate

import (
	"reflect"
	"testing"
)

func TestMapperTitle(t *testing.T) {
	var cases = []struct {
		b      string
		result []string
		err    error
	}{
		{
			b:      "{}",
			result: []string{"", "{}"},
			err:    nil,
		},
		{
			b:      `{"title": "Hello"}`,
			result: []string{"Hello", `{"title": "Hello"}`},
			err:    nil,
		},
		{
			b: `{"title": "This is not_**normalized"}`,
			result: []string{
				"This is not_**normalized",
				`{"title": "This is not_**normalized"}`,
			},
			err: nil,
		},
	}
	for _, c := range cases {
		result, err := MapperTitle([]byte(c.b))
		if !reflect.DeepEqual(prettySlice(result), c.result) {
			t.Fatalf("got %v, want %v", result, c.result)
		}
		if err != c.err {
			t.Fatalf("got %v, want %v", err, c.err)
		}
	}
}

func TestMapperTitleNormalized(t *testing.T) {
	var cases = []struct {
		b      string
		result []string
		err    error
	}{
		{
			b:      "{}",
			result: []string{"", "{}"},
			err:    nil,
		},
		{
			b:      `{"title": "Hello"}`,
			result: []string{"hello", `{"title": "Hello"}`},
			err:    nil,
		},
		{
			b: `{"title": "This is ..._**normalized"}`,
			result: []string{
				"thisis_normalized",
				`{"title": "This is ..._**normalized"}`,
			},
			err: nil,
		},
	}
	for _, c := range cases {
		result, err := MapperTitleNormalized([]byte(c.b))
		if !reflect.DeepEqual(prettySlice(result), c.result) {
			t.Fatalf("got %v, want %v", prettySlice(result), c.result)
		}
		if err != c.err {
			t.Fatalf("got %v, want %v", err, c.err)
		}
	}
}

func TestMapperTitleNysiis(t *testing.T) {
	var cases = []struct {
		b      string
		result []string
		err    error
	}{
		{
			b:      "{}",
			result: []string{"", "{}"},
			err:    nil,
		},
		{
			b:      `{"title": "Hello"}`,
			result: []string{"HAL", `{"title": "Hello"}`},
			err:    nil,
		},
		{
			b: `{"title": "This is ..._**normalized"}`,
			result: []string{
				"TASASN",
				`{"title": "This is ..._**normalized"}`,
			},
			err: nil,
		},
	}
	for _, c := range cases {
		result, err := MapperTitleNysiis([]byte(c.b))
		if !reflect.DeepEqual(prettySlice(result), c.result) {
			t.Fatalf("got %v, want %v", prettySlice(result), c.result)
		}
		if err != c.err {
			t.Fatalf("got %v, want %v", err, c.err)
		}
	}
}

func TestMapperTitleSandcrawler(t *testing.T) {
	var cases = []struct {
		b      string
		result []string
		err    error
	}{
		{
			b:      "{}",
			result: []string{"", "{}"},
			err:    nil,
		},
		{
			b:      `{"title": "Hello"}`,
			result: []string{"hello", `{"title": "Hello"}`},
			err:    nil,
		},
		{
			b: `{"title": "This is ..._**normalized"}`,
			result: []string{
				"thisisnormalized",
				`{"title": "This is ..._**normalized"}`,
			},
			err: nil,
		},
	}
	for _, c := range cases {
		result, err := MapperTitleSandcrawler([]byte(c.b))
		if !reflect.DeepEqual(prettySlice(result), c.result) {
			t.Fatalf("got %v, want %v", prettySlice(result), c.result)
		}
		if err != c.err {
			t.Fatalf("got %v, want %v", err, c.err)
		}
	}
}

func prettySlice(p [][]byte) (result []string) {
	result = make([]string, len(p))
	for i, v := range p {
		result[i] = string(v)
	}
	return result
}