File: quote_test.go

package info (click to toggle)
elvish 0.12%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,532 kB
  • sloc: python: 108; makefile: 94; sh: 72; xml: 9
file content (36 lines) | stat: -rw-r--r-- 867 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package parse

import (
	"testing"

	"github.com/elves/elvish/tt"
)

var quoteTests = tt.Table{
	// Empty string is single-quoted.
	tt.Args("").Rets(`''`),

	// Bareword when possible.
	tt.Args("x-y:z@h/d").Rets("x-y:z@h/d"),

	// Single quote when there are special characters but no unprintable
	// characters.
	tt.Args("x$y[]ef'").Rets("'x$y[]ef'''"),

	// Tilde needs quoting only leading the expression.
	tt.Args("~x").Rets("'~x'"),
	tt.Args("x~").Rets("x~"),

	// Double quote when there is unprintable char.
	tt.Args("a\nb").Rets(`"a\nb"`),
	tt.Args("\x1b\"\\").Rets(`"\e\"\\"`),

	// Commas and equal signs are always quoted, so that the quoted string is
	// safe for use everywhere.
	tt.Args("a,b").Rets(`'a,b'`),
	tt.Args("a=b").Rets(`'a=b'`),
}

func TestQuote(t *testing.T) {
	tt.Test(t, tt.Fn("Quote", Quote).ArgsFmt("(%q)").RetsFmt("%q"), quoteTests)
}