-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
60 lines (52 loc) · 1.75 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
package tfmt
import (
"github.com/christianhujer/assert"
"github.com/christianhujer/intercept"
"strings"
"testing"
)
func TestTsprintf(t *testing.T) {
expected := "foo bar"
actual := Tsprintf("%{p1}s %{p2}s", map[string]interface{}{"p1": "foo", "p2": "bar"})
assert.Equals(t, expected, actual)
}
func TestTsprintfDoesNotFormatAgain(t *testing.T) {
expected := "%s bar"
actual := Tsprintf("%{p1}s %{p2}s", map[string]interface{}{"p1": "%s", "p2": "bar"})
assert.Equals(t, expected, actual)
}
func TestTfprintf(t *testing.T) {
expected := "foo bar"
builder := strings.Builder{}
Tfprintf(&builder, "%{p1}s %{p2}s", map[string]interface{}{"p1": "foo", "p2": "bar"})
assert.Equals(t, expected, builder.String())
}
func TestTfprintfDoesNotFormatAgain(t *testing.T) {
expected := "%s bar"
builder := strings.Builder{}
Tfprintf(&builder, "%{p1}s %{p2}s", map[string]interface{}{"p1": "%s", "p2": "bar"})
assert.Equals(t, expected, builder.String())
}
func TestTprintf(t *testing.T) {
expected := "foo bar"
stdout, stderr, err := intercept.Strings(func() { Tprintf("%{p1}s %{p2}s", map[string]interface{}{"p1": "foo", "p2": "bar"}) })
if err != nil {
t.Error(err)
}
assert.Equals(t, expected, *stdout)
assert.Equals(t, "", *stderr)
}
func TestTprintfDoesNotFormatAgain(t *testing.T) {
expected := "%s bar"
stdout, stderr, err := intercept.Strings(func() { Tprintf("%{p1}s %{p2}s", map[string]interface{}{"p1": "%s", "p2": "bar"}) })
if err != nil {
t.Error(err)
}
assert.Equals(t, expected, *stdout)
assert.Equals(t, "", *stderr)
}
//func TestTsprintfDoesNotReplaceRecursively(t *testing.T) {
// expected := "%{p2}s bar"
// actual := Tsprintf("%{p1}s %{p2}s", map[string]interface{}{"p1": "%{p2}s", "p2": "bar"})
// assert.Equals(t, expected, actual)
//}