@@ -261,26 +261,56 @@ func TestIntegration(t *testing.T) {
261261}
262262
263263func TestUastQueries (t * testing.T ) {
264- require := require .New (t )
265-
266264 engine , pool , cleanup := setup (t )
267265 defer cleanup ()
268266
269- session := gitbase .NewSession (pool )
270- ctx := sql .NewContext (context .TODO (), sql .WithSession (session ))
271- _ , iter , err := engine .Query (ctx , `
272- SELECT uast_xpath(uast(blob_content, language(tree_entry_name, blob_content)), '//*[@roleIdentifier]') as uast,
267+ testCases := []struct {
268+ query string
269+ rows int
270+ }{
271+ {`SELECT uast_xpath(uast(blob_content, language(tree_entry_name, blob_content)), '//Identifier') as uast,
273272 tree_entry_name
274273 FROM tree_entries te
275274 INNER JOIN blobs b
276275 ON b.blob_hash = te.blob_hash
277- WHERE te.tree_entry_name = 'crappy.php'` ,
278- )
279- require .NoError (err )
276+ WHERE te.tree_entry_name = 'example.go'` , 1 },
277+ {`SELECT uast_xpath(uast_mode(blob_content, language(tree_entry_name, blob_content), 'semantic'), '//Identifier') as uast,
278+ tree_entry_name
279+ FROM tree_entries te
280+ INNER JOIN blobs b
281+ ON b.blob_hash = te.blob_hash
282+ WHERE te.tree_entry_name = 'example.go'` , 1 },
283+ {`SELECT uast_xpath(uast_mode(blob_content, language(tree_entry_name, blob_content), 'annotated'), '//*[@roleIdentifier]') as uast,
284+ tree_entry_name
285+ FROM tree_entries te
286+ INNER JOIN blobs b
287+ ON b.blob_hash = te.blob_hash
288+ WHERE te.tree_entry_name = 'example.go'` , 1 },
289+ {`SELECT uast_xpath(uast_mode(blob_content, language(tree_entry_name, blob_content), 'native'), '//*[@ast_type=\'FunctionDef\']') as uast,
290+ tree_entry_name
291+ FROM tree_entries te
292+ INNER JOIN blobs b
293+ ON b.blob_hash = te.blob_hash
294+ WHERE te.tree_entry_name = 'example.go'` , 1 },
295+ }
280296
281- rows , err := sql .RowIterToRows (iter )
282- require .NoError (err )
283- require .Len (rows , 1 )
297+ _ = testCases
298+
299+ for _ , c := range testCases {
300+ t .Run (c .query , func (t * testing.T ) {
301+ require := require .New (t )
302+
303+ session := gitbase .NewSession (pool )
304+ ctx := sql .NewContext (context .TODO (), sql .WithSession (session ))
305+
306+ _ , iter , err := engine .Query (ctx , c .query )
307+ require .NoError (err )
308+
309+ rows , err := sql .RowIterToRows (iter )
310+ require .NoError (err )
311+ require .Len (rows , c .rows )
312+ })
313+ }
284314}
285315
286316func TestSquashCorrectness (t * testing.T ) {
0 commit comments