<commit_before>'use strict';

var t = require('chai').assert;
var s = require('./support');
var mqttr = require('../');

describe('Client', function () {

  var server, client;

  before(function (done) {
    s.createMqttServer({logger: {level: 'error'}}, function (err, _server) {
      if (err) throw err;
      server = _server;
      done();
    });
  });

  after(function (done) {
    server.close(done);
  });

  beforeEach(function (done) {
    client = mqttr.connect(server.url);
    client.once('connect', function () {
      done();
    });
  });

  afterEach(function (done) {
    client.end(done);
  });

  it('should work', function (done) {
    client.subscribe('$hello/:name', function (topic, payload, message) {
      t.equal(message.params.name, 'foo');
      t.deepEqual(payload, {a: 1});
      done();
    });

    client.publish('$hello/foo', {a: 1});

  });

  it('should work with two clients', function (done) {
    var client2 = mqttr.connect(server.url);
    client2.subscribe('$hello/:name', function (topic, payload, message) {
      t.equal(message.params.name, 'foo');
      t.deepEqual(payload, {a: 1});
      client2.end(done);
    });

    client2.ready(function () {
      client.publish('$hello/foo', {a: 1});
    });
  });

  it('should work with char wild char', function (done) {
    var data = {boo: 'foo'};
    client.subscribe('foo/*', function (topic, payload) {
      t.deepEqual(data, payload);
      done();
    });
    client.publish('foo/bar', data);
  });

  it('should work with params', function (done) {
    var data = {boo: 'foo'};
    client.subscribe('foo/:bar', function (topic, payload, route) {
      t.deepEqual(data, payload);
      t.equal(route.params.bar, 'bar');
      done();
    });
    client.publish('foo/bar', data);
  });

  it('should not received data when subscription cancelled', function (done) {
    var i = 0;
    var sub = client.subscribe('$hello/:name', function () {
      if (i === 0) return ++i;
      t.fail('Should not run here');
    });<commit_msg>Added tow wild char tests<commit_after>'use strict';

var t = require('chai').assert;
var s = require('./support');
var mqttr = require('../');

describe('Client', function () {

  var server, client;

  before(function (done) {
    s.createMqttServer({logger: {level: 'error'}}, function (err, _server) {
      if (err) throw err;
      server = _server;
      done();
    });
  });

  after(function (done) {
    server.close(done);
  });

  beforeEach(function (done) {
    client = mqttr.connect(server.url);
    client.once('connect', function () {
      done();
    });
  });

  afterEach(function (done) {
    client.end(done);
  });

  it('should work', function (done) {
    client.subscribe('$hello/:name', function (topic, payload, message) {
      t.equal(message.params.name, 'foo');
      t.deepEqual(payload, {a: 1});
      done();
    });

    client.publish('$hello/foo', {a: 1});

  });

  it('should work with two clients', function (done) {
    var client2 = mqttr.connect(server.url);
    client2.subscribe('$hello/:name', function (topic, payload, message) {
      t.equal(message.params.name, 'foo');
      t.deepEqual(payload, {a: 1});
      client2.end(done);
    });

    client2.ready(function () {
      client.publish('$hello/foo', {a: 1});
    });
  });

  it('should work with char wild char', function (done) {
    var data = {boo: 'foo'};
    client.subscribe('foo/*', function (topic, payload) {
      t.equal('foo/bar', topic);
      t.deepEqual(data, payload);
      done();
    });
    client.publish('foo/bar', data);
  });

  it('should work with two char wild char', function (done) {
    var data = {boo: 'foo'};
    client.subscribe('foo/**', function (topic, payload) {
      t.equal('foo/bar/hello', topic);
      t.deepEqual(data, payload);
      done();
    });
    client.publish('foo/bar/hello', data);
  });

  it('should work with params', function (done) {
    var data = {boo: 'foo'};
    client.subscribe('foo/:bar', function (topic, payload, route) {
      t.deepEqual(data, payload);
      t.equal(route.params.bar, 'bar');
      done();
    });
    client.publish('foo/bar', data);
  });

  it('should not received data when subscription cancelled', function (done) {
    var i = 0;
    var sub = client.subscribe('$hello/:name', function () {
      if (i === 0) return ++i;
      t.fail('Should not run here');
    });
{'fraction_non_alphanumeric': 0.19365079365079366, 'fraction_numerical': 0.0045351473922902496, 'mean_word_length': 2.938392857142857, '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': '7349490', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1431, 'n_words': 340}