Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 96
Sort nodeset on demand#330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -85,9 +85,9 @@ def get_namespace( node_set = nil ) | ||
| if node_set == nil | ||
| yield @context[:node] if @context[:node].respond_to?(:namespace) | ||
| else | ||
| if node_set.respond_to? :each | ||
| if node_set.kind_of? Array | ||
| result = [] | ||
| node_set.each do |node| | ||
| XPathParser.sort(node_set).each do |node| | ||
| result << yield(node) if node.respond_to?(:namespace) | ||
| end | ||
| result | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @@ -149,7 +149,7 @@ def string( object=@context[:node] ) | ||
| else | ||
| case object | ||
| when Array | ||
| string(object[0]) | ||
| string(XPathParser.sort(object).first) | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| when Float | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if object.nan? | ||
| "NaN" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -156,7 +156,7 @@ def match(path_stack, node) | ||
| result = expr(path_stack, nodeset) | ||
| case result | ||
| when Array # nodeset | ||
| result.uniq | ||
| XPathParser.sort(result) | ||
| else | ||
| [result] | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| end | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| @@ -323,7 +323,7 @@ def expr( path_stack, nodeset, context=nil ) | ||
| # If result is a nodeset, apply following predicates | ||
| path_stack.unshift(:node) | ||
| nodeset = step(path_stack) do | ||
| [:iterate_nodesets, [result]] | ||
| [:iterate_nodesets, [XPathParser.sort(result)]] | ||
| end | ||
| else | ||
| return result | ||
| @@ -571,6 +571,7 @@ def split_positional_predicates(predicates) | ||
| end | ||
| # Performs an axis scanning step. | ||
| # Returns an unordered non-duplicated nodeset of matching nodes. | ||
| # The caller provides a scanner method and its argument, which determines the axis to scan and the nodes to scan from: | ||
| # step(path_stack) { [scanner_method, scanner_argument] } | ||
| # Scanner methods are called with `(scanner_argument, tester_block, selector)` | ||
| @@ -621,7 +622,7 @@ def step(path_stack, any_type: :element) | ||
| nodes << node | ||
| end | ||
| end | ||
| new_nodeset = sort(nodes.to_a) | ||
| new_nodeset = nodes.to_a | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| ensure | ||
| leave(:step, path_stack, new_nodeset) if @debug | ||
| end | ||
| @@ -761,7 +762,7 @@ def leave(tag, *args) | ||
| # in and out of function calls. If I knew what the index of the nodes was, | ||
| # I wouldn't have to do this. Maybe add a document IDX for each node? | ||
| # Problems with mutable documents. Or, rewrite everything. | ||
| def sort(array_of_nodes) | ||
| def self.sort(array_of_nodes) | ||
| return array_of_nodes if array_of_nodes.size <= 1 | ||
| new_arry = [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -87,6 +87,13 @@ def process_value_of(context, variables, namespaces, value_of) | ||
| xpath = value_of.attributes["select"] | ||
| matched = XPath.match(context, xpath, namespaces, variables, strict: true) | ||
| # XPath.match can be a nodeset or a primitive value wrapped in an array. | ||
| # We need to unwrap primitive value because Functions doesn't accept array which is not a nodeset. | ||
| unless matched.all? { |node| node.is_a?(REXML::Node) } | ||
| assert_equal(1, matched.size, 'Primitive value should be a single value') | ||
| matched = matched.first | ||
| end | ||
naitoh marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page.
Comment on lines
+92
to
+95
| ||
| message = user_message(context, xpath, matched) | ||
| assert_equal(expected || "", | ||
| REXML::Functions.string(matched), | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.