]> arthur.barton.de Git - bup.git/blob - test/int/test_shquote.py
Migrate tests to pytest
[bup.git] / test / int / test_shquote.py
1
2 from __future__ import absolute_import
3
4 from wvpytest import *
5
6 from bup import shquote
7
8
9 def qst(line):
10     return [word for offset,word in shquote.quotesplit(line)]
11
12 def test_shquote():
13     WVPASSEQ(qst(b"""  this is    basic \t\n\r text  """),
14              [b'this', b'is', b'basic', b'text'])
15     WVPASSEQ(qst(br""" \"x\" "help" 'yelp' """), [b'"x"', b'help', b'yelp'])
16     WVPASSEQ(qst(br""" "'\"\"'" '\"\'' """), [b"'\"\"'", b'\\"\''])
17
18     WVPASSEQ(shquote.quotesplit(b'  this is "unfinished'),
19              [(2, b'this'), (7, b'is'), (10, b'unfinished')])
20
21     WVPASSEQ(shquote.quotesplit(b'"silly"\'will'),
22              [(0, b'silly'), (7, b'will')])
23
24     WVPASSEQ(shquote.unfinished_word(b'this is a "billy" "goat'),
25              (b'"', b'goat'))
26     WVPASSEQ(shquote.unfinished_word(b"'x"),
27              (b"'", b'x'))
28     WVPASSEQ(shquote.unfinished_word(b"abra cadabra "),
29              (None, b''))
30     WVPASSEQ(shquote.unfinished_word(b"abra cadabra"),
31              (None, b'cadabra'))
32
33     qtype, word = shquote.unfinished_word(b"this is /usr/loc")
34     WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
35              b"al")
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", False),
44              b"al")
45     qtype, word = shquote.unfinished_word(b"this is \\ hammer\\ \"")
46     WVPASSEQ(word, b' hammer "')
47     WVPASSEQ(shquote.what_to_add(qtype, word, b" hammer \"time\"", True),
48              b"time\\\"")
49
50     WVPASSEQ(shquote.quotify_list([b'a', b'', b'"word"', b"'third'", b"'",
51                                    b"x y"]),
52              b"a '' '\"word\"' \"'third'\" \"'\" 'x y'")