miller/pkg/lib/unbackslash_test.go
John Kerl 5eb40c9e7b
Multiple style updates (#1974)
* Comment style

* IRecordTransformer -> RecordTransfomer

* make fmt

* else-return style mod

* snake-case -> camel-case

* Remove redundant err = nil and similar zero-value initializations.

* redundant break;

* bugfix

* neaten

* typofix

* simplify/standardize init of zero-length slices

* Standardize fmt.Fprintf w/ errors

* fix double print of "mlr:"

* neatening

* Uniformize error messages

* make docs

* avoid shadowing package names

* shorten some receiver names
2026-02-16 15:49:21 -05:00

43 lines
1 KiB
Go

// Most Miller tests (thousands of them) are command-line-driven via
// mlr regtest. Here are some cases needing special focus.
package lib
import (
"testing"
)
type tDataForUnbackslash struct {
input string
expectedOutput string
}
// Note we are here dealing with Go's backslashing conventions.
// At the Miller user-space level this is simply "\t" -> TAB, etc.
var dataForUnbackslash = []tDataForUnbackslash{
{"", ""},
{"abcde", "abcde"},
{`\1`, `\1`},
{`a\tb\tc`, "a\tb\tc"},
{`a\fb\rc`, "a\fb\rc"},
{`a"b"c`, `a"b"c`},
{`a\"b\"c`, `a"b"c`},
{`a\102c`, `aBc`},
{`a\x42c`, `aBc`},
{`[\101\102\103]`, `[ABC]`},
{`[\x44\x45\x46]`, `[DEF]`},
{`\u2766`, ``},
{`\U00010877`, `𐡷`},
{`a\u0062c`, `abc`},
}
func TestUnbackslash(t *testing.T) {
for i, entry := range dataForUnbackslash {
actualOutput := UnbackslashStringLiteral(entry.input)
if actualOutput != entry.expectedOutput {
t.Fatalf("case %d input \"%s\" expected \"%s\" got \"%s\"\n",
i, entry.input, entry.expectedOutput, actualOutput,
)
}
}
}