X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fbup%2Ft%2Ftshquote.py;h=f17346df40d7b0286560a406aebdae09aba3e373;hb=bf67f94dd4f4096de4eee07a7dc377d6c889a016;hp=15b06ec1a53992435cf91fb529d4f85c77367727;hpb=7e7405d32f7f0a1570c8524e936b168adab03661;p=bup.git diff --git a/lib/bup/t/tshquote.py b/lib/bup/t/tshquote.py index 15b06ec..f17346d 100644 --- a/lib/bup/t/tshquote.py +++ b/lib/bup/t/tshquote.py @@ -1,44 +1,54 @@ -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(""" 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\\\"") + + WVPASSEQ(shquote.quotify_list(['a', '', '"word"', "'third'", "'", "x y"]), + "a '' '\"word\"' \"'third'\" \"'\" 'x y'")