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