Skip to content

Commit ffaec76

Browse files
author
Gareth Robinson
committed
Merge master into query branch
2 parents 31efe87 + 0e299a3 commit ffaec76

File tree

7 files changed

+308
-60
lines changed

7 files changed

+308
-60
lines changed

features/data/selection-tests.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"@type": [
3+
"http://www.example.org#unrealistic-data-with-no-decent-analogy"
4+
],
5+
"http://www.example.org#type": [{
6+
"@id": "http://www.example.org#type1",
7+
"@index": "index1",
8+
"@type": [
9+
"http://www.example.org#type-child",
10+
"one"
11+
],
12+
"http://www.example.org#type": [{
13+
"@id": "http://www.example.org#type2",
14+
"@index": "index2",
15+
"@type": [
16+
"http://www.example.org#type-child",
17+
"two"
18+
],
19+
"http://www.example.org#grabThis": [{
20+
"@value": "One-Two"
21+
}]
22+
}],
23+
"http://www.example.org#grabThis": [{
24+
"@value": "One"
25+
}]
26+
}, {
27+
"@id": "http://www.example.org#type3",
28+
"@index": "index3",
29+
"@type": [
30+
"http://www.example.org#type-child",
31+
"three"
32+
],
33+
"http://www.example.org#type": [{
34+
"@id": "http://www.example.org#type4",
35+
"@type": [
36+
"http://www.example.org#type-child",
37+
"four-noindex"
38+
],
39+
"http://www.example.org#type": [{
40+
"@id": "http://www.example.org#type4",
41+
"@index": "index4",
42+
"@type": [
43+
"http://www.example.org#type-child",
44+
"four"
45+
],
46+
"http://www.example.org#grabThis": [{
47+
"@value": "Three-Four"
48+
}]
49+
}],
50+
"http://www.example.org#grabThis": [{
51+
"@value": "Three-NoIndex"
52+
}]
53+
}],
54+
"http://www.example.org#grabThis": [{
55+
"@value": "Three"
56+
}]
57+
}]
58+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Feature: select values by type using child combinators
2+
As a developer working with JSON-LD
3+
I want to be able to use the child combinator in my selections
4+
So that I can better control how I represent the exact elements I need
5+
6+
Background: Load sample data
7+
Given the sample data containing selection tests is loaded
8+
And I construct an ldQuery object using the loaded data and <context>
9+
| context |
10+
| { "ex": "http://www.example.org#" } |
11+
12+
Scenario: Query for child path under root node should not retrieve other matching paths
13+
When I query for "> @type"
14+
And I get the result's json
15+
Then the json should match
16+
| json |
17+
| ["http://www.example.org#unrealistic-data-with-no-decent-analogy"] |
18+
19+
Scenario: Query for child path under current node should not retrieve other matching paths
20+
When I query for "ex:type[@index=index3]"
21+
And I query the result for "> ex:grabThis @value"
22+
Then the result should be "Three"
23+
24+
Scenario: Query should match any part of the tree
25+
When I query for all "ex:type[@id=ex:type4] > ex:grabThis @value"
26+
Then the result should be an array [ "Three-Four", "Three-NoIndex" ]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Feature: select values by type using multiple attributes
2+
As a developer working with JSON-LD
3+
I want to be able to use familiar syntax to query a JSON-LD document
4+
So that I don't need to manually parse the expanded JSON tree
5+
6+
Background: Load sample data
7+
Given the sample data containing selection tests is loaded
8+
And I construct an ldQuery object using the loaded data and <context>
9+
| context |
10+
| { "ex": "http://www.example.org#" } |
11+
12+
Scenario: Query for index and attribute, then first value
13+
When I query for "ex:type[@id=ex:type1][@index=index1] ex:grabThis @value"
14+
Then the result should be "One-Two"
15+
16+
Scenario: Query for index and attribute, then direct value
17+
When I query for "ex:type[@id=ex:type1][@index=index1] > ex:grabThis @value"
18+
Then the result should be "One"
19+
20+
Scenario: Stacked queries must match the same node
21+
When I query for "ex:type[@id=ex:type1][@index=index2] ex:grabThis @value"
22+
Then there should be no result
23+
24+
Scenario: Query by id on one node and index on another
25+
When I query for "ex:type[@id=ex:type1] ex:type[@index=index2] ex:grabThis @value"
26+
Then the result should be "One-Two"
27+
28+
Scenario: Query should match any part of the tree
29+
When I query for "ex:type[@id=ex:type4][@index=index4] ex:grabThis @value"
30+
Then the result should be "Three-Four"
31+
32+
Scenario: Query by two values of the same attribute
33+
When I query for "ex:type[@type=ex:type-child][@type=four-noindex] > ex:grabThis @value"
34+
Then the result should be "Three-NoIndex"

features/selection-by-type.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: select values by type using query syntax
22
As a developer working with JSON-LD
3-
I want to be able to use familiar syntax to query a JSON-LD document
4-
So that I don't need to manually parse the expanded JSON tree
3+
I want to be able to find query the @type attribute that may be an array
4+
So that I can find elements entries match a specific need
55

66
Background: Load sample data
77
Given the sample data containing operations is loaded

features/step_definitions/selection.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ var favouriteReads = JSON.stringify( require( "../data/person-favourite-reads.js
22
var dataWithNesting = JSON.stringify( require( "../data/data-with-nesting.json" ) );
33
var solitaryField = JSON.stringify( require( "../data/solitary.json" ) );
44
var operations = JSON.stringify( require( "../data/operations.json" ) );
5+
var selectionTests = JSON.stringify( require( "../data/selection-tests.json" ) );
56
var ldQuery = require( "../../src/ld-query" );
67
var should = require( "should" );
78

@@ -38,6 +39,12 @@ module.exports = function() {
3839

3940
} );
4041

42+
this.Given(/^the sample data containing selection tests is loaded$/, function () {
43+
44+
this.data = JSON.parse( selectionTests );
45+
46+
} );
47+
4148
this.Given(/^I construct an ldQuery object using the loaded data and <context>$/, function (table) {
4249

4350
this.context = JSON.parse( table.hashes()[ 0 ].context );
@@ -111,6 +118,12 @@ module.exports = function() {
111118

112119
} );
113120

121+
this.Then(/^there should be no result$/, function() {
122+
123+
should.not.exist( this.result );
124+
125+
} );
126+
114127
this.When(/^I query the result for "([^"]*)"$/, function( selector ) {
115128

116129
this.result = this.result.query( selector );

features/support/world.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ require( "should" );
33
function World() { }
44

55
module.exports = function() {
6-
6+
77
this.World = World;
8-
8+
99
};

0 commit comments

Comments
 (0)