-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treewalker: Yield for each array element itself, not just children
Due to an oversight in how the treewalker was implemented, we would never pass the direct array elements to the walk! block, only any children the elements have. In practice this is usually not an issue, since the array elements are typically the generic PgQuery::Node object, and we would call the walk! function successfully on its children. However, working with those node objects directly is necessary when wanting to replace the node. This may be a backwards incompatible change if one relies on the parent_field to always be a symbol (it can now be an integer as well).
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require 'spec_helper' | ||
|
||
describe PgQuery, '.treewalker' do | ||
it 'walks nodes contained in repeated fields' do | ||
locations = [] | ||
described_class.parse("SELECT to_timestamp($1)").walk! do |_, _, _, location| | ||
locations << location | ||
end | ||
expect(locations).to match_array [ | ||
[:stmts], | ||
[:stmts, 0], | ||
[:stmts, 0, :stmt], | ||
[:stmts, 0, :stmt, :select_stmt], | ||
[:stmts, 0, :stmt, :select_stmt, :distinct_clause], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list], | ||
[:stmts, 0, :stmt, :select_stmt, :from_clause], | ||
[:stmts, 0, :stmt, :select_stmt, :group_clause], | ||
[:stmts, 0, :stmt, :select_stmt, :window_clause], | ||
[:stmts, 0, :stmt, :select_stmt, :values_lists], | ||
[:stmts, 0, :stmt, :select_stmt, :sort_clause], | ||
[:stmts, 0, :stmt, :select_stmt, :locking_clause], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :indirection], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :funcname], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :args], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :agg_order], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :funcname, 0], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :args, 0], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :funcname, 0, :string], | ||
[:stmts, 0, :stmt, :select_stmt, :target_list, 0, :res_target, :val, :func_call, :args, 0, :param_ref] | ||
] | ||
end | ||
end |