CODE39.test.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. var assert = require('assert');
  2. var JsBarcode = require('../../bin/JsBarcode.js');
  3. var Canvas = require("canvas");
  4. describe('CODE39', function() {
  5. it('should be able to include the encoder(s)', function () {
  6. CODE39 = JsBarcode.getModule("CODE39");
  7. });
  8. it('should be able to encode normal text', function () {
  9. var enc = new CODE39("AB12", {});
  10. assert.equal("100010111011101011101010001011101011101000101110111010001010111010111000101011101000101110111010"
  11. , enc.encode().data);
  12. });
  13. it('should warn with invalid text', function () {
  14. var enc = new CODE39("AB!12", {});
  15. assert.equal(false, enc.valid());
  16. });
  17. it('should make lowercase to uppercase', function () {
  18. var enc = new CODE39("abc123ABC", {});
  19. assert.equal("ABC123ABC", enc.encode().text);
  20. });
  21. it('should calculate correct checksums', function () {
  22. var enc = new CODE39("ABCDEFG", {mod43: true});
  23. assert.equal("1000101110111010111010100010111010111010001011101110111010001010101011100010111011101011100010101011101110001010101010001110111011101000111010101000101110111010"
  24. , enc.encode().data);
  25. });
  26. it('should work with text option', function () {
  27. var enc = new CODE39("AB12", {text: "THISISTEXT"});
  28. assert.equal("THISISTEXT", enc.encode().text);
  29. });
  30. });