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

Test 'Parser.write should use special characters as defined in the UNA header' fail #23

Closed tophsic closed 7 years ago

tophsic commented 7 years ago

Hi,

On development branch with node 7.2.0, tests suite fail on 'Parser.write should use special characters as defined in the UNA header'.

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

Started
............F................................

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)

45 specs, 1 failure
Finished in 0.035 seconds

=============================================================================
Writing coverage object [/home/christophe/Dev/tdecaluwe/node-edifact/coverage/coverage.json]
Writing coverage reports at [/home/christophe/Dev/tdecaluwe/node-edifact/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 83.02% ( 357/430 )
Branches     : 81.21% ( 134/165 )
Functions    : 72.6% ( 53/73 )
Lines        : 83.02% ( 357/430 )
================================================================================
npm ERR! Test failed.  See above for more details.

As I was looking why, I suppose this is because Tokenizer is instantiated before settings configuration from UNA header and take default Configuration settings.

Do you have any idea how to solve this ?

tophsic commented 7 years ago

I wanted to write a test to use a different decimal separator but I am not familiar enough with UN/EDIFACT format :disappointed:

tdecaluwe commented 7 years ago

I get the same error here, I'll look into your fix.

You can use a different decimal separator by specifying it in the UNA header. Or set it manually in the Configuration object.

tophsic commented 7 years ago

I manage to change decimal separator in the UNA header (using fix in my PR) but I just did not manage to write a test on this case.

tdecaluwe commented 7 years ago

I see, for this to work you need to include a number component and make sure it's being parsed as a number. So you should include the corresponding segment and element definitions. For example:

validator.define({
  'QVR': { requires: 0, elements: ['C279', '4221', 'C960'] }
});
validator.define({
  'C279': { requires: 1, components: ['n..15', 'an..3'] }
});