/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*
 * Copyright (c) 2015, Joyent, Inc.
 */

var test = require('tape').test;


///--- Globals

var CIDR;
var lib;


///--- Tests

test('load library', function (t) {
  lib = require('../ip6addr.js');
  t.ok(lib);
  t.ok(CIDR = lib.createCIDR);
  t.end();
});

test('create - basic', function (t) {
  var addr = lib.parse('::1');
  var out = CIDR(addr, 128);
  t.ok(out);
  t.end();
});

@@ -318,16 +318,89 @@
 r lib;%0A%0A
+///--- Helpers%0A%0Afunction bc(input) %7B%0A  return CIDR.bind(null, input);%0A%7D%0A%0A
 %0A///--- 
@@ -580,76 +580,839 @@
 %7B%0A  
-var addr = lib.parse('::1');%0A  var out = CIDR(addr, 128);%0A  t.ok(out
+t.ok(CIDR(lib.parse('dead:beef::'), 64));%0A  t.ok(CIDR(lib.parse('192.168.0.0'), 24));%0A  t.end();%0A%7D);%0A%0Atest('create - parse', function (t) %7B%0A  t.ok(CIDR('192.168.0.0/24'));%0A  t.ok(CIDR('dead:beef::/48'));%0A  t.throws(bc('bogus'), null, 'bogus string');%0A  t.throws(bc('192.168.0.0/33'), null, 'long v4 prefix');%0A  t.throws(bc('dead:beef::/129'), null, 'long v6 prefix');%0A  t.end();%0A%7D);%0A%0Atest('contains v4', function (t) %7B%0A  var val = CIDR('192.168.0.0/24');%0A  t.ok(val.contains(lib.parse('192.168.0.0')), 'contains net');%0A  t.ok(val.contains(lib.parse('192.168.0.1')), 'contains address');%0A  t.ok(val.contains(lib.parse('192.168.0.255')), 'contains bcast');%0A  t.ok(val.contains(lib.parse('::ffff:192.168.0.1')), 'contains v4-mapped');%0A  t.notOk(val.contains(lib.parse('192.168.1.0')));%0A  t.notOk(val.contains(lib.parse('::c0a8:0001'))
 );%0A 

Improve CIDR tests