Skip to content

Commit 04ecdc4

Browse files
committed
adds CREDITS, plus mocha tests for transpiled node
1 parent 7008f45 commit 04ecdc4

File tree

5 files changed

+142
-25
lines changed

5 files changed

+142
-25
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules/
2+
package-lock.json
3+
lib/netmask.js

CREDITS.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Credits
2+
=======
3+
4+
These credits refer to the contributors to this repository:
5+
6+
[@rs](https://github.com/rs) - maintainer
7+
8+
[@ryanrolds](https://github.com/ryanrolds) - Now with 0.4.x support. #2
9+
10+
[@palmerabollo](https://github.com/palmerabollo) - Expressions "1.2.3.4/" are not valid #6
11+
12+
[@steve-jansen](https://github.com/steve-jansen) - fixes typo in readme.md #7
13+
14+
[@jksdua](https://github.com/jksdua) - Added forEach helper to allow looping through usable IP addresses #9
15+
16+
[@gmiroshnykov](https://github.com/gmiroshnykov) - Tiny typo fix #10
17+
18+
[@TooTallNate](https://github.com/TooTallNate) - package: move "coffee-script" to devDependencies #11, README: fix small typo #12
19+
20+
[@yorkie](https://github.com/yorkie) - more rigid check for Netmask.constructor #13
21+
22+
[@runk](https://github.com/runk) - fix contains method for netmasks #18
23+
24+
[@yvesago](https://github.com/yvesago) - a patch with mocha test to fix /31 and /32 block.contains #20
25+
26+
[@meteormatt](https://github.com/meteormatt) - The comment in README.md is wrong #22
27+
28+
[@dschenkelman](https://github.com/dschenkelman) - Avoid large memory allocations when doing forEach in case netmask is large (e.g. /8) #34
29+
30+
[@sickcodes](https://github.com/sickcodes), [@kaoudis](https://github.com/kaoudis), [@Koroeskohr](https://github.com/Koroeskohr), [@nicksahler](https://github.com/nicksahler) - harden error handling, add a few more tests, and include CREDITS.md #36

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Installation
6060

6161
$ npm install netmask
6262

63+
Run all tests (vows plus mocha)
64+
-------------------------------
65+
66+
$ npm test
67+
6368
License
6469
-------
6570

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
"main": "./lib/netmask",
2424
"scripts": {
2525
"prepublish": "coffee -c lib/*.coffee",
26-
"test": "vows --spec test/*"
26+
"test": "coffee -c lib/*.coffee && vows --spec test/* && mocha tests/*"
2727
},
2828
"engines": {
2929
"node": ">= 0.4.0"
3030
},
3131
"devDependencies": {
3232
"coffee-script": ">=1.2.0",
33+
"mocha": "^8.3.2",
3334
"vows": "*"
3435
}
3536
}

tests/netmask.js

Lines changed: 103 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,103 @@
1-
/* some troubles with vows
2-
here is some mocha test
3-
4-
npm install
5-
mocha tests/netmask.js
6-
*/
7-
var assert = require('assert');
8-
9-
var Netmask = require('../').Netmask;
10-
11-
var block = new Netmask('10.1.2.0/24');
12-
var b1 = new Netmask('10.1.2.10/29');
13-
var b2 = new Netmask('10.1.2.10/31');
14-
var b3 = new Netmask('10.1.2.20/32');
15-
16-
console.log('first : '+b2.base);
17-
console.log('broadcast : '+b2.broadcast);
18-
console.log('last : ' + b2.last);
19-
20-
describe("Netmask contains bug", function() {
21-
assert.equal(block.contains(b1),true);
22-
assert.equal(block.contains(b2),true);
23-
assert.equal(block.contains(b3),true);
24-
});
1+
/* It is important to test our Javascript output as well as our coffeescript,
2+
* since code that is transpiled may be slightly different in effect from the
3+
* original.
4+
*
5+
* Run these tests (against lib/netmask.js, not lib/netmask.coffee directly)
6+
* using mocha, after re-generating lib/netmask.js including your changes:
7+
*
8+
* mocha tests/netmask.js
9+
*/
10+
11+
const assert = require('assert');
12+
const Netmask = require('../').Netmask;
13+
14+
describe('Netmask', () => {
15+
describe('can build a block', () => {
16+
let block = new Netmask('10.1.2.0/24');
17+
18+
it('should contain a sub-block', () => {
19+
let block1 = new Netmask('10.1.2.10/29');
20+
assert(block.contains(block1));
21+
});
22+
23+
it('should contain another sub-block', () => {
24+
let block2 = new Netmask('10.1.2.10/31');
25+
assert(block.contains(block2));
26+
});
27+
28+
it('should contain a third sub-block', () => {
29+
let block3 = new Netmask('10.1.2.20/32');
30+
assert(block.contains(block3));
31+
});
32+
});
33+
34+
describe('when presented with an octet which is not a number', () => {
35+
let block = new Netmask('192.168.0.0/29')
36+
37+
it('should throw', () => {
38+
assert.throws(() => block.contains('192.168.~.4'), Error);
39+
});
40+
});
41+
42+
describe('can handle hexadecimal, octal, & decimal octets in input IP', () => {
43+
let block1 = new Netmask('31.0.0.0/19');
44+
let block2 = new Netmask('127.0.0.0/8');
45+
let block3 = new Netmask('255.0.0.1/12');
46+
let block4 = new Netmask('10.0.0.1/8');
47+
let block5 = new Netmask('1.0.0.1/4');
48+
49+
describe('octal', () => {
50+
it('block 31.0.0.0/19 does not contain 031.0.5.5', () => {
51+
assert(!block1.contains('031.0.5.5'));
52+
});
53+
it('block 127.0.0.0/8 contains 0177.0.0.2 (127.0.0.2)', () => {
54+
assert(block2.contains('0177.0.0.2'));
55+
});
56+
it('block 255.0.0.1/12 does not contain 0255.0.0.2 (173.0.0.2)', () => {
57+
assert(!block3.contains('0255.0.0.2'));
58+
});
59+
it('block 10.0.0.1/8 contains 012.0.0.255 (10.0.0.255)', () => {
60+
assert(block4.contains('012.0.0.255'));
61+
});
62+
it('block 1.0.0.1/4 contains 01.02.03.04', () => {
63+
assert(block5.contains('01.02.03.04'));
64+
});
65+
});
66+
67+
describe('hexadecimal', () => {
68+
it('block 31.0.0.0/19 does not contain 0x31.0.5.5', () => {
69+
assert(!block1.contains('0x31.0.5.5'));
70+
});
71+
it('block 127.0.0.0/8 contains 0x7f.0.0.0x2 (127.0.0.2)', () => {
72+
assert(block2.contains('0x7f.0.0.0x2'));
73+
});
74+
it('block 255.0.0.1/12 contains 0xff.0.0.2', () => {
75+
assert(block3.contains('0xff.0.0.2'));
76+
});
77+
it('block 10.0.0.1/8 does not contain 0x10.0.0.255', () => {
78+
assert(!block4.contains('0x10.0.0.255'));
79+
});
80+
it('block 1.0.0.1/4 contains 0x1.0x2.0x3.0x4', () => {
81+
assert(block5.contains('0x1.0x2.0x3.0x4'));
82+
});
83+
});
84+
85+
describe('decimal', () => {
86+
it('block 31.0.0.0/19 contains 31.0.5.5', () => {
87+
assert(block1.contains('31.0.5.5'));
88+
});
89+
it('block 127.0.0.0/8 does not contain 128.0.0.2', () =>{
90+
assert(!block2.contains('128.0.0.2'));
91+
});
92+
it('block 255.0.0.1/12 contains 255.0.0.2', () => {
93+
assert(block3.contains('255.0.0.2'));
94+
});
95+
it('block 10.0.0.1/8 contains 10.0.0.255', () => {
96+
assert(block4.contains('10.0.0.255'));
97+
});
98+
it('block 1.0.0.1/4 contains 1.2.3.4', () => {
99+
assert(block5.contains('1.2.3.4'));
100+
});
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)