File: table_test.go

package info (click to toggle)
tea-cli 0.11.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,648 kB
  • sloc: makefile: 116; sh: 17
file content (72 lines) | stat: -rw-r--r-- 1,409 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

package print

import (
	"bytes"
	"encoding/json"
	"testing"

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

func TestToSnakeCase(t *testing.T) {
	assert.EqualValues(t, "some_test_var_at2d", toSnakeCase("SomeTestVarAt2d"))
}

func TestPrint(t *testing.T) {
	tData := &table{
		headers: []string{"A", "B"},
		values: [][]string{
			{"new a", "some bbbb"},
			{"AAAAA", "b2"},
			{"\"abc", "\"def"},
			{"'abc", "de'f"},
			{"\\abc", "'def\\"},
		},
	}

	buf := &bytes.Buffer{}

	tData.fprint(buf, "json")
	result := []struct {
		A string
		B string
	}{}
	assert.NoError(t, json.NewDecoder(buf).Decode(&result))

	if assert.Len(t, result, 5) {
		assert.EqualValues(t, "new a", result[0].A)
		assert.EqualValues(t, "some bbbb", result[0].B)
		assert.EqualValues(t, "AAAAA", result[1].A)
		assert.EqualValues(t, "b2", result[1].B)
		assert.EqualValues(t, "\"abc", result[2].A)
		assert.EqualValues(t, "\"def", result[2].B)
		assert.EqualValues(t, "'abc", result[3].A)
		assert.EqualValues(t, "de'f", result[3].B)
		assert.EqualValues(t, "\\abc", result[4].A)
		assert.EqualValues(t, "'def\\", result[4].B)
	}

	buf.Reset()

	tData.fprint(buf, "yaml")

	assert.Equal(t, `-
  A: 'new a'
  B: 'some bbbb'
-
  A: 'AAAAA'
  B: 'b2'
-
  A: '"abc'
  B: '"def'
-
  A: '''abc'
  B: 'de''f'
-
  A: '\abc'
  B: '''def\'
`, buf.String())
}