github.com/hirochachacha/plua@v0.0.0-20170217012138-c82f520cc725/internal/strconv/strconv_test.go (about)

     1  package strconv
     2  
     3  import "testing"
     4  
     5  var unquoteCases = []struct {
     6  	input  string
     7  	output string
     8  }{
     9  	{`"test"`, "test"},
    10  	{`'test'`, "test"},
    11  	{`"test\nart"`, "test\nart"},
    12  	{`"\27Lua"`, "\x1bLua"},
    13  	{`"\027Lua"`, "\x1bLua"},
    14  	{`"\x19\x93\r\n\x1a\n"`, "\x19\x93\r\n\x1a\n"},
    15  	{`"\"test\""`, `"test"`},
    16  	{`"\'test\'"`, `'test'`},
    17  	{`"'test'"`, `'test'`},
    18  	{`"\u{0}\u{00000000}\x00\0"`, "\x00\x00\x00\x00"},
    19  }
    20  
    21  func TestUnquote(t *testing.T) {
    22  	for i, test := range unquoteCases {
    23  		got, err := Unquote(test.input)
    24  		if err != nil {
    25  			t.Fatal(err)
    26  		}
    27  		if got != test.output {
    28  			t.Errorf("%d: got %v, want %v", i+1, got, test.output)
    29  		}
    30  	}
    31  }
    32  
    33  var escapeCases = []struct {
    34  	input  string
    35  	output string
    36  }{
    37  	{"test", "test"},
    38  	{"test\x1bart", "test\\027art"},
    39  	{"test\x10art", "test\\016art"},
    40  	{"test\xfeart", "test\\254art"},
    41  	{"test\xffart", "test\\255art"},
    42  }
    43  
    44  func TestEscape(t *testing.T) {
    45  	for i, test := range escapeCases {
    46  		got := Escape(test.input)
    47  		if got != test.output {
    48  			t.Errorf("%d: got %v, want %v", i+1, got, test.output)
    49  		}
    50  	}
    51  }