]> arthur.barton.de Git - bup.git/blob - lib/bup/t/tshquote.py
195cc58170ad418d804ca961cf0c6296bcfc2b81
[bup.git] / lib / bup / t / tshquote.py
1
2 from wvtest import *
3
4 from bup import shquote
5 from buptest import no_lingering_errors
6
7
8 def qst(line):
9     return [word for offset,word in shquote.quotesplit(line)]
10
11 @wvtest
12 def test_shquote():
13     with no_lingering_errors():
14         WVPASSEQ(qst("""  this is    basic \t\n\r text  """),
15                  ['this', 'is', 'basic', 'text'])
16         WVPASSEQ(qst(r""" \"x\" "help" 'yelp' """), ['"x"', 'help', 'yelp'])
17         WVPASSEQ(qst(r""" "'\"\"'" '\"\'' """), ["'\"\"'", '\\"\''])
18
19         WVPASSEQ(shquote.quotesplit('  this is "unfinished'),
20                  [(2,'this'), (7,'is'), (10,'unfinished')])
21
22         WVPASSEQ(shquote.quotesplit('"silly"\'will'),
23                  [(0,'silly'), (7,'will')])
24
25         WVPASSEQ(shquote.unfinished_word('this is a "billy" "goat'),
26                  ('"', 'goat'))
27         WVPASSEQ(shquote.unfinished_word("'x"),
28                  ("'", 'x'))
29         WVPASSEQ(shquote.unfinished_word("abra cadabra "),
30                  (None, ''))
31         WVPASSEQ(shquote.unfinished_word("abra cadabra"),
32                  (None, 'cadabra'))
33
34         (qtype, word) = shquote.unfinished_word("this is /usr/loc")
35         WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True),
36                  "al")
37         (qtype, word) = shquote.unfinished_word("this is '/usr/loc")
38         WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True),
39                  "al'")
40         (qtype, word) = shquote.unfinished_word("this is \"/usr/loc")
41         WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True),
42                  "al\"")
43         (qtype, word) = shquote.unfinished_word("this is \"/usr/loc")
44         WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", False),
45                  "al")
46         (qtype, word) = shquote.unfinished_word("this is \\ hammer\\ \"")
47         WVPASSEQ(word, ' hammer "')
48         WVPASSEQ(shquote.what_to_add(qtype, word, " hammer \"time\"", True),
49                  "time\\\"")
50
51         WVPASSEQ(shquote.quotify_list(['a', '', '"word"', "'third'", "'", "x y"]),
52                  "a '' '\"word\"' \"'third'\" \"'\" 'x y'")