|
| 1 | +// Copyright © 2018 VMware, Inc. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: BSD-2-Clause |
| 3 | + |
| 4 | +package util |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestMakeFluentdSafeName(t *testing.T) { |
| 13 | + assert.Equal(t, "a", MakeFluentdSafeName("a")) |
| 14 | + assert.Equal(t, "123", MakeFluentdSafeName("123")) |
| 15 | + assert.Equal(t, "", MakeFluentdSafeName("")) |
| 16 | + assert.Equal(t, "a-a", MakeFluentdSafeName("a.a")) |
| 17 | + assert.Equal(t, "a-a", MakeFluentdSafeName("a\na")) |
| 18 | + assert.Equal(t, "---", MakeFluentdSafeName(" ")) |
| 19 | +} |
| 20 | + |
| 21 | +func TestToRubyMapLiteral(t *testing.T) { |
| 22 | + assert.Equal(t, "{}", ToRubyMapLiteral(map[string]string{})) |
| 23 | + assert.Equal(t, "{'a'=>'1'}", ToRubyMapLiteral(map[string]string{ |
| 24 | + "a": "1", |
| 25 | + })) |
| 26 | + assert.Equal(t, "{'a'=>'1','z'=>'2'}", ToRubyMapLiteral(map[string]string{ |
| 27 | + "a": "1", |
| 28 | + "z": "2", |
| 29 | + })) |
| 30 | +} |
| 31 | + |
| 32 | +func TestTrim(t *testing.T) { |
| 33 | + assert.Equal(t, "a", Trim("a")) |
| 34 | + assert.Equal(t, "a", Trim(" a")) |
| 35 | + assert.Equal(t, "a", Trim("a \t ")) |
| 36 | + assert.Equal(t, "a", Trim(" \t a ")) |
| 37 | +} |
| 38 | + |
| 39 | +func TestTrimTrailingComment(t *testing.T) { |
| 40 | + assert.Equal(t, "a", TrimTrailingComment("a #12451345")) |
| 41 | + assert.Equal(t, "a", TrimTrailingComment("a")) |
| 42 | + assert.Equal(t, "a", TrimTrailingComment("a#########")) |
| 43 | +} |
0 commit comments