-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtwbot_test.go
More file actions
83 lines (73 loc) · 3.63 KB
/
twbot_test.go
File metadata and controls
83 lines (73 loc) · 3.63 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
82
83
package twbot
import (
"testing"
. "gopkg.in/check.v1"
)
func Test(t *testing.T) { TestingT(t) }
type MySuite struct{}
var _ = Suite(&MySuite{})
// go test ...twbot -gocheck.vv -test.v -gocheck.f TestNAME
const (
string141 = "Wrote water woman of heart it total other. By in entirely securing suitable graceful at families improved. Zealously few furniture repulsive."
string140 = "Wrote water woman of heart it total other. By in entirely securing suitable graceful at families improved. Zealously few furniture repulsive"
string42 = "Wrote water woman of heart it total other."
url140 = "https://------------------------------------------" +
"--------------------------------------------------" +
"----------------------------------------"
)
func truncateTest(msg, archiveURL string) string {
return truncate(msg, archiveURL, len(archiveURL))
}
// twitter messages are 140 char long maximum, so we check here
// several displays when you got a message and an url to deal with.
func (s *MySuite) TestTruncate(c *C) {
trunc := truncateTest("test", "")
c.Assert(trunc, Equals, "test")
trunc = truncateTest("test", "test_url")
c.Assert(trunc, Equals, "test test_url")
trunc = truncateTest("test sentence with at least 30 characters", "test_url_long_enough________________________________________________________________________________")
c.Assert(trunc, Equals, "test sentence with at least 30 chara... test_url_long_enough________________________________________________________________________________")
trunc = truncateTest(string42, url140)
c.Assert(trunc, Equals, url140)
trunc = truncateTest(string141, "")
c.Assert(trunc, Equals, "Wrote water woman of heart it total other. "+
"By in entirely securing suitable graceful at families improved. Zealously few furniture repul...")
trunc = truncateTest(string140, "")
c.Assert(trunc, Equals, string140)
}
const (
rawtweet = "Every year it's a new cool space! Looking forward to the cozy homey atmosphere of this one! "
tweet1 = "Every year it's a new cool space! Looking forward to the cozy homey atmosphere of this one! https://t.co/CebckjFwmZ"
tweet2 = "Every year it's a new cool space! Looking forward to the cozy homey atmosphere of this one! http://t.co/CebckjFwmZ"
retweet1 = "RT @twitandrewking: Every year it's a new cool space! Looking forward to the cozy homey atmosphere of this one! https://t.co/CebckjFwmZ"
retweet2 = "RT @RonBaalke: Every year it's a new cool space! https://t.co/CebckjFwmZ Looking forward to the cozy homey atmosphere of this one! https://t.co/x5UsU…"
retweet3 = "RT @RonBaalke: Every year it's a new cool space! https://t.co/CebckjFwmZ https://t.co/CebckjFwmZ Looking forward to the cozy homey atmosphere of this one! https://t.co/x5UsU…"
retweet4 = "RT @twitandrewking: "
retweet5 = "RT @twitandrewking:"
)
func (s *MySuite) TestOriginalText(c *C) {
original, err := getOriginalText(rawtweet)
c.Assert(err, IsNil)
c.Assert(original, Equals, rawtweet)
original, err = getOriginalText(tweet1)
c.Assert(err, IsNil)
c.Assert(original, Equals, rawtweet)
original, err = getOriginalText(tweet2)
c.Assert(err, IsNil)
c.Assert(original, Equals, rawtweet)
original, err = getOriginalText(retweet1)
c.Assert(err, IsNil)
c.Assert(original, Equals, rawtweet)
original, err = getOriginalText(retweet2)
c.Assert(err, IsNil)
c.Assert(original, Equals, rawtweet)
original, err = getOriginalText(retweet3)
c.Assert(err, IsNil)
c.Assert(original, Equals, rawtweet)
original, err = getOriginalText(retweet4)
c.Assert(err, IsNil)
c.Assert(original, Equals, "")
original, err = getOriginalText(retweet5)
c.Assert(err, NotNil)
c.Assert(original, Equals, "")
}