github.com/richardwilkes/toolbox@v1.121.0/cmdline/parse_test.go (about)

     1  // Copyright (c) 2016-2024 by Richard A. Wilkes. All rights reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the Mozilla Public
     4  // License, version 2.0. If a copy of the MPL was not distributed with
     5  // this file, You can obtain one at http://mozilla.org/MPL/2.0/.
     6  //
     7  // This Source Code Form is "Incompatible With Secondary Licenses", as
     8  // defined by the Mozilla Public License, version 2.0.
     9  
    10  package cmdline_test
    11  
    12  import (
    13  	"testing"
    14  
    15  	"github.com/richardwilkes/toolbox/check"
    16  	"github.com/richardwilkes/toolbox/cmdline"
    17  )
    18  
    19  func TestParseCommandLine(t *testing.T) {
    20  	tests := []struct {
    21  		input    string
    22  		expected []string
    23  	}{
    24  		{"hello world", []string{"hello", "world"}},
    25  		{`hello "world hello"`, []string{"hello", "world hello"}},
    26  		{`'hello again' "world hello"`, []string{"hello again", "world hello"}},
    27  		{`\"hello\ world\"`, []string{`"hello world"`}},
    28  		{"hello 世界", []string{"hello", "世界"}},
    29  		{`hello\ world`, []string{"hello world"}},
    30  	}
    31  	for i, one := range tests {
    32  		parts, err := cmdline.Parse(one.input)
    33  		check.NoError(t, err, i)
    34  		check.Equal(t, one.expected, parts, i)
    35  	}
    36  }