mirror of
https://github.com/fluencelabs/js-mafmt
synced 2025-04-25 17:42:27 +00:00
Use dignified.js
This commit is contained in:
parent
05dc53989d
commit
b04c5112fc
5
.gitignore
vendored
5
.gitignore
vendored
@ -1 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
|
|
||||||
|
lib
|
||||||
|
dist
|
||||||
|
|
||||||
|
*.log
|
||||||
|
17
package.json
17
package.json
@ -2,10 +2,15 @@
|
|||||||
"name": "mafmt",
|
"name": "mafmt",
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"description": "A multiaddr validator",
|
"description": "A multiaddr validator",
|
||||||
"main": "src/index.js",
|
"main": "lib/index.js",
|
||||||
|
"jsnext:main": "src/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "standard",
|
"lint": "dignified-lint",
|
||||||
"test": "node tests/test.js"
|
"build": "dignified-build",
|
||||||
|
"test": "dignified-test",
|
||||||
|
"test:node": "dignified-test node",
|
||||||
|
"test:browser": "dignified-test browser",
|
||||||
|
"release": "dignified-release"
|
||||||
},
|
},
|
||||||
"pre-commit": [
|
"pre-commit": [
|
||||||
"lint",
|
"lint",
|
||||||
@ -25,9 +30,9 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/whyrusleeping/js-mafmt#readme",
|
"homepage": "https://github.com/whyrusleeping/js-mafmt#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"pre-commit": "^1.1.2",
|
"chai": "^3.5.0",
|
||||||
"standard": "^6.0.8",
|
"dignified.js": "github:dignifiedquire/dignified.js",
|
||||||
"tape": "^4.4.0"
|
"pre-commit": "^1.1.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"multiaddr": "^1.3.0"
|
"multiaddr": "^1.3.0"
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
var multiaddr = require('multiaddr')
|
var multiaddr = require('multiaddr')
|
||||||
|
|
||||||
var IP = or(base('ip4'), base('ip6'))
|
var IP = or(base('ip4'), base('ip6'))
|
||||||
|
95
test/index.spec.js
Normal file
95
test/index.spec.js
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/* eslint-env mocha */
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
var expect = require('chai').expect
|
||||||
|
var mafmt = require('./../src')
|
||||||
|
|
||||||
|
describe('multiaddr validation', function () {
|
||||||
|
it('basic stuff works', function () {
|
||||||
|
var good_ip = [
|
||||||
|
'/ip4/0.0.0.0',
|
||||||
|
'/ip6/fc00::'
|
||||||
|
]
|
||||||
|
|
||||||
|
var bad_ip = [
|
||||||
|
'/ip4/0.0.0.0/tcp/555',
|
||||||
|
'/udp/789/ip6/fc00::'
|
||||||
|
]
|
||||||
|
|
||||||
|
var good_tcp = [
|
||||||
|
'/ip4/0.0.7.6/tcp/1234',
|
||||||
|
'/ip6/::/tcp/0'
|
||||||
|
]
|
||||||
|
|
||||||
|
var bad_tcp = [
|
||||||
|
'/tcp/12345',
|
||||||
|
'/ip6/fc00::/udp/5523/tcp/9543'
|
||||||
|
]
|
||||||
|
|
||||||
|
var good_udp = [
|
||||||
|
'/ip4/0.0.7.6/udp/1234',
|
||||||
|
'/ip6/::/udp/0'
|
||||||
|
]
|
||||||
|
|
||||||
|
var bad_udp = [
|
||||||
|
'/udp/12345',
|
||||||
|
'/ip6/fc00::/tcp/5523/udp/9543'
|
||||||
|
]
|
||||||
|
|
||||||
|
var good_utp = [
|
||||||
|
'/ip4/1.2.3.4/udp/3456/utp',
|
||||||
|
'/ip6/::/udp/0/utp'
|
||||||
|
]
|
||||||
|
|
||||||
|
var bad_utp = [
|
||||||
|
'/ip4/0.0.0.0/tcp/12345/utp',
|
||||||
|
'/ip6/::/ip4/0.0.0.0/udp/1234/utp'
|
||||||
|
]
|
||||||
|
|
||||||
|
var good_websockets = [
|
||||||
|
'/ip4/1.2.3.4/tcp/3456/websockets',
|
||||||
|
'/ip6/::/tcp/0/websockets'
|
||||||
|
]
|
||||||
|
|
||||||
|
var bad_websockets = [
|
||||||
|
'/ip4/0.0.0.0/tcp/12345/udp/2222/websockets',
|
||||||
|
'/ip6/::/ip4/0.0.0.0/udp/1234/websockets'
|
||||||
|
]
|
||||||
|
|
||||||
|
function assertMatches (p) {
|
||||||
|
var tests = Array.from(arguments).slice(1)
|
||||||
|
tests.forEach(function (test) {
|
||||||
|
test.forEach(function (testcase) {
|
||||||
|
expect(p.matches(testcase)).to.be.eql(true)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function assertMismatches (p) {
|
||||||
|
var tests = Array.from(arguments).slice(1)
|
||||||
|
tests.forEach(function (test) {
|
||||||
|
test.forEach(function (testcase) {
|
||||||
|
expect(p.matches(testcase)).to.be.eql(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
assertMatches(mafmt.IP, good_ip)
|
||||||
|
assertMismatches(mafmt.IP, bad_ip, good_tcp)
|
||||||
|
|
||||||
|
assertMatches(mafmt.TCP, good_tcp)
|
||||||
|
assertMismatches(mafmt.TCP, bad_tcp, good_ip)
|
||||||
|
|
||||||
|
assertMatches(mafmt.UDP, good_udp)
|
||||||
|
assertMismatches(mafmt.UDP, bad_udp, good_ip, good_tcp, good_utp)
|
||||||
|
|
||||||
|
assertMatches(mafmt.UTP, good_utp)
|
||||||
|
assertMismatches(mafmt.UTP, bad_utp, good_ip, good_tcp, good_udp)
|
||||||
|
|
||||||
|
assertMatches(mafmt.Reliable, good_utp, good_tcp)
|
||||||
|
assertMismatches(mafmt.Reliable, good_ip, good_udp)
|
||||||
|
|
||||||
|
assertMatches(mafmt.WebSockets, good_websockets)
|
||||||
|
assertMismatches(mafmt.WebSockets, good_ip, good_udp, bad_websockets)
|
||||||
|
})
|
||||||
|
})
|
@ -1,94 +0,0 @@
|
|||||||
var test = require('tape')
|
|
||||||
var mafmt = require('./../src')
|
|
||||||
|
|
||||||
test('basic stuff works', function (t) {
|
|
||||||
var good_ip = [
|
|
||||||
'/ip4/0.0.0.0',
|
|
||||||
'/ip6/fc00::'
|
|
||||||
]
|
|
||||||
|
|
||||||
var bad_ip = [
|
|
||||||
'/ip4/0.0.0.0/tcp/555',
|
|
||||||
'/udp/789/ip6/fc00::'
|
|
||||||
]
|
|
||||||
|
|
||||||
var good_tcp = [
|
|
||||||
'/ip4/0.0.7.6/tcp/1234',
|
|
||||||
'/ip6/::/tcp/0'
|
|
||||||
]
|
|
||||||
|
|
||||||
var bad_tcp = [
|
|
||||||
'/tcp/12345',
|
|
||||||
'/ip6/fc00::/udp/5523/tcp/9543'
|
|
||||||
]
|
|
||||||
|
|
||||||
var good_udp = [
|
|
||||||
'/ip4/0.0.7.6/udp/1234',
|
|
||||||
'/ip6/::/udp/0'
|
|
||||||
]
|
|
||||||
|
|
||||||
var bad_udp = [
|
|
||||||
'/udp/12345',
|
|
||||||
'/ip6/fc00::/tcp/5523/udp/9543'
|
|
||||||
]
|
|
||||||
|
|
||||||
var good_utp = [
|
|
||||||
'/ip4/1.2.3.4/udp/3456/utp',
|
|
||||||
'/ip6/::/udp/0/utp'
|
|
||||||
]
|
|
||||||
|
|
||||||
var bad_utp = [
|
|
||||||
'/ip4/0.0.0.0/tcp/12345/utp',
|
|
||||||
'/ip6/::/ip4/0.0.0.0/udp/1234/utp'
|
|
||||||
]
|
|
||||||
|
|
||||||
var good_websockets = [
|
|
||||||
'/ip4/1.2.3.4/tcp/3456/websockets',
|
|
||||||
'/ip6/::/tcp/0/websockets'
|
|
||||||
]
|
|
||||||
|
|
||||||
var bad_websockets = [
|
|
||||||
'/ip4/0.0.0.0/tcp/12345/udp/2222/websockets',
|
|
||||||
'/ip6/::/ip4/0.0.0.0/udp/1234/websockets'
|
|
||||||
]
|
|
||||||
|
|
||||||
function assertMatches (p) {
|
|
||||||
var tests = Array.from(arguments).slice(1)
|
|
||||||
tests.forEach(function (test) {
|
|
||||||
test.forEach(function (testcase) {
|
|
||||||
if (!p.matches(testcase)) {
|
|
||||||
t.fail('should have matched: ' + testcase + ' ' + p)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function assertMismatches (p) {
|
|
||||||
var tests = Array.from(arguments).slice(1)
|
|
||||||
tests.forEach(function (test) {
|
|
||||||
test.forEach(function (testcase) {
|
|
||||||
t.equal(p.matches(testcase), false, 'should not have matched: ' + testcase + ' ' + test)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
assertMatches(mafmt.IP, good_ip)
|
|
||||||
assertMismatches(mafmt.IP, bad_ip, good_tcp)
|
|
||||||
|
|
||||||
assertMatches(mafmt.TCP, good_tcp)
|
|
||||||
assertMismatches(mafmt.TCP, bad_tcp, good_ip)
|
|
||||||
|
|
||||||
assertMatches(mafmt.UDP, good_udp)
|
|
||||||
assertMismatches(mafmt.UDP, bad_udp, good_ip, good_tcp, good_utp)
|
|
||||||
|
|
||||||
assertMatches(mafmt.UTP, good_utp)
|
|
||||||
assertMismatches(mafmt.UTP, bad_utp, good_ip, good_tcp, good_udp)
|
|
||||||
|
|
||||||
assertMatches(mafmt.Reliable, good_utp, good_tcp)
|
|
||||||
assertMismatches(mafmt.Reliable, good_ip, good_udp)
|
|
||||||
|
|
||||||
assertMatches(mafmt.WebSockets, good_websockets)
|
|
||||||
assertMismatches(mafmt.WebSockets, good_ip, good_udp, bad_websockets)
|
|
||||||
|
|
||||||
t.end()
|
|
||||||
})
|
|
Loading…
x
Reference in New Issue
Block a user