Skip to content

Commit

Permalink
Merge branch 'development' into stream
Browse files Browse the repository at this point in the history
  • Loading branch information
tdecaluwe committed Oct 31, 2016
2 parents 23bafc6 + 0bc5731 commit 01f0249
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ such, also it's associated overhead.
## Classes

| Class | Description |
| ----- | ----------- |
| ----: | :---------- |
| [Parser](#Parser) | The `Parser` class encapsulates an online parsing algorithm. By itself it doesn't do anything useful, however the parser can be extended through several event callbacks. |
| [Tracker](#Tracker) | A utility class which validates segment order against a given message structure. |
| [Validator](#Validator) | The `Validator` can be used as an add-on to the `Parser` class, to enable validation of segments, elements and components. This class implements a tolerant validator, only segments and elements for which definitions are provided will be validated. Other segments or elements will pass through untouched. Validation includes:<ul><li>Checking data element counts, including mandatory elements.</li><li>Checking component counts, including mandatory components.</li><li>Checking components against their required format.</li> |
Expand All @@ -167,7 +167,7 @@ new Parser([validator])
```

| Function | Description |
| -------- | ----------- |
| -------: | :---------- |
| `on(event,callback)` | Add a listener for a specific event. The event can be any of `opensegment`, `element`, `component` and `closesegment`. |
| `write(chunk)` | Write a chunk of data to the parser |
| `end()` | Terminate the EDI interchange |
Expand All @@ -183,7 +183,7 @@ new Tracker(table)
```

| Function | Description |
| -------- | ----------- |
| -------: | :---------- |
| `accept(segment)` | Match a segment to the message structure and update the current position of the tracker. |
| `reset()` | Reset the tracker to the initial position of the current segment table. |

Expand All @@ -199,7 +199,7 @@ new Validator()
```

| Function | Description |
| -------- | ----------- |
| -------: | :---------- |
| `disable()` | Disable validation. |
| `enable()` | Enable validation. |
| `define(definitions)` | Provision the validator with an array of segment and element definitions. |
Expand Down
2 changes: 1 addition & 1 deletion configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Configuration.prototype.delimiters = function () {
// Sort the array of excluded characters using a sorting network.
compareAndSwap(exclude, 1, 2);
compareAndSwap(exclude, 3, 4);
compareAndSwap(exclude, 1, 2);
compareAndSwap(exclude, 1, 3);
compareAndSwap(exclude, 0, 2);
compareAndSwap(exclude, 2, 4);
compareAndSwap(exclude, 0, 3);
Expand Down
56 changes: 56 additions & 0 deletions spec/ConfigurationSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict'

let Configuration = require('../configuration.js');

describe('Configuration', function () {
let configuration;
beforeEach(function () {
configuration = new Configuration();
});
it('should accept known encodings', function () {
expect(function () { configuration.encoding('UNOA'); }).not.toThrow();
expect(function () { configuration.encoding('UNOB'); }).not.toThrow();
expect(function () { configuration.encoding('UNOC'); }).not.toThrow();
});
it('should reject unknown encodings', function () {
expect(function () { configuration.encoding('ENCODING'); }).toThrow();
});
it('should return the delimiters as a sorted array', function () {
var count = 0;

var run = function (permutation) {
var delimiters;

configuration.ST = permutation[0];
configuration.DES = permutation[1];
configuration.CDS = permutation[2];
configuration.DM = permutation[3];
configuration.RC = permutation[4];

delimiters = configuration.delimiters();
for (var i = 1; i < delimiters.length; i++) {
expect(delimiters[i]).toBeGreaterThan(delimiters[i - 1]);
}
count++;
}

var permute = function (head, tail, callback) {
var item;
if (tail.length === 0) {
callback(head);
} else {
for (var i = 0; i < tail.length; i++) {
item = tail[i];
tail.splice(i, 1);
head.push(item);
permute(head, tail, callback);
head.pop();
tail.splice(i, 0, item);
}
}
}

permute([], [0, 1, 2, 3, 4], run);
expect(count).toEqual(120);
});
});

0 comments on commit 01f0249

Please sign in to comment.