Annotate

tests/test_util_ip.lua @ 5606:3dc141acf381

test_util_ip: Add tests for IP matching
author Matthew Wild <mwild1@gmail.com>
date Sat, 18 May 2013 17:44:01 +0100
parent 5604:6df0ec991f2e
child 5607:eee23fb79a5e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5604
6df0ec991f2e tests: Some much-needed cleanup...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1
5606
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
2 function match(match)
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
3 local _ = require "util.ip".new_ip;
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
4 local ip = _"10.20.30.40";
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
5 assert_equal(match(ip, _"10.0.0.0", 8), true);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
6 assert_equal(match(ip, _"10.0.0.0", 16), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
7 assert_equal(match(ip, _"10.0.0.0", 24), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
8 assert_equal(match(ip, _"10.0.0.0", 32), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
9
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
10 assert_equal(match(ip, _"10.20.0.0", 8), true);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
11 assert_equal(match(ip, _"10.20.0.0", 16), true);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
12 assert_equal(match(ip, _"10.20.0.0", 24), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
13 assert_equal(match(ip, _"10.20.0.0", 32), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
14
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
15 assert_equal(match(ip, _"0.0.0.0", 32), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
16 assert_equal(match(ip, _"0.0.0.0", 0), true);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
17 assert_equal(match(ip, _"0.0.0.0"), false);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
18
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
19 assert_equal(match(ip, _"10.0.0.0", 255), false, "excessive number of bits");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
20 assert_equal(match(ip, _"10.0.0.0", -8), true, "negative number of bits");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
21 assert_equal(match(ip, _"10.0.0.0", -32), true, "negative number of bits");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
22 assert_equal(match(ip, _"10.0.0.0", 0), true, "zero bits");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
23 assert_equal(match(ip, _"10.0.0.0"), false, "no specified number of bits (differing ip)");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
24 assert_equal(match(ip, _"10.20.30.40"), true, "no specified number of bits (same ip)");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
25
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
26 assert_equal(match(_"80.244.94.84", _"80.244.94.84"), true, "simple ip");
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
27
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
28 assert_equal(match(_"8.8.8.8", _"8.8.0.0", 16), true);
3dc141acf381 test_util_ip: Add tests for IP matching
Matthew Wild <mwild1@gmail.com>
parents: 5604
diff changeset
29 assert_equal(match(_"8.8.4.4", _"8.8.0.0", 16), true);
5604
6df0ec991f2e tests: Some much-needed cleanup...
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 end