X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=tests%2Ftest_tokens.py;h=4e48ab040e00c4212225f4415c467a776c8ac00a;hb=26ca2f53d8fe333bb2448ea412e82be415cb3fd2;hp=d537d73f068291c2eb3d9a13773ba31c9cccf5ef;hpb=6d906e2f335699348bf44a653ca708b522a99d85;p=sqlconvert.git diff --git a/tests/test_tokens.py b/tests/test_tokens.py index d537d73..4e48ab0 100644 --- a/tests/test_tokens.py +++ b/tests/test_tokens.py @@ -6,6 +6,7 @@ from sqlconvert.print_tokens import tlist2str from sqlconvert.process_mysql import remove_directive_tokens, \ is_directive_statement, requote_names, unescape_strings, \ process_statement +from sqlconvert.process_tokens import escape_strings def test_encoding(): @@ -42,10 +43,26 @@ def test_requote(): assert query == u'SELECT * FROM "T"' -def test_string(): +def test_unescape_string(): parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0] unescape_strings(parsed) query = tlist2str(parsed) + assert query == u"INSERT INTO test VALUES ('\"te'st\"\n')" + + +def test_escape_string_postgres(): + parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0] + unescape_strings(parsed) + escape_strings(parsed, 'postgres') + query = tlist2str(parsed) + assert query == u"INSERT INTO test VALUES (E'\"te''st\"\\n')" + + +def test_escape_string_sqlite(): + parsed = parse("insert into test values ('\"te\\'st\\\"\\n')")[0] + unescape_strings(parsed) + escape_strings(parsed, 'sqlite') + query = tlist2str(parsed) assert query == u"INSERT INTO test VALUES ('\"te''st\"\n')"