forked from resyzedev/consulta-operadora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
62 lines (54 loc) · 1.36 KB
/
main_test.go
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
/* ==> go test */
package main
import (
"consulta-operadora/funcs"
"fmt"
"html"
"os"
"strings"
"testing"
)
// GetStr Returns empty string if no start string found
func GetStr(str string, start string, end string) (result string, found bool) {
s := strings.Index(str, start)
if s == -1 {
return result, false
}
newS := str[s+len(start):]
e := strings.Index(newS, end)
if e == -1 {
return result, false
}
result = newS[:e]
return result, true
}
func TestGetStr(t *testing.T) {
body := `<span class="lead laranja" id="span_tempo">11</span>`
result, found := GetStr(body, `<span class="lead laranja" id="span_tempo">`, `</span>`)
if !found {
t.Error("string not found")
os.Exit(0)
}
t.Error(result)
}
func TestContains(t *testing.T) {
str := `<span class="lead laranja">Aguarde</span>`
if strings.Contains(str, "Aguarde") {
t.Error("found")
} else {
t.Error("not found")
}
}
func TestChar(t *testing.T) {
operadora := ` Telef�nica Brasil (Móvel/SMP)`
portado := ` NÃO`
remove_spaces_operadora := strings.TrimSpace(operadora)
remove_html_entities_operadora := html.UnescapeString(remove_spaces_operadora)
fmt.Println(remove_html_entities_operadora)
fmt.Println("----")
fmt.Println(strings.TrimSpace(html.UnescapeString(portado)))
}
func TestRegex(t *testing.T) {
test := funcs.IsValidPhone("11975738658")
fmt.Println(test)
}