]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/t/tshquote.py
features: show version number of the Python interpreter
[bup.git] / lib / bup / t / tshquote.py
index 15b06ec1a53992435cf91fb529d4f85c77367727..8c85d4bc10f2bd69fb01122ef7dfed86a23caa7d 100644 (file)
@@ -1,44 +1,55 @@
-from bup import shquote
+
+from __future__ import absolute_import
+
 from wvtest import *
 
+from bup import shquote
+from buptest import no_lingering_errors
+
+
 def qst(line):
-    return [s[1] for s in shquote.quotesplit(line)]
+    return [word for offset,word in shquote.quotesplit(line)]
 
 @wvtest
 def test_shquote():
-    WVPASSEQ(qst("""  this is    basic \t\n\r text  """),
-             ['this', 'is', 'basic', 'text'])
-    WVPASSEQ(qst(r""" \"x\" "help" 'yelp' """), ['"x"', 'help', 'yelp'])
-    WVPASSEQ(qst(r""" "'\"\"'" '\"\'' """), ["'\"\"'", '\\"\''])
-
-    WVPASSEQ(shquote.quotesplit('  this is "unfinished'),
-             [(2,'this'), (7,'is'), (10,'unfinished')])
-
-    WVPASSEQ(shquote.quotesplit('"silly"\'will'),
-             [(0,'silly'), (7,'will')])
-
-    WVPASSEQ(shquote.unfinished_word('this is a "billy" "goat'),
-             ('"', 'goat'))
-    WVPASSEQ(shquote.unfinished_word("'x"),
-             ("'", 'x'))
-    WVPASSEQ(shquote.unfinished_word("abra cadabra "),
-             (None, ''))
-    WVPASSEQ(shquote.unfinished_word("abra cadabra"),
-             (None, 'cadabra'))
-
-    (qtype, word) = shquote.unfinished_word("this is /usr/loc")
-    WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True),
-             "al")
-    (qtype, word) = shquote.unfinished_word("this is '/usr/loc")
-    WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True),
-             "al'")
-    (qtype, word) = shquote.unfinished_word("this is \"/usr/loc")
-    WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", True),
-             "al\"")
-    (qtype, word) = shquote.unfinished_word("this is \"/usr/loc")
-    WVPASSEQ(shquote.what_to_add(qtype, word, "/usr/local", False),
-             "al")
-    (qtype, word) = shquote.unfinished_word("this is \\ hammer\\ \"")
-    WVPASSEQ(word, ' hammer "')
-    WVPASSEQ(shquote.what_to_add(qtype, word, " hammer \"time\"", True),
-             "time\\\"")
+    with no_lingering_errors():
+        WVPASSEQ(qst(b"""  this is    basic \t\n\r text  """),
+                 [b'this', b'is', b'basic', b'text'])
+        WVPASSEQ(qst(br""" \"x\" "help" 'yelp' """), [b'"x"', b'help', b'yelp'])
+        WVPASSEQ(qst(br""" "'\"\"'" '\"\'' """), [b"'\"\"'", b'\\"\''])
+
+        WVPASSEQ(shquote.quotesplit(b'  this is "unfinished'),
+                 [(2, b'this'), (7, b'is'), (10, b'unfinished')])
+
+        WVPASSEQ(shquote.quotesplit(b'"silly"\'will'),
+                 [(0, b'silly'), (7, b'will')])
+
+        WVPASSEQ(shquote.unfinished_word(b'this is a "billy" "goat'),
+                 (b'"', b'goat'))
+        WVPASSEQ(shquote.unfinished_word(b"'x"),
+                 (b"'", b'x'))
+        WVPASSEQ(shquote.unfinished_word(b"abra cadabra "),
+                 (None, b''))
+        WVPASSEQ(shquote.unfinished_word(b"abra cadabra"),
+                 (None, b'cadabra'))
+
+        qtype, word = shquote.unfinished_word(b"this is /usr/loc")
+        WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
+                 b"al")
+        qtype, word = shquote.unfinished_word(b"this is '/usr/loc")
+        WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
+                 b"al'")
+        qtype, word = shquote.unfinished_word(b"this is \"/usr/loc")
+        WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", True),
+                 b"al\"")
+        qtype, word = shquote.unfinished_word(b"this is \"/usr/loc")
+        WVPASSEQ(shquote.what_to_add(qtype, word, b"/usr/local", False),
+                 b"al")
+        qtype, word = shquote.unfinished_word(b"this is \\ hammer\\ \"")
+        WVPASSEQ(word, b' hammer "')
+        WVPASSEQ(shquote.what_to_add(qtype, word, b" hammer \"time\"", True),
+                 b"time\\\"")
+
+        WVPASSEQ(shquote.quotify_list([b'a', b'', b'"word"', b"'third'", b"'",
+                                       b"x y"]),
+                 b"a '' '\"word\"' \"'third'\" \"'\" 'x y'")