<commit_before>'use strict';
var ModbusRTU = require("../index");
var TestPort = ModbusRTU.TestPort;
var testPort = new TestPort();
var modbusRTU = new ModbusRTU(testPort);

var expect = require('chai').expect;

describe('ModbusRTU', function() {
  
  describe('#open() - open serial port.', function () {
    it('should open the port without errors', function (done) {
      modbusRTU.open(function(err) {
        expect(err).to.be.a('null');
        
        done();
      });
    });
  });
  
  describe('#writeFC3() - read holding registers.', function () {
    it('should read 3 registers [0xa12b, 0xffff, 0xb21a] without errors', function (done) {
        modbusRTU.writeFC3(1, 8, 3, function(err, data) {
            expect(err).to.be.a('null');
            expect(data).to.have.property('data').with.length(3);
            expect(data.data.toString()).to.equal([0xa12b, 0xffff, 0xb21a].toString());
            done()
        });
    });
    
    it('should read raw buffer "a12bffffb21a" without errors', function (done) {
        modbusRTU.writeFC3(1, 8, 3, function(err, data) {
            expect(err).to.be.a('null');
            expect(data).to.have.property('buffer');
            expect(data.buffer.toString('hex')).to.equal("a12bffffb21a");
            done()
        });
    });
  });
  
  describe('#writeFC4() - read input registers.', function () {
    it('should read 3 registers [8, 9, 10] without errors', function (done) {
        modbusRTU.writeFC4(1, 8, 3, function(err, data) {
            expect(err).to.be.a('null');
            expect(data).to.have.property('data').with.length(3);
            expect(data.data.toString()).to.equal([8, 9, 10].toString());
            done()
        });
    });
    
    it('should fail on short data answer', function (done) {
        modbusRTU.writeFC4(2, 8, 1, function(err, data) {
            expect(err).to.equal('Data length error');
            
            done()
        });
    });
    
    it('should fail on CRC error', function (done) {
        modbusRTU.writeFC4(3, 8, 1, function(err, data) {
            expect(err).to.equal('CRC error');
            
            done()
        });
    });
    
    it('should fail on unexpected replay', function (done) {
        modbusRTU.writeFC4(4, 8, 1, function(err, data) {
            expect(err).to.equal('Unexpected data error');
            
            done()
        });
    });
  });
  
  describe('#writeFC16() - write holding registers.', function () {
    it('should write 3 registors [42, 128, 5] without errors', function (done) {
        modbusRTU.writeFC16(1, 8, [42, 128, 5], function(err, data) {
            expect(err).to.be.a('null');
            
            done()
        });
    });
    
    it('should fail on short data answer', function (done) {
        modbusRTU.writeFC16(2, 8, [42, 128, 5], function(err, data) {
            expect(err).to.equal('Data length error');
            
            done()
        });
    });
    
    it('should fail on CRC error', function (done) {
        modbusRTU.writeFC16(3, 8, [42, 128, 5], function(err, data) {
            expect(err).to.equal('CRC error');
            
            done()
        });
    });
    
    it('should fail on unexpected replay', function (done) {
        modbusRTU.writeFC16(4, 8, [42, 128, 5], function(err, data) {
            expect(err).to.equal('Unexpected data error');
            
            done()
        });
    });
  });
  
  describe('#writeFC3() - read holding registers after write.', function () {
    it('should read 3 registers [42, 128, 5] without errors', function (done) {
        modbusRTU.writeFC3(1, 8, 3, function(err, data) {<commit_msg>fix tests to work with new error strings<commit_after>'use strict';
var ModbusRTU = require("../index");
var TestPort = ModbusRTU.TestPort;
var testPort = new TestPort();
var modbusRTU = new ModbusRTU(testPort);

var expect = require('chai').expect;

describe('ModbusRTU', function() {
  
  describe('#open() - open serial port.', function () {
    it('should open the port without errors', function (done) {
      modbusRTU.open(function(err) {
        expect(err).to.be.a('null');
        
        done();
      });
    });
  });
  
  describe('#writeFC3() - read holding registers.', function () {
    it('should read 3 registers [0xa12b, 0xffff, 0xb21a] without errors', function (done) {
        modbusRTU.writeFC3(1, 8, 3, function(err, data) {
            expect(err).to.be.a('null');
            expect(data).to.have.property('data').with.length(3);
            expect(data.data.toString()).to.equal([0xa12b, 0xffff, 0xb21a].toString());
            done()
        });
    });
    
    it('should read raw buffer "a12bffffb21a" without errors', function (done) {
        modbusRTU.writeFC3(1, 8, 3, function(err, data) {
            expect(err).to.be.a('null');
            expect(data).to.have.property('buffer');
            expect(data.buffer.toString('hex')).to.equal("a12bffffb21a");
            done()
        });
    });
  });
  
  describe('#writeFC4() - read input registers.', function () {
    it('should read 3 registers [8, 9, 10] without errors', function (done) {
        modbusRTU.writeFC4(1, 8, 3, function(err, data) {
            expect(err).to.be.a('null');
            expect(data).to.have.property('data').with.length(3);
            expect(data.data.toString()).to.equal([8, 9, 10].toString());
            done()
        });
    });
    
    it('should fail on short data answer', function (done) {
        modbusRTU.writeFC4(2, 8, 1, function(err, data) {
            expect(err).to.have.string('Data length error');
            
            done()
        });
    });
    
    it('should fail on CRC error', function (done) {
        modbusRTU.writeFC4(3, 8, 1, function(err, data) {
            expect(err).to.have.string('CRC error');
            
            done()
        });
    });
    
    it('should fail on unexpected replay', function (done) {
        modbusRTU.writeFC4(4, 8, 1, function(err, data) {
            expect(err).to.have.string('Unexpected data error');
            
            done()
        });
    });
  });
  
  describe('#writeFC16() - write holding registers.', function () {
    it('should write 3 registors [42, 128, 5] without errors', function (done) {
        modbusRTU.writeFC16(1, 8, [42, 128, 5], function(err, data) {
            expect(err).to.be.a('null');
            
            done()
        });
    });
    
    it('should fail on short data answer', function (done) {
        modbusRTU.writeFC16(2, 8, [42, 128, 5], function(err, data) {
            expect(err).to.have.string('Data length error');
            
            done()
        });
    });
    
    it('should fail on CRC error', function (done) {
        modbusRTU.writeFC16(3, 8, [42, 128, 5], function(err, data) {
            expect(err).to.have.string('CRC error');
            
            done()
        });
    });
    
    it('should fail on unexpected replay', function (done) {
        modbusRTU.writeFC16(4, 8, [42, 128, 5], function(err, data) {
            expect(err).to.have.string('Unexpected data error');
            
            done()
        });
    });
  });
  
  describe('#writeFC3() - read holding registers after write.', function () {
    it('should read 3 registers [42, 128, 5] without errors', function (done) {
        modbusRTU.writeFC3(1, 8, 3, function(err, data) {
{'fraction_non_alphanumeric': 0.16673400673400673, 'fraction_numerical': 0.03259259259259259, 'mean_word_length': 2.1280539174389217, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4349531', 'n_tokens_mistral': 2460, 'n_tokens_neox': 2299, 'n_words': 525}