Skip to content

Commit

Permalink
Fix generator for ADD, MOVE, COPY (#151)
Browse files Browse the repository at this point in the history
* Add failing test case for SPARQL 1.1 graph mgmt operations

The test case currently fails and will drop <http://example.com/my-graph>

* Fix sparql generator for SPARQL 1.1 update ADD, MOVE, COPY operations

Previously the generator incorrectly omitted the source graph.

Reference https://www.w3.org/TR/sparql11-update/#copy
  • Loading branch information
QuarksToQuasars authored May 24, 2022
1 parent a80062a commit 2d084c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/SparqlGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ Generator.prototype.toUpdate = function (update) {
case 'add':
case 'copy':
case 'move':
return update.type.toUpperCase() + (update.source.default ? ' DEFAULT ' : ' ') +
'TO ' + this.toEntity(update.destination.name);
return update.type.toUpperCase()+ ' ' + (update.silent ? 'SILENT ' : '') + (update.source.default ? 'DEFAULT' : this.toEntity(update.source.name)) +
' TO ' + this.toEntity(update.destination.name);
case 'create':
case 'clear':
case 'drop':
Expand Down
30 changes: 30 additions & 0 deletions test/SparqlGenerator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,36 @@ describe('A SPARQL generator', function () {
'GROUP BY ?k';
expect(generatedQuery).toEqual(expectedQuery);
});

it('should preserve source graph in sparql 1.1 update ADD operation', function () {
var parser = new SparqlParser();
var parsedQuery = parser.parse('ADD <http://example.com/my-graph> TO <http://example.com/your-graph>');
var generator = new SparqlGenerator();
var generatedQuery = generator.stringify(parsedQuery);
var expectedQuery =
'ADD <http://example.com/my-graph> TO <http://example.com/your-graph>';
expect(generatedQuery).toEqual(expectedQuery);
});

it('should preserve source, default graph in sparql 1.1 update MOVE operation', function () {
var parser = new SparqlParser();
var parsedQuery = parser.parse('MOVE DEFAULT TO <http://example.org/named>');
var generator = new SparqlGenerator();
var generatedQuery = generator.stringify(parsedQuery);
var expectedQuery =
'MOVE DEFAULT TO <http://example.org/named>';
expect(generatedQuery).toEqual(expectedQuery);
});

it('should preserve source, default graph in sparql 1.1 update MOVE operation', function () {
var parser = new SparqlParser();
var parsedQuery = parser.parse('COPY SILENT DEFAULT TO <http://example.org/named>');
var generator = new SparqlGenerator();
var generatedQuery = generator.stringify(parsedQuery);
var expectedQuery =
'COPY SILENT DEFAULT TO <http://example.org/named>';
expect(generatedQuery).toEqual(expectedQuery);
});
});

function testQueries(directory, settings) {
Expand Down

0 comments on commit 2d084c3

Please sign in to comment.