-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathdecode_test.go
More file actions
81 lines (76 loc) · 1.7 KB
/
decode_test.go
File metadata and controls
81 lines (76 loc) · 1.7 KB
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
package main
import (
"testing"
)
func TestToString(t *testing.T) {
testCases := []conversion{
{
from: "Title",
to: "Title",
},
{
from: "This is a {Title}",
to: "This is a Title",
},
{
from: "This is a {Title}",
to: "This is a Title",
},
{
from: `{\#h00t}: Censorship Resistant Microblogging`,
to: `#h00t: Censorship Resistant Microblogging`,
},
{
from: "``Good'' Worms and Human Rights",
to: "“Good” Worms and Human Rights",
},
{
from: "An Analysis of {China}'s ``{Great Cannon}''",
to: "An Analysis of China’s “Great Cannon”",
},
{
from: `lib$\cdot$erate, (n):`,
to: `lib·erate, (n):`,
},
{
from: "Well -- Exploring the {Great} {Firewall}'s Poisoned {DNS}",
to: "Well – Exploring the Great Firewall’s Poisoned DNS",
},
}
for _, test := range testCases {
to := decodeTitle(test.from)
if to != test.to {
t.Errorf("Expected\n%s\ngot\n%s", test.to, to)
}
}
}
func TestDecodeAuthors(t *testing.T) {
testCases := []conversion{
{ // Multiple authors should be separated by commas.
from: "John Doe and Jane Doe",
to: "John Doe, Jane Doe",
},
{ // Single authors should remain as-is.
from: "John Doe",
to: "John Doe",
},
{ // Single-name authors should remain as-is.
from: "John and Jane",
to: "John, Jane",
},
{ // Non-ASCII characters should be unaffected.
from: "Jóhn Doe",
to: "Jóhn Doe",
},
{ // Apostrophes should be replaced with the right single quote.
from: "John O'Brian",
to: "John O’Brian",
},
}
for _, test := range testCases {
to := decodeAuthors(test.from)
if to != test.to {
t.Errorf("Expected\n%s\ngot\n%s", test.to, to)
}
}
}