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