Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use dignified.js #4

Merged
merged 1 commit into from
Mar 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
node_modules

lib
dist

*.log
17 changes: 11 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
"name": "mafmt",
"version": "1.0.1",
"description": "A multiaddr validator",
"main": "src/index.js",
"main": "lib/index.js",
"jsnext:main": "src/index.js",
"scripts": {
"lint": "standard",
"test": "node tests/test.js"
"lint": "dignified-lint",
"build": "dignified-build",
"test": "dignified-test",
"test:node": "dignified-test node",
"test:browser": "dignified-test browser",
"release": "dignified-release"
},
"pre-commit": [
"lint",
Expand All @@ -25,9 +30,9 @@
},
"homepage": "https://github.com/whyrusleeping/js-mafmt#readme",
"devDependencies": {
"pre-commit": "^1.1.2",
"standard": "^6.0.8",
"tape": "^4.4.0"
"chai": "^3.5.0",
"dignified.js": "github:dignifiedquire/dignified.js",
"pre-commit": "^1.1.2"
},
"dependencies": {
"multiaddr": "^1.3.0"
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict'

var multiaddr = require('multiaddr')

var IP = or(base('ip4'), base('ip6'))
Expand Down
95 changes: 95 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
94 changes: 0 additions & 94 deletions tests/test.js

This file was deleted.