Skip to content

Commit bf3b65a

Browse files
committed
internal/function: make UAST be able to use language results
Signed-off-by: Miguel Molina <[email protected]>
1 parent 0bd1c13 commit bf3b65a

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ func TestUastQueries(t *testing.T) {
178178
session := gitbase.NewSession(pool)
179179
ctx := sql.NewContext(context.TODO(), sql.WithSession(session))
180180
_, iter, err := engine.Query(ctx, `
181-
SELECT uast_xpath(uast(content, 'php'), '//*[@roleIdentifier]') as uast, name
181+
SELECT uast_xpath(uast(content, language(name, content)), '//*[@roleIdentifier]') as uast, name
182182
FROM tree_entries te
183183
INNER JOIN blobs b
184184
ON b.hash = te.entry_hash

internal/function/uast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (f UAST) Eval(ctx *sql.Context, row sql.Row) (interface{}, error) {
155155
return nil, err
156156
}
157157

158-
lang = lng.(string)
158+
lang = strings.ToLower(lng.(string))
159159
}
160160

161161
var xpath string

internal/function/uast_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ func TestUAST(t *testing.T) {
5858
{"lang is nil", fn3, sql.NewRow([]byte{}, nil, nil), nil, nil},
5959
{"xpath is nil", fn3, sql.NewRow([]byte{}, "Ruby", nil), nil, nil},
6060
{"only blob, can't infer language", fn1, sql.NewRow([]byte(testCode)), nil, ErrParseBlob},
61-
{"blob with lang", fn2, sql.NewRow([]byte(testCode), "python"), uast, nil},
62-
{"blob with lang and xpath", fn3, sql.NewRow([]byte(testCode), "python", testXPath), filteredNodes, nil},
61+
{"blob with lang", fn2, sql.NewRow([]byte(testCode), "Python"), uast, nil},
62+
{"blob with lang and xpath", fn3, sql.NewRow([]byte(testCode), "Python", testXPath), filteredNodes, nil},
6363
}
6464

6565
for _, tt := range testCases {

0 commit comments

Comments
 (0)