-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
193 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,196 +1,199 @@ | ||
/* eslint-disable unicorn/filename-case */ | ||
/* global describe, it */ | ||
|
||
const should = require('should'); | ||
const mw = require('../nodes/lib/mqtt-wildcard.js'); | ||
|
||
should.Assertion.add('arrayEqual', function (other) { | ||
this.params = {operator: 'to be have same items'}; | ||
describe('mqtt-wildcard', () => { | ||
should.Assertion.add('arrayEqual', function (other) { | ||
this.params = {operator: 'to be have same items'}; | ||
|
||
for (const [index, item] of this.obj.entries()) { | ||
//both arrays should at least contain the same items | ||
other[index].should.equal(item); | ||
} | ||
for (const [index, item] of this.obj.entries()) { | ||
//both arrays should at least contain the same items | ||
other[index].should.equal(item); | ||
} | ||
|
||
// both arrays need to have the same number of items | ||
this.obj.length.should.be.equal(other.length); | ||
}); | ||
|
||
describe('trivial matching', () => { | ||
it('should return the correct array when topic equals wildcard', () => { | ||
mw('test/123', 'test/123').should.arrayEqual([]); | ||
// both arrays need to have the same number of items | ||
this.obj.length.should.be.equal(other.length); | ||
}); | ||
}); | ||
|
||
describe('mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test/test/test', 'test/test')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test/test/test', 'test/test')).equal(null); | ||
describe('trivial matching', () => { | ||
it('should return the correct array when topic equals wildcard', () => { | ||
mw('test/123', 'test/123').should.arrayEqual([]); | ||
}); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'test/test/test')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'test/test/test/test')).equal(null); | ||
}); | ||
}); | ||
|
||
describe('wildcard # matching', () => { | ||
it('should return the correct array when wildcard is #', () => { | ||
mw('test', '#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array when wildcard is #', () => { | ||
mw('test/test', '#').should.arrayEqual(['test/test']); | ||
}); | ||
it('should return the correct array when wildcard is #', () => { | ||
mw('test/test/test', '#').should.arrayEqual(['test/test/test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test', 'test/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/#').should.arrayEqual(['test/test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/test/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/', '/#').should.arrayEqual(['']); | ||
describe('mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test/test/test', 'test/test')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test/test/test', 'test/test')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'test/test/test')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'test/test/test/test')).equal(null); | ||
}); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/test', '/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/test/', '/#').should.arrayEqual(['test/']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/test/test', '/#').should.arrayEqual(['test/test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/', 'test/#').should.arrayEqual(['']); | ||
}); | ||
it('should return correct array', () => { | ||
mw('test', 'test/#').should.arrayEqual([]); | ||
}); | ||
it('should return correct array', () => { | ||
mw('test/test', 'test/test/#').should.arrayEqual([]); | ||
}); | ||
}); | ||
|
||
describe('wildcard # mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test', '/#')).equal(null); | ||
describe('wildcard # matching', () => { | ||
it('should return the correct array when wildcard is #', () => { | ||
mw('test', '#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array when wildcard is #', () => { | ||
mw('test/test', '#').should.arrayEqual(['test/test']); | ||
}); | ||
it('should return the correct array when wildcard is #', () => { | ||
mw('test/test/test', '#').should.arrayEqual(['test/test/test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test', 'test/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/#').should.arrayEqual(['test/test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/test/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/', '/#').should.arrayEqual(['']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/test', '/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/test/', '/#').should.arrayEqual(['test/']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('/test/test', '/#').should.arrayEqual(['test/test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/', 'test/#').should.arrayEqual(['']); | ||
}); | ||
it('should return correct array', () => { | ||
mw('test', 'test/#').should.arrayEqual([]); | ||
}); | ||
it('should return correct array', () => { | ||
mw('test/test', 'test/test/#').should.arrayEqual([]); | ||
}); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'muh/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('', 'muh/#')).equal(null); | ||
}); | ||
}); | ||
|
||
describe('wildcard + matching', () => { | ||
it('should return the correct array', () => { | ||
mw('test', '+').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/', 'test/+').should.arrayEqual(['']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test', 'test/+').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/+').should.arrayEqual(['test', 'test']); | ||
describe('wildcard # mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test', '/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'muh/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('', 'muh/#')).equal(null); | ||
}); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/test').should.arrayEqual(['test']); | ||
}); | ||
}); | ||
|
||
describe('wildcard + mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test', '/+')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test', 'test/+')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'test/test/+')).equal(null); | ||
describe('wildcard + matching', () => { | ||
it('should return the correct array', () => { | ||
mw('test', '+').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/', 'test/+').should.arrayEqual(['']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test', 'test/+').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/+').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/test').should.arrayEqual(['test']); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('wildcard +/# matching', () => { | ||
it('should return the correct array', () => { | ||
mw('test/test', '+/#').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/', '+/test/#').should.arrayEqual(['test', '']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/', 'test/+/#').should.arrayEqual(['test', '']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', '+/test/#').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/#').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', '+/+/#').should.arrayEqual(['test', 'test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test/test', 'test/+/+/#').should.arrayEqual(['test', 'test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test', '+/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test', 'test/+/#').should.arrayEqual(['test']); | ||
describe('wildcard + mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test', '/+')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test', 'test/+')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/test', 'test/test/+')).equal(null); | ||
}); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/test/#').should.arrayEqual(['test']); | ||
}); | ||
}); | ||
|
||
describe('wildcard +/# mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test/foo/test', '+/test/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('foo/test/test', 'test/+/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('foo/test/test/test', 'test/+/+/#')).equal(null); | ||
describe('wildcard +/# matching', () => { | ||
it('should return the correct array', () => { | ||
mw('test/test', '+/#').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/', '+/test/#').should.arrayEqual(['test', '']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/', 'test/+/#').should.arrayEqual(['test', '']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', '+/test/#').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/#').should.arrayEqual(['test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', '+/+/#').should.arrayEqual(['test', 'test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test/test', 'test/+/+/#').should.arrayEqual(['test', 'test', 'test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test', '+/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test', 'test/+/#').should.arrayEqual(['test']); | ||
}); | ||
it('should return the correct array', () => { | ||
mw('test/test/test', 'test/+/test/#').should.arrayEqual(['test']); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('examples', () => { | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar', 'test/+/bar')).arrayEqual(['foo']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar', 'test/#')).arrayEqual(['foo/bar']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar/baz', 'test/+/#')).arrayEqual(['foo', 'bar/baz']); | ||
describe('wildcard +/# mismatching', () => { | ||
it('should return null', () => { | ||
should(mw('test/foo/test', '+/test/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('foo/test/test', 'test/+/#')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('foo/test/test/test', 'test/+/+/#')).equal(null); | ||
}); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar/baz', 'test/+/+/baz')).arrayEqual(['foo', 'bar']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test', 'test/#')).arrayEqual([]); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/', 'test/#')).arrayEqual(['']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar/baz', 'test/+/+/baz/#')).arrayEqual(['foo', 'bar']); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/foo/bar', 'test/+')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/foo/bar', 'test/nope/bar')).equal(null); | ||
|
||
describe('examples', () => { | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar', 'test/+/bar')).arrayEqual(['foo']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar', 'test/#')).arrayEqual(['foo/bar']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar/baz', 'test/+/#')).arrayEqual(['foo', 'bar/baz']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar/baz', 'test/+/+/baz')).arrayEqual(['foo', 'bar']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test', 'test/#')).arrayEqual([]); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/', 'test/#')).arrayEqual(['']); | ||
}); | ||
it('should return the correct array', () => { | ||
should(mw('test/foo/bar/baz', 'test/+/+/baz/#')).arrayEqual(['foo', 'bar']); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/foo/bar', 'test/+')).equal(null); | ||
}); | ||
it('should return null', () => { | ||
should(mw('test/foo/bar', 'test/nope/bar')).equal(null); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.