321 lines
6.4 KiB
Go
321 lines
6.4 KiB
Go
package text
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestUnquote(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic quoted string",
|
|
input: []byte(`"hello"`),
|
|
expected: []byte("hello"),
|
|
},
|
|
{
|
|
name: "single quotes",
|
|
input: []byte(`'world'`),
|
|
expected: []byte("world"),
|
|
},
|
|
{
|
|
name: "empty quotes",
|
|
input: []byte(`""`),
|
|
expected: []byte(""),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := Unquote(tt.input)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("Unquote() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNoop(t *testing.T) {
|
|
dst := []byte("hello")
|
|
src := []byte("world")
|
|
expected := []byte("helloworld")
|
|
|
|
result := Noop(dst, src)
|
|
if !bytes.Equal(result, expected) {
|
|
t.Errorf("Noop() = %q, want %q", result, expected)
|
|
}
|
|
}
|
|
|
|
func TestAppendQuote(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic append quote",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte(`prefix"content"`),
|
|
},
|
|
{
|
|
name: "empty dst",
|
|
dst: []byte{},
|
|
src: []byte("test"),
|
|
expected: []byte(`"test"`),
|
|
},
|
|
{
|
|
name: "empty src",
|
|
dst: []byte("start"),
|
|
src: []byte{},
|
|
expected: []byte(`start""`),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendQuote(tt.dst, tt.src, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendQuote() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestQuote(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic quote",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte(`prefix"content"`),
|
|
},
|
|
{
|
|
name: "empty dst",
|
|
dst: []byte{},
|
|
src: []byte("test"),
|
|
expected: []byte(`"test"`),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := Quote(tt.dst, tt.src)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("Quote() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendSingleQuote(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic single quote",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte("prefix'content'"),
|
|
},
|
|
{
|
|
name: "empty src",
|
|
dst: []byte("start"),
|
|
src: []byte{},
|
|
expected: []byte("start''"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendSingleQuote(tt.dst, tt.src, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendSingleQuote() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendBackticks(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic backticks",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte("prefix`content`"),
|
|
},
|
|
{
|
|
name: "empty src",
|
|
dst: []byte("start"),
|
|
src: []byte{},
|
|
expected: []byte("start``"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendBackticks(tt.dst, tt.src, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendBackticks() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendBrace(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic braces",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte("prefix(content)"),
|
|
},
|
|
{
|
|
name: "empty src",
|
|
dst: []byte("start"),
|
|
src: []byte{},
|
|
expected: []byte("start()"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendBrace(tt.dst, tt.src, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendBrace() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendParenthesis(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic parenthesis",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte("prefix{content}"),
|
|
},
|
|
{
|
|
name: "empty src",
|
|
dst: []byte("start"),
|
|
src: []byte{},
|
|
expected: []byte("start{}"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendParenthesis(tt.dst, tt.src, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendParenthesis() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendBracket(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src []byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic brackets",
|
|
dst: []byte("prefix"),
|
|
src: []byte("content"),
|
|
expected: []byte("prefix[content]"),
|
|
},
|
|
{
|
|
name: "empty src",
|
|
dst: []byte("start"),
|
|
src: []byte{},
|
|
expected: []byte("start[]"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendBracket(tt.dst, tt.src, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendBracket() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestAppendList(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
dst []byte
|
|
src [][]byte
|
|
separator byte
|
|
expected []byte
|
|
}{
|
|
{
|
|
name: "basic list with comma",
|
|
dst: []byte("list:"),
|
|
src: [][]byte{[]byte("a"), []byte("b"), []byte("c")},
|
|
separator: ',',
|
|
expected: []byte("list:a,b,c"),
|
|
},
|
|
{
|
|
name: "single item",
|
|
dst: []byte("item:"),
|
|
src: [][]byte{[]byte("single")},
|
|
separator: ',',
|
|
expected: []byte("item:single"),
|
|
},
|
|
{
|
|
name: "empty list",
|
|
dst: []byte("empty:"),
|
|
src: [][]byte{},
|
|
separator: ',',
|
|
expected: []byte("empty:"),
|
|
},
|
|
{
|
|
name: "pipe separator",
|
|
dst: []byte{},
|
|
src: [][]byte{[]byte("x"), []byte("y")},
|
|
separator: '|',
|
|
expected: []byte("x|y"),
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := AppendList(tt.dst, tt.src, tt.separator, Noop)
|
|
if !bytes.Equal(result, tt.expected) {
|
|
t.Errorf("AppendList() = %q, want %q", result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
} |