-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils_test.go
71 lines (65 loc) · 2.36 KB
/
utils_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
63
64
65
66
67
68
69
70
71
// Copyright 2011, Shelby Ramsey. All rights reserved.
// Use of this code is governed by a BSD license that can be
// found in the LICENSE.txt file.
package sipparser
import (
"testing"
)
func TestCleanWs(t *testing.T) {
s := " white space .. "
if cleanWs(s) != "white space .." {
t.Errorf("[TestCleanWs] Error from cleanWs. Got unexpected result.")
}
s = "white space"
if cleanWs(s) != "white space" {
t.Errorf("[TestCleanWs] Error from cleanWs. Got unexpected result.")
}
}
func TestCleanBrack(t *testing.T) {
s := "<sip:[email protected]>"
if cleanBrack(s) != "sip:[email protected]" {
t.Errorf("[TestCleanBrack] Error cleaning bracks from \"<sip:[email protected]>\".")
}
s = "<sip:[email protected]>;param=foo?header=boo"
if cleanBrack(s) != "sip:[email protected];param=foo?header=boo" {
t.Errorf("[TestCleanBrack] Error cleaning bracks from \"<sip:[email protected]>;param=foo?header=boo\".")
}
}
func TestGetName(t *testing.T) {
s := "\"name\" <sip:[email protected]>"
name, _ := getName(s)
if name != "name" {
t.Errorf("[TestGetName] Error getting name from getName for: \"name\" <sip:[email protected]>")
}
s = "<sip:[email protected]>"
name, _ = getName(s)
if name != "" {
t.Errorf("[TestGetName] Received a name for a string without one from getName.")
}
s = "Anonymous <sip:[email protected]>;tag=hyh8"
name, _ = getName(s)
if name != "Anonymous" {
t.Errorf("[TestGetName] Error parsing string: Anonymous <sip:[email protected]>;tag=hyh8. Should have gotten name: \"Anonymous\" but received: \"%s\".", name)
}
}
func TestGetCommaSeperated(t *testing.T) {
s := "foo "
cs := getCommaSeperated(s)
if cs != nil {
t.Errorf("[TestGetCommaSeperated] Error with string: \"foo\". getCommaSeperated should have returned nil.")
}
s = "foo , bar"
cs = getCommaSeperated(s)
if cs == nil {
t.Errorf("[TestGetCommaSeperated] Error with string: \"foo , bar\". getCommaSeperated should have returned a list of strings. Returned nil.")
}
if len(cs) != 2 {
t.Errorf("[TestGetCommaSeperated] Error with string: \"foo , bar\". Returned list but length should be 2.")
}
if cs[0] != "foo" {
t.Errorf("[TestGetCommaSeperated] Error with string: \"foo , bar\". Returned list pos[0] should be \"foo\" but received: " + cs[0])
}
if cs[1] != "bar" {
t.Errorf("[TestGetCommaSeperated] Error with string: \"foo , bar\". Returned list pos[1] should be \"bar\" but received: " + cs[1])
}
}