File: kebab_test.go

package info (click to toggle)
golang-github-stoewer-go-strcase 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 116 kB
  • sloc: makefile: 2
file content (56 lines) | stat: -rw-r--r-- 1,756 bytes parent folder | download
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
// Copyright (c) 2017, A. Stoewer <adrian.stoewer@rz.ifi.lmu.de>
// All rights reserved.

package strcase

import (
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestKebabCase(t *testing.T) {
	data := map[string]string{
		"":                           "",
		"F":                          "f",
		"Foo":                        "foo",
		"FooB":                       "foo-b",
		"FooID":                      "foo-id",
		" FooBar\t":                  "foo-bar",
		"HTTPStatusCode":             "http-status-code",
		"ParseURL.DoParse":           "parse-url.do-parse",
		"Convert Space":              "convert-space",
		"Convert-dash":               "convert-dash",
		"Skip___MultipleUnderscores": "skip-multiple-underscores",
		"Skip   MultipleSpaces":      "skip-multiple-spaces",
		"Skip---MultipleDashes":      "skip-multiple-dashes",
	}

	for camel, snake := range data {
		converted := KebabCase(camel)
		assert.Equal(t, snake, converted)
	}
}

func TestUpperKebabCase(t *testing.T) {
	data := map[string]string{
		"":                           "",
		"F":                          "F",
		"Foo":                        "FOO",
		"FooB":                       "FOO-B",
		"FooID":                      "FOO-ID",
		" FooBar\t":                  "FOO-BAR",
		"HTTPStatusCode":             "HTTP-STATUS-CODE",
		"ParseURL.DoParse":           "PARSE-URL.DO-PARSE",
		"Convert Space":              "CONVERT-SPACE",
		"Convert-dash":               "CONVERT-DASH",
		"Skip___MultipleUnderscores": "SKIP-MULTIPLE-UNDERSCORES",
		"Skip   MultipleSpaces":      "SKIP-MULTIPLE-SPACES",
		"Skip---MultipleDashes":      "SKIP-MULTIPLE-DASHES",
	}

	for camel, snake := range data {
		converted := UpperKebabCase(camel)
		assert.Equal(t, snake, converted)
	}
}