Jelajahi Sumber

添加一些测试

myuan 2 tahun lalu
induk
melakukan
58fa59451c
2 mengubah file dengan 33 tambahan dan 3 penghapusan
  1. 5 2
      run_sql_parser_test.py
  2. 28 1
      tests_config.py

+ 5 - 2
run_sql_parser_test.py

@@ -115,12 +115,15 @@ async def on_checker_modified():
 async def assert_sql_optimizer_check():
     for sql, res in sql_optimizer_tests:
         stdout, stderr = await run_and_output("xmake", "run", "sql-optimizer", "-s", sql)
-        print(sql, res)
+        print(sql)
 
         try:
             output = orjson.loads(stdout)
             if output != res:
-                print(stdout.decode("utf-8") + "\n" + stderr.decode("utf-8"))
+                print(colored(res, "yellow"))
+                print(colored(output, "red"))
+                print(colored(stdout.decode("utf-8"), "yellow"))
+                print(colored(stderr.decode("utf-8"), "yellow"))
                 assert False
             
         except Exception as e:

+ 28 - 1
tests_config.py

@@ -611,6 +611,33 @@ sql_checker_tests = [
 sql_optimizer_tests = [
     (
         "select * from person where (age < 18) or (age > 60 and age < 35);",
+        {
+            "select_cols": [
+                {
+                    "target": {
+                        "type": "select_all_column",
+                        "value": "select_all_column",
+                    },
+                    "type": "select_all_column",
+                }
+            ],
+            "table_names": ["person"],
+            "type": "select_stmt",
+            "where": {
+                "left": {
+                    "left": {"type": "identifier", "value": "age"},
+                    "op_type": "bin_cmp_op",
+                    "right": {"type": "int", "value": 18},
+                    "type": "小于",
+                },
+                "op_type": "bin_logical_op",
+                "right": {"type": "bool", "value": False},
+                "type": "或",
+            },
+        },
+    ),
+    (
+        "select * from person where (age < 18) and age < 5 and age < 35;",
         {
             "select_cols": [
                 {
@@ -626,7 +653,7 @@ sql_optimizer_tests = [
             "where": {
                 "left": {"type": "identifier", "value": "age"},
                 "op_type": "bin_cmp_op",
-                "right": {"type": "int", "value": 18},
+                "right": {"type": "int", "value": 5},
                 "type": "小于",
             },
         },