github.com/diamondburned/arikawa/v2@v2.1.0/bot/extras/shellwords/shellwords_test.go (about)

     1  package shellwords
     2  
     3  import (
     4  	"reflect"
     5  	"testing"
     6  )
     7  
     8  type wordsTest struct {
     9  	line  string
    10  	args  []string
    11  	doErr bool
    12  }
    13  
    14  func TestParse(t *testing.T) {
    15  	var tests = []wordsTest{
    16  		{
    17  			"",
    18  			nil,
    19  			false,
    20  		},
    21  		{
    22  			"'",
    23  			nil,
    24  			true,
    25  		},
    26  		{
    27  			`this is a "te""st"`,
    28  			[]string{"this", "is", "a", "test"},
    29  			false,
    30  		},
    31  		{
    32  			`hanging "quote`,
    33  			[]string{"hanging", "quote"},
    34  			true,
    35  		},
    36  		{
    37  			`Hello, 世界`,
    38  			[]string{"Hello,", "世界"},
    39  			false,
    40  		},
    41  		{
    42  			"this is `inline code`",
    43  			[]string{"this", "is", "inline code"},
    44  			false,
    45  		},
    46  		{
    47  			"how about a ```go\npackage main\n```\ngo code?",
    48  			[]string{"how", "about", "a", "go\npackage main\n", "go", "code?"},
    49  			false,
    50  		},
    51  		{
    52  			"this should not crash `",
    53  			[]string{"this", "should", "not", "crash"},
    54  			true,
    55  		},
    56  		{
    57  			"this should not crash '",
    58  			[]string{"this", "should", "not", "crash"},
    59  			true,
    60  		},
    61  		{
    62  			"iPhone “double quoted” text",
    63  			[]string{"iPhone", "double quoted", "text"},
    64  			true,
    65  		},
    66  		{
    67  			"iPhone ‘single quoted’ text",
    68  			[]string{"iPhone", "single quoted", "text"},
    69  			true,
    70  		},
    71  	}
    72  
    73  	for _, test := range tests {
    74  		w, err := Parse(test.line)
    75  		if err != nil && !test.doErr {
    76  			t.Errorf("Error at %q: %v", test.line, err)
    77  			continue
    78  		}
    79  
    80  		if !reflect.DeepEqual(w, test.args) {
    81  			t.Errorf("Inequality:\n%#v !=\n%#v", w, test.args)
    82  		}
    83  	}
    84  }