File: transform_test.go

package info (click to toggle)
golang-github-jdkato-prose 1.1.0%2Bgit20171031.e27abfd-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,848 kB
  • sloc: python: 115; makefile: 55; sh: 21
file content (81 lines) | stat: -rw-r--r-- 1,687 bytes parent folder | download | duplicates (3)
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
72
73
74
75
76
77
78
79
80
81
package transform

import (
	"encoding/json"
	"fmt"
	"path/filepath"
	"testing"

	"github.com/jdkato/prose/internal/util"
	"github.com/stretchr/testify/assert"
)

var testdata = filepath.Join("..", "testdata")

type testFormat struct {
	Input    string
	None     string
	Snake    string
	Param    string
	Dot      string
	Constant string
	Pascal   string
	Camel    string
}

func TestTransform(t *testing.T) {
	tests := make([]testFormat, 0)
	cases := util.ReadDataFile(filepath.Join(testdata, "case.json"))

	util.CheckError(json.Unmarshal(cases, &tests))
	for _, test := range tests {
		assert.Equal(t, test.None, Simple(test.Input))
		assert.Equal(t, test.Snake, Snake(test.Input))
		assert.Equal(t, test.Param, Dash(test.Input))
		assert.Equal(t, test.Dot, Dot(test.Input))
		assert.Equal(t, test.Constant, Constant(test.Input))
		assert.Equal(t, test.Pascal, Pascal(test.Input))
		assert.Equal(t, test.Camel, Camel(test.Input))
	}
}

func ExampleNewTitleConverter() {
	tc := NewTitleConverter(APStyle)
	fmt.Println(tc.Title("the last of the mohicans"))
	// Output: The Last of the Mohicans
}

func ExampleSimple() {
	fmt.Println(Simple("test string"))
	// Output: test string
}

func ExampleDash() {
	fmt.Println(Dash("test string"))
	// Output: test-string
}

func ExampleSnake() {
	fmt.Println(Snake("test string"))
	// Output: test_string
}

func ExampleDot() {
	fmt.Println(Dot("test string"))
	// Output: test.string
}

func ExampleConstant() {
	fmt.Println(Constant("test string"))
	// Output: TEST_STRING
}

func ExamplePascal() {
	fmt.Println(Pascal("test string"))
	// Output: TestString
}

func ExampleCamel() {
	fmt.Println(Camel("test string"))
	// Output: testString
}