|
| 1 | +var assert = require('assert'); |
| 2 | +var JsBarcode = require('../../bin/JsBarcode.js'); |
| 3 | +var Canvas = require("canvas"); |
| 4 | + |
| 5 | + |
| 6 | +describe('CODE93', function() { |
| 7 | + it('should be able to include the encoder(s)', function () { |
| 8 | + CODE93 = JsBarcode.getModule("CODE93"); |
| 9 | + CODE93FullASCII = JsBarcode.getModule("CODE93FullASCII"); |
| 10 | + }); |
| 11 | + |
| 12 | + it('should be able to encode normal text', function () { |
| 13 | + const encoded = "1010111101101010001101001001010010001010001001100101101110101001010111101"; |
| 14 | + |
| 15 | + var enc = new CODE93("AB12", {}); |
| 16 | + assert.equal(encoded, enc.encode().data); |
| 17 | + |
| 18 | + var enc = new CODE93FullASCII("AB12", {}); |
| 19 | + assert.equal(encoded, enc.encode().data); |
| 20 | + }); |
| 21 | + |
| 22 | + it('should be able to encode full ASCII', function () { |
| 23 | + // Lowercase characters |
| 24 | + var enc = new CODE93FullASCII("ABab12", {}); |
| 25 | + assert.equal("1010111101101010001101001001001100101101010001001100101101001001010010001010001001001100101011101101010111101", |
| 26 | + enc.encode().data); |
| 27 | + |
| 28 | + // Special characters |
| 29 | + var enc = new CODE93FullASCII("AB!*12", {}); |
| 30 | + assert.equal("1010111101101010001101001001110101101101010001110101101001101001010010001010001001100101001101011001010111101", |
| 31 | + enc.encode().data); |
| 32 | + |
| 33 | + // Non-printable ASCII characters |
| 34 | + var enc = new CODE93FullASCII("AB\x07\x09", {}); |
| 35 | + assert.equal("1010111101101010001101001001001001101011010001001001101011000101011010001011011001010111101", |
| 36 | + enc.encode().data); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should warn with invalid text', function () { |
| 40 | + // Lowercase characters |
| 41 | + var enc = new CODE93("ABab12", {}); |
| 42 | + assert.equal(false, enc.valid()); |
| 43 | + |
| 44 | + // Special characters |
| 45 | + var enc = new CODE93("AB!12", {}); |
| 46 | + assert.equal(false, enc.valid()); |
| 47 | + |
| 48 | + // Non-printable ASCII |
| 49 | + var enc = new CODE93("AB\x07 ", {}); |
| 50 | + assert.equal(false, enc.valid()); |
| 51 | + |
| 52 | + // Non-ASCII |
| 53 | + var enc = new CODE93FullASCII("ABð", {}); |
| 54 | + assert.equal(false, enc.valid()); |
| 55 | + }); |
| 56 | + |
| 57 | + it('should calculate correct checksums with special character checksum values', function () { |
| 58 | + var enc = new CODE93("ABCDEF123456", {}); |
| 59 | + assert.equal("1010111101101010001101001001101000101100101001100100101100010101010010001010001001010000101001010001001001001001000101001100101000101001010111101" |
| 60 | + , enc.encode().data); |
| 61 | + }); |
| 62 | + |
| 63 | + it('should work with text option', function () { |
| 64 | + var enc = new CODE93("AB12", {text: "THISISTEXT"}); |
| 65 | + assert.equal("THISISTEXT", enc.encode().text); |
| 66 | + }); |
| 67 | +}); |
0 commit comments