rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
714 stars 130 forks source link

DataFactory tests for Triple and Quad insinuate unquoted literals are acceptable #305

Closed rorlic closed 2 years ago

rorlic commented 2 years ago

The Triple and Quads tests in the DataFactory tests use literals without double-quotes insinuated that a Literal can be created as follows:

new Literal('abc')

however the Literal value is defined as:

  // ### The text value of this literal
  get value() {
    return this.id.substring(1, this.id.lastIndexOf('"'));
  }

which will return a as the value, not abc: A simple test proves that:

  describe('A literal value without quotes', () => {
    it('should equal that value', () => {
      new Literal('abc').value.should.be.equal('abc');
    })
  })

results in:

  1542 passing (950ms)
  1 failing

  1) Literal
       A literal value without quotes
         should equal that value:

      AssertionError: expected 'a' to equal 'abc'
      + expected - actual

      -a
      +abc

      at Context.<anonymous> (test/Literal-test.js:644:42)
      at processImmediate (node:internal/timers:471:21)

Can I assume that the tests are wrong and should all contain literals as follows?

new Literal('"abc"')

Or can a Literal be created as an unquoted string, and is the value implementation not correct?

RubenVerborgh commented 2 years ago

The Triple and Quads tests in the DataFactory tests use literals without double-quotes insinuated that a Literal can be created as follows:

new Literal('abc')

This is an internal data structure that is not exposed; the dataFactory interface should be used, which exposes .literal.