Ensure that multi-nested parenthesis are never unrolled after IN
[dbsrgits/SQL-Abstract.git] / t / 11parser.t
index b70cb0d..3c60c95 100644 (file)
@@ -619,18 +619,222 @@ is_deeply($sqlat->parse("SELECT x, y FROM foo WHERE x IN (?, ?, ?, ?)"), [
   ]
 ], 'Lists parsed correctly');
 
-is_deeply($sqlat->parse("SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo bar WHERE NOT NOT NOT EXISTS (SELECT 'cr,ap') AND foo.a = ? and not (foo.b LIKE 'station') and x = y and a = b and GROUP BY , ORDER BY x x1 x2 y asc, max(y) desc x z desc"), [
+is_deeply($sqlat->parse('SELECT foo FROM bar ORDER BY x + ? DESC, oomph, y - ? DESC, unf, baz.g / ? ASC, buzz * 0 DESC, foo LIKE ? DESC, ickk ASC'), [
   [
     "SELECT",
     [
       [
-        "*",
+        "-LITERAL",
+        [
+          "foo"
+        ]
+      ]
+    ]
+  ],
+  [
+    "FROM",
+    [
+      [
+        "-LITERAL",
+        [
+          "bar"
+        ]
+      ]
+    ]
+  ],
+  [
+    "ORDER BY",
+    [
+      [
+        "-LIST",
+        [
+          [
+            "-DESC",
+            [
+              [
+                "-MISC",
+                [
+                  [
+                    "-LITERAL",
+                    [
+                      "x"
+                    ]
+                  ],
+                  [
+                    "-LITERAL",
+                    [
+                      "+"
+                    ]
+                  ],
+                  [
+                    "-PLACEHOLDER",
+                    [
+                      "?"
+                    ]
+                  ]
+                ]
+              ],
+            ]
+          ],
+          [
+            "-LITERAL",
+            [
+              "oomph"
+            ]
+          ],
+          [
+            "-DESC",
+            [
+              [
+                "-MISC",
+                [
+                  [
+                    "-LITERAL",
+                    [
+                      "y"
+                    ]
+                  ],
+                  [
+                    "-LITERAL",
+                    [
+                      "-"
+                    ]
+                  ],
+                  [
+                    "-PLACEHOLDER",
+                    [
+                      "?"
+                    ]
+                  ],
+                ]
+              ],
+            ]
+          ],
+          [
+            "-LITERAL",
+            [
+              "unf"
+            ]
+          ],
+          [
+            "-ASC",
+            [
+              [
+                "-MISC",
+                [
+                  [
+                    "-LITERAL",
+                    [
+                      "baz.g"
+                    ]
+                  ],
+                  [
+                    "-LITERAL",
+                    [
+                      "/"
+                    ]
+                  ],
+                  [
+                    "-PLACEHOLDER",
+                    [
+                      "?"
+                    ]
+                  ],
+                ]
+              ],
+            ]
+          ],
+          [
+            "-DESC",
+            [
+              [
+                "-MISC",
+                [
+                  [
+                    "-LITERAL",
+                    [
+                      "buzz"
+                    ]
+                  ],
+                  [
+                    "-LITERAL",
+                    [
+                      "*"
+                    ]
+                  ],
+                  [
+                    "-LITERAL",
+                    [
+                      0
+                    ]
+                  ]
+                ]
+              ]
+            ]
+          ],
+          [
+            "-DESC",
+            [
+              [
+                "LIKE",
+                [
+                  [
+                    "-LITERAL",
+                    [
+                      "foo"
+                    ]
+                  ],
+                  [
+                    "-PLACEHOLDER",
+                    [
+                      "?"
+                    ]
+                  ],
+                ],
+              ],
+            ]
+          ],
+          [
+            "-ASC",
+            [
+              [
+                "-LITERAL",
+                [
+                  "ickk"
+                ]
+              ]
+            ]
+          ]
+        ]
+      ]
+    ]
+  ]
+], 'Crazy ORDER BY parsed correctly');
+
+is_deeply( $sqlat->parse("META SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo bar WHERE NOT NOT NOT EXISTS (SELECT 'cr,ap') AND foo.a = ? STUFF moar(stuff) and not (foo.b LIKE 'station') and x = y and z in ((1, 2)) and a = b and GROUP BY , ORDER BY x x1 x2 y asc, max(y) desc x z desc"), [
+  [
+    "-LITERAL",
+    [
+      "META"
+    ]
+  ],
+  [
+    "SELECT",
+    [
+      [
+        "-MISC",
         [
           [
             "-LITERAL",
             [
               "*"
             ]
+          ],
+          [
+            "-LITERAL",
+            [
+              "*"
+            ]
           ]
         ]
       ]
@@ -755,18 +959,45 @@ is_deeply($sqlat->parse("SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo ba
             ]
           ],
           [
-            "=",
+            "-MISC",
             [
               [
+                "=",
+                [
+                  [
+                    "-LITERAL",
+                    [
+                      "foo.a"
+                    ]
+                  ],
+                  [
+                    "-PLACEHOLDER",
+                    [
+                      "?"
+                    ]
+                  ],
+                ],
+              ],
+              [
                 "-LITERAL",
                 [
-                  "foo.a"
+                  "STUFF"
                 ]
               ],
+            ],
+          ],
+          [
+            'moar',
+            [
               [
-                "-PLACEHOLDER",
+                '-PAREN',
                 [
-                  "?"
+                  [
+                    '-LITERAL',
+                    [
+                      'stuff'
+                    ]
+                 ]
                 ]
               ]
             ]
@@ -816,6 +1047,44 @@ is_deeply($sqlat->parse("SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo ba
             ]
           ],
           [
+            'IN',
+            [
+              [
+                '-LITERAL',
+                [
+                  'z',
+                ],
+              ],
+              [
+                '-PAREN',
+                [
+                  [
+                    '-PAREN',
+                    [
+                      [
+                        '-LIST',
+                        [
+                          [
+                            '-LITERAL',
+                            [
+                              '1'
+                            ]
+                          ],
+                          [
+                            '-LITERAL',
+                            [
+                              '2'
+                            ]
+                          ],
+                        ],
+                      ],
+                    ],
+                  ],
+                ],
+              ],
+            ],
+          ],
+          [
             "=",
             [
               [
@@ -855,78 +1124,76 @@ is_deeply($sqlat->parse("SELECT * * FROM (SELECT *, FROM foobar baz buzz) foo ba
         "-LIST",
         [
           [
-            "-MISC",
-            [
-              [
-                "-LITERAL",
-                [
-                  "x"
-                ]
-              ],
-              [
-                "-LITERAL",
-                [
-                  "x1"
-                ]
-              ],
-              [
-                "-LITERAL",
-                [
-                  "x2"
-                ]
-              ],
-              [
-                "-LITERAL",
-                [
-                  "y"
-                ]
-              ],
-              [
-                "-LITERAL",
-                [
-                  "asc"
-                ]
-              ]
-            ]
-          ],
-          [
-            "max",
+            "-ASC",
             [
               [
                 "-MISC",
                 [
                   [
-                    "-DESC",
+                    "-LITERAL",
                     [
-                      [
-                        "-PAREN",
-                        [
-                          [
-                            "-LITERAL",
-                            [
-                              "y"
-                            ]
-                          ]
-                        ]
-                      ]
+                      "x"
                     ]
                   ],
                   [
                     "-LITERAL",
                     [
-                      "x"
+                      "x1"
                     ]
                   ],
                   [
                     "-LITERAL",
                     [
-                      "z"
+                      "x2"
                     ]
                   ],
                   [
                     "-LITERAL",
                     [
-                      "desc"
+                      "y"
+                    ]
+                  ]
+                ]
+              ],
+            ],
+          ],
+          [
+                "-DESC",
+                [
+                  [
+                    "-MISC",
+                    [
+                      [
+                        "-DESC",
+                        [
+                          [
+                            "max",
+                            [
+                              [
+                                "-PAREN",
+                                [
+                                  [
+                                    "-LITERAL",
+                                    [
+                                      "y"
+                                    ]
+                                  ]
+                                ]
+                              ]
+                            ],
+                          ]
+                        ]
+                      ],
+                      [
+                        "-LITERAL",
+                        [
+                          "x"
+                        ]
+                      ],
+                  [
+                    "-LITERAL",
+                    [
+                      "z"
                     ]
                   ]
                 ]