]> arthur.barton.de Git - bup.git/blobdiff - t/tshquote.py
cmd-ftp: a new command-line client you can use for browsing your repo.
[bup.git] / t / tshquote.py
diff --git a/t/tshquote.py b/t/tshquote.py
new file mode 100644 (file)
index 0000000..9f9c8cc
--- /dev/null
@@ -0,0 +1,44 @@
+from wvtest import *
+import shquote
+
+def qst(line):
+    return [s[1] for s 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\\\"")