github.com/westcoastroms/westcoastroms-build@v0.0.0-20190928114312-2350e5a73030/build/soong/zip/zip_test.go (about)

     1  // Copyright 2018 Google Inc. All rights reserved.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package zip
    16  
    17  import (
    18  	"reflect"
    19  	"testing"
    20  )
    21  
    22  func TestReadRespFile(t *testing.T) {
    23  	testCases := []struct {
    24  		name, in string
    25  		out      []string
    26  	}{
    27  		{
    28  			name: "single quoting test case 1",
    29  			in:   `./cmd '"'-C`,
    30  			out:  []string{"./cmd", `"-C`},
    31  		},
    32  		{
    33  			name: "single quoting test case 2",
    34  			in:   `./cmd '-C`,
    35  			out:  []string{"./cmd", `-C`},
    36  		},
    37  		{
    38  			name: "single quoting test case 3",
    39  			in:   `./cmd '\"'-C`,
    40  			out:  []string{"./cmd", `\"-C`},
    41  		},
    42  		{
    43  			name: "single quoting test case 4",
    44  			in:   `./cmd '\\'-C`,
    45  			out:  []string{"./cmd", `\\-C`},
    46  		},
    47  		{
    48  			name: "none quoting test case 1",
    49  			in:   `./cmd \'-C`,
    50  			out:  []string{"./cmd", `'-C`},
    51  		},
    52  		{
    53  			name: "none quoting test case 2",
    54  			in:   `./cmd \\-C`,
    55  			out:  []string{"./cmd", `\-C`},
    56  		},
    57  		{
    58  			name: "none quoting test case 3",
    59  			in:   `./cmd \"-C`,
    60  			out:  []string{"./cmd", `"-C`},
    61  		},
    62  		{
    63  			name: "double quoting test case 1",
    64  			in:   `./cmd "'"-C`,
    65  			out:  []string{"./cmd", `'-C`},
    66  		},
    67  		{
    68  			name: "double quoting test case 2",
    69  			in:   `./cmd "\\"-C`,
    70  			out:  []string{"./cmd", `\-C`},
    71  		},
    72  		{
    73  			name: "double quoting test case 3",
    74  			in:   `./cmd "\""-C`,
    75  			out:  []string{"./cmd", `"-C`},
    76  		},
    77  	}
    78  
    79  	for _, testCase := range testCases {
    80  		t.Run(testCase.name, func(t *testing.T) {
    81  			got := ReadRespFile([]byte(testCase.in))
    82  			if !reflect.DeepEqual(got, testCase.out) {
    83  				t.Errorf("expected %q got %q", testCase.out, got)
    84  			}
    85  		})
    86  	}
    87  }