config-lsp/server/common/parser/strings_test.go

168 lines
3.1 KiB
Go

package parser
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestStringsSingleWortQuotedFullFeatures(
t *testing.T,
) {
input := `hello "world"`
expected := ParsedString{
Raw: input,
Value: "hello world",
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsFullyQuotedFullFeatures(
t *testing.T,
) {
input := `"hello world"`
expected := ParsedString{
Raw: input,
Value: "hello world",
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsMultipleQuotesFullFeatures(
t *testing.T,
) {
input := `hello "world goodbye"`
expected := ParsedString{
Raw: input,
Value: "hello world goodbye",
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsSimpleEscapedFullFeatures(
t *testing.T,
) {
input := `hello \"world`
expected := ParsedString{
Raw: input,
Value: `hello "world`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsEscapedQuotesFullFeatures(
t *testing.T,
) {
input := `hello \"world\"`
expected := ParsedString{
Raw: input,
Value: `hello "world"`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsQuotesAndEscapedFullFeatures(
t *testing.T,
) {
input := `hello "world how\" are you"`
expected := ParsedString{
Raw: input,
Value: `hello world how" are you`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsIncompleteQuotesFullFeatures(
t *testing.T,
) {
input := `hello "world`
expected := ParsedString{
Raw: input,
Value: `hello "world`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsIncompleteQuoteEscapedFullFeatures(
t *testing.T,
) {
input := `hello "world\"`
expected := ParsedString{
Raw: input,
Value: `hello "world"`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsIncompleteQuotes2FullFeatures(
t *testing.T,
) {
input := `hello "world how" "are you`
expected := ParsedString{
Raw: input,
Value: `hello world how "are you`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}
func TestStringsIncompleteQuotes3FullFeatures(
t *testing.T,
) {
input := `hello "world how are you`
expected := ParsedString{
Raw: input,
Value: `hello "world how are you`,
}
actual := ParseRawString(input, FullFeatures)
if !(cmp.Equal(expected, actual)) {
t.Errorf("Expected %v, got %v", expected, actual)
}
}