<commit_before>'use strict';

var assert = require('chai').assert
  , SLIP = require('../src/slip.js')
  , fs = require('fs')
  , conf = JSON.parse(fs.readFileSync('test/test-config.json', {encoding: 'utf8'}))

describe('SLIP class', function () {

  it('exists', function(){
    assert.isFunction(SLIP)
  })

  it('inherits SerialPort class', function(){
    assert.isFunction(SLIP.prototype.write)
  })

  describe('SLIP instance', function () {

    var slip = null
    before(function () {
      slip = new SLIP(conf.serailPort.path, conf.serailPort.options, conf.protocol)
    })

    it('has same methods as SerialPort instances via inheritance', function(){
      assert.isFunction(slip.write)
    })

    it('has protocol_ defined', function(){
      assert.isObject(slip.protocol_)
    })

    it('has sendMessage method', function(){
      assert.isFunction(slip.sendMessage)
    })

    it('has collectDataAndFireMessageEvent_ method', function(done){
      slip.on('message', function (buf) {
        assert.isTrue(buf.equals(new Buffer([0x20, 0x24])))
        done()
      })
      slip.collectDataAndFireMessageEvent_(new Buffer([0x20, 0x24, 0xc0, 0x22, 0x21]))
    })

  })

})<commit_msg>Better coverage for SLIP class<commit_after>'use strict';

var assert = require('chai').assert
  , SLIP = require('../src/slip.js')
  , fs = require('fs')
  , conf = JSON.parse(fs.readFileSync('test/test-config.json', {encoding: 'utf8'}))

describe('SLIP class', function () {

  it('exists', function(){
    assert.isFunction(SLIP)
  })

  it('inherits SerialPort class', function(){
    assert.isFunction(SLIP.prototype.write)
  })

  describe('SLIP instance', function () {

    var slip = null
    before(function () {
      slip = new SLIP(conf.serailPort.path, conf.serailPort.options, conf.protocol)
    })

    it('has same methods as SerialPort instances via inheritance', function(){
      assert.isFunction(slip.write)
    })

    it('has protocol_ defined', function(){
      assert.isObject(slip.protocol_)
    })

    it('has sendMessage method that send message to seriaport', function(done){
      assert.isFunction(slip.sendMessage)
      slip.sendMessage(new Buffer([0]), function (err) {
        assert.isTrue(err.message == 'Serialport not open.')
        done()
      })
    })

    it('has collectDataAndFireMessageEvent_ method', function(done){
      slip.collectDataAndFireMessageEvent_(new Buffer([0x22]))
      slip.on('message', function (buf) {
        assert.isTrue(buf.equals(new Buffer([0x22, 0x20, 0x24])))
        done()
      })
      slip.collectDataAndFireMessageEvent_(new Buffer([0x20, 0x24, 0xc0, 0x22, 0x21]))
    })

  })

})
{'fraction_non_alphanumeric': 0.15462373642830401, 'fraction_numerical': 0.018345189067764882, 'mean_word_length': 3.453333333333333, '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': '6228482', 'n_tokens_mistral': 892, 'n_tokens_neox': 851, 'n_words': 167}