tdecaluwe / node-edifact

Javascript stream parser for UN/EDIFACT documents.
https://www.npmjs.com/package/edifact
Apache License 2.0
50 stars 13 forks source link

Fix 'should use special characters as defined in the UNA header test #24

Closed tophsic closed 7 years ago

tophsic commented 7 years ago

Tokenizer needs to be reinstantiated Fix #23

tdecaluwe commented 7 years ago

In fact, it is enough to call configure() on the tokenizer. The constructor does nearly exactly that, but this should make it clearer to read.

tophsic commented 7 years ago

If we call only configure(), we got all these errors:

> edifact@1.2.7 test /home/christophe/Dev/tdecaluwe/node-edifact
> istanbul cover -i "[^ies]*.js" --include-all-sources jasmine

Started
............F..FF.FF.........................

Failures:
1) Parser.write should use special characters as defined in the UNA header
  Message:
    Expected function not to throw, but it threw Error: Cannot close an incomplete message.
  Stack:
    Error: Expected function not to throw, but it threw Error: Cannot close an incomplete message.
        at Object.<anonymous> (/home/christophe/Dev/tdecaluwe/node-edifact/spec/ParserSpec.js:20:46)

2) Parser.write should call onopensegment when starting a new segment
  Message:
    Expected 1 to equal 2.
  Stack:
    Error: Expected 1 to equal 2.
        at Object.<anonymous> (/home/christophe/Dev/tdecaluwe/node-edifact/spec/ParserSpec.js:40:32)

3) Parser.write should call onclosesegment when terminating a segment
  Message:
    Expected 0 to equal 1.
  Stack:
    Error: Expected 0 to equal 1.
        at Object.<anonymous> (/home/christophe/Dev/tdecaluwe/node-edifact/spec/ParserSpec.js:48:32)

4) Parser.write should call onelement when finishing an new component
  Message:
    Expected 1 to equal 2.
  Stack:
    Error: Expected 1 to equal 2.
        at Object.<anonymous> (/home/christophe/Dev/tdecaluwe/node-edifact/spec/ParserSpec.js:68:32)

5) Parser.write should read characters preceded by the release character as data
  Message:
    Expected undefined to equal '?'.
  Stack:
    Error: Expected undefined to equal '?'.
        at Object.<anonymous> (/home/christophe/Dev/tdecaluwe/node-edifact/spec/ParserSpec.js:74:23)

45 specs, 5 failures
Finished in 0.043 seconds

I did not analyze why for instance.

tdecaluwe commented 7 years ago

~If I replace your fix by this._tokenizer.configure(this._configuration); everything works fine over here. All tests pass. Do you have any other changes in place?~

Was running an old version.

tdecaluwe commented 7 years ago

I fixed a different bug in the Tokenizer.configure method. Calling configure() when parsing the UNA should work now. Can you confirm?