]> arthur.barton.de Git - bup.git/blob - test/int/tshquote.py
8c85d4bc10f2bd69fb01122ef7dfed86a23caa7d
[bup.git] / test / int / 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(b"""  this is    basic \t\n\r text  """),
17                  [b'this', b'is', b'basic', b'text'])
18         WVPASSEQ(qst(br""" \"x\" "help" 'yelp' """), [b'"x"', b'help', b'yelp'])
19         WVPASSEQ(qst(br""" "'\"\"'" '\"\'' """), [b"'\"\"'", b'\\"\''])
20
21         WVPASSEQ(shquote.quotesplit(b'  this is "unfinished'),
22                  [(2, b'this'), (7, b'is'), (10, b'unfinished')])
23
24         WVPASSEQ(shquote.quotesplit(b'"silly"\'will'),
25                  [(0, b'silly'), (7, b'will')])
26
27         WVPASSEQ(shquote.unfinished_word(b'this is a "billy" "goat'),
28                  (b'"', b'goat'))
29         WVPASSEQ(shquote.unfinished_word(b"'x"),
30                  (b"'", b'x'))
31         WVPASSEQ(shquote.unfinished_word(b"abra cadabra "),
32                  (None, b''))
33         WVPASSEQ(shquote.unfinished_word(b"abra cadabra"),
34                  (None, b'cadabra'))
35
36         qtype, word = shquote.unfinished_word(b"this is /usr/loc")
37         WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
38                  b"al")
39         qtype, word = shquote.unfinished_word(b"this is '/usr/loc")
40         WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
41                  b"al'")
42         qtype, word = shquote.unfinished_word(b"this is \"/usr/loc")
43         WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
44                  b"al\"")
45         qtype, word = shquote.unfinished_word(b"this is \"/usr/loc")
46         WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", False),
47                  b"al")
48         qtype, word = shquote.unfinished_word(b"this is \\ hammer\\ \"")
49         WVPASSEQ(word, b' hammer "')
50         WVPASSEQ(shquote.what_to_add(qtype, word, b" hammer \"time\"", True),
51                  b"time\\\"")
52
53         WVPASSEQ(shquote.quotify_list([b'a', b'', b'"word"', b"'third'", b"'",
54                                        b"x y"]),
55                  b"a '' '\"word\"' \"'third'\" \"'\" 'x y'")