summaryrefslogtreecommitdiff
path: root/test/integration/strings_test.go
blob: c8843de5fa58bd91253a1df4b47078e178eeb1f1 (plain)
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
//+build integration
//+build !windows

package integration

import (
	. "gopkg.in/check.v1"

	"github.com/gotestyourself/gotestyourself/icmd"
)

type StringsSuite struct{}

var _ = Suite(&StringsSuite{})

func (s *StringsSuite) TestIndent(c *C) {
	result := icmd.RunCommand(GomplateBin, "-i",
		`{{ strings.Indent "   " "hello world" }}
{{ "hello\nmultiline\nworld" | indent 2 "-" }}
{{ "foo\nbar" | strings.Indent 2 }}
    {{"hello\nworld" | strings.Indent 5 | strings.TrimSpace }}
`)
	result.Assert(c, icmd.Expected{ExitCode: 0, Out: `   hello world
--hello
--multiline
--world
  foo
  bar
    hello
     world`})
}

func (s *StringsSuite) TestRepeat(c *C) {
	result := icmd.RunCommand(GomplateBin, "-i",
		`ba{{ strings.Repeat 2 "na" }}`)
	result.Assert(c, icmd.Expected{ExitCode: 0, Out: `banana`})

	result = icmd.RunCommand(GomplateBin, "-i",
		`ba{{ strings.Repeat 9223372036854775807 "na" }}`)
	result.Assert(c, icmd.Expected{ExitCode: 1, Out: `too long: causes overflow`})

	result = icmd.RunCommand(GomplateBin, "-i",
		`ba{{ strings.Repeat -1 "na" }}`)
	result.Assert(c, icmd.Expected{ExitCode: 1, Out: `negative count`})
}

func (s *StringsSuite) TestSlug(c *C) {
	result := icmd.RunCommand(GomplateBin, "-i",
		`{{ strings.Slug "Hellö, Wôrld! Free @ last..." }}`)
	result.Assert(c, icmd.Expected{ExitCode: 0, Out: `hello-world-free-at-last`})
}