Selaa lähdekoodia

Support new method for show stars

Toni Fadjukoff 6 vuotta sitten
vanhempi
commit
7431e5dc74
2 muutettua tiedostoa jossa 40 lisäystä ja 0 poistoa
  1. 5 0
      bot.go
  2. 35 0
      bot_test.go

+ 5 - 0
bot.go Näytä tiedosto

@@ -146,6 +146,11 @@ func parseScore(line string) string {
146 146
 	if score == "" {
147 147
 		return score
148 148
 	}
149
+	rating, _ := regexp.Compile("^\\{\\{Rating\\|\\d([.,]\\d)\\|5\\}\\}?$")
150
+	if rating.MatchString(score) {
151
+		score = strings.Replace(score, "{{Rating|", "", 1)
152
+		score = strings.Replace(score, "|5}}", "", 1)
153
+	}
149 154
 	number, _ := regexp.Compile("^\\d([.,]\\d)?$")
150 155
 	if number.MatchString(score) {
151 156
 		return strings.Replace(score, ",", ".", 1)

+ 35 - 0
bot_test.go Näytä tiedosto

@@ -0,0 +1,35 @@
1
+package main
2
+
3
+import "testing"
4
+
5
+func testParseScore(t *testing.T) {
6
+	s := parseScore("[[Image:1.png]][[Image:1.png]][[Image:1.png]][[Image:0.png]][[Image:0.png]]")
7
+	if s != "3" {
8
+		t.Fail()
9
+	}
10
+
11
+	s = parseScore("{{Rating|3|5}}")
12
+	if s != "3" {
13
+		t.Fail()
14
+	}
15
+	s = parseScore("{{Rating|4.5|5}}")
16
+	if s != "4.5" {
17
+		t.Fail()
18
+	}
19
+	s = parseScore("**")
20
+	if s != "2" {
21
+		t.Fail()
22
+	}
23
+	s = parseScore("4½")
24
+	if s != "4.5" {
25
+		t.Fail()
26
+	}
27
+	s = parseScore("1.5")
28
+	if s != "1.5" {
29
+		t.Fail()
30
+	}
31
+	s = parseScore("2,5")
32
+	if s != "2.5" {
33
+		t.Fail()
34
+	}
35
+}