diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2023-02-27 10:46:33 +0000 |
commit | aa1d1f1ea72887a3efb78f4950e27bc79dfa3766 (patch) | |
tree | a9f5bf5ab14c69d011e21d40f8504c4f94a8de72 /tests/test_diff.py | |
parent | Adding upstream version 11.2.0. (diff) | |
download | sqlglot-aa1d1f1ea72887a3efb78f4950e27bc79dfa3766.tar.xz sqlglot-aa1d1f1ea72887a3efb78f4950e27bc79dfa3766.zip |
Adding upstream version 11.2.3.upstream/11.2.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tests/test_diff.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/test_diff.py b/tests/test_diff.py index cbd53b3..372af70 100644 --- a/tests/test_diff.py +++ b/tests/test_diff.py @@ -1,6 +1,6 @@ import unittest -from sqlglot import parse_one +from sqlglot import exp, parse_one from sqlglot.diff import Insert, Keep, Move, Remove, Update, diff from sqlglot.expressions import Join, to_identifier @@ -128,6 +128,33 @@ class TestDiff(unittest.TestCase): ], ) + def test_pre_matchings(self): + expr_src = parse_one("SELECT 1") + expr_tgt = parse_one("SELECT 1, 2, 3, 4") + + self._validate_delta_only( + diff(expr_src, expr_tgt), + [ + Remove(expr_src), + Insert(expr_tgt), + Insert(exp.Literal.number(2)), + Insert(exp.Literal.number(3)), + Insert(exp.Literal.number(4)), + ], + ) + + self._validate_delta_only( + diff(expr_src, expr_tgt, matchings=[(expr_src, expr_tgt)]), + [ + Insert(exp.Literal.number(2)), + Insert(exp.Literal.number(3)), + Insert(exp.Literal.number(4)), + ], + ) + + with self.assertRaises(ValueError): + diff(expr_src, expr_tgt, matchings=[(expr_src, expr_tgt), (expr_src, expr_tgt)]) + def _validate_delta_only(self, actual_diff, expected_delta): actual_delta = _delta_only(actual_diff) self.assertEqual(set(actual_delta), set(expected_delta)) |