github.com/mvdan/u-root-coreutils@v0.0.0-20230122170626-c2eef2898555/pkg/boot/grub/grub_test.go (about)

     1  // Copyright 2017-2020 the u-root Authors. All rights reserved
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package grub
     6  
     7  import (
     8  	"fmt"
     9  	"testing"
    10  )
    11  
    12  func TestCmdlineQuote(t *testing.T) {
    13  	for i, tt := range []struct {
    14  		desc string
    15  		in   []string
    16  		want string
    17  	}{
    18  		{
    19  			desc: "nothing to do",
    20  			in:   []string{"stuff"},
    21  			want: "stuff",
    22  		},
    23  		{
    24  			desc: "split",
    25  			in:   []string{"stuff", "more", "stuff"},
    26  			want: "stuff more stuff",
    27  		},
    28  		{
    29  			desc: "escape",
    30  			in:   []string{`escape\quote'double"`},
    31  			want: `escape\\quote\'double\"`,
    32  		},
    33  		{
    34  			desc: "quote spaced",
    35  			in:   []string{`some stuff`},
    36  			want: `"some stuff"`,
    37  		},
    38  	} {
    39  		t.Run(fmt.Sprintf("Test [%02d] %s", i, tt.desc), func(t *testing.T) {
    40  			got := cmdlineQuote(tt.in)
    41  			if got != tt.want {
    42  				t.Errorf("cmdlineQuote = %#v, want %#v", got, tt.want)
    43  			}
    44  		})
    45  	}
    46  }