ipaddress 0.2.5 → 0.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/src/crunchy.d.ts +130 -0
  2. package/dist/src/crunchy.d.ts.map +1 -0
  3. package/dist/src/crunchy.js +616 -0
  4. package/dist/src/index.d.ts +13 -0
  5. package/dist/src/index.d.ts.map +1 -0
  6. package/dist/src/index.js +21 -0
  7. package/{ip_bits.d.ts → dist/src/ip_bits.d.ts} +6 -7
  8. package/dist/src/ip_bits.d.ts.map +1 -0
  9. package/dist/src/ip_bits.js +133 -0
  10. package/{ip_version.d.ts → dist/src/ip_version.d.ts} +2 -1
  11. package/dist/src/ip_version.d.ts.map +1 -0
  12. package/dist/src/ip_version.js +6 -0
  13. package/{ipaddress.d.ts → dist/src/ipaddress.d.ts} +38 -35
  14. package/dist/src/ipaddress.d.ts.map +1 -0
  15. package/dist/src/ipaddress.js +1243 -0
  16. package/dist/src/ipv4.d.ts +15 -0
  17. package/dist/src/ipv4.d.ts.map +1 -0
  18. package/dist/src/ipv4.js +187 -0
  19. package/dist/src/ipv6.d.ts +13 -0
  20. package/dist/src/ipv6.d.ts.map +1 -0
  21. package/dist/src/ipv6.js +190 -0
  22. package/dist/src/ipv6_loopback.d.ts +6 -0
  23. package/dist/src/ipv6_loopback.d.ts.map +1 -0
  24. package/dist/src/ipv6_loopback.js +51 -0
  25. package/dist/src/ipv6_mapped.d.ts +6 -0
  26. package/dist/src/ipv6_mapped.d.ts.map +1 -0
  27. package/dist/src/ipv6_mapped.js +159 -0
  28. package/dist/src/ipv6_unspec.d.ts +6 -0
  29. package/dist/src/ipv6_unspec.d.ts.map +1 -0
  30. package/dist/src/ipv6_unspec.js +57 -0
  31. package/{prefix.d.ts → dist/src/prefix.d.ts} +10 -7
  32. package/dist/src/prefix.d.ts.map +1 -0
  33. package/dist/src/prefix.js +142 -0
  34. package/dist/src/prefix128.d.ts +7 -0
  35. package/dist/src/prefix128.d.ts.map +1 -0
  36. package/dist/src/prefix128.js +39 -0
  37. package/dist/src/prefix32.d.ts +7 -0
  38. package/dist/src/prefix32.d.ts.map +1 -0
  39. package/dist/src/prefix32.js +29 -0
  40. package/dist/src/rle.d.ts +19 -0
  41. package/dist/src/rle.d.ts.map +1 -0
  42. package/dist/src/rle.js +73 -0
  43. package/dist/test/test_crunchy_impls.d.ts +2 -0
  44. package/dist/test/test_crunchy_impls.d.ts.map +1 -0
  45. package/dist/test/test_crunchy_impls.js +150 -0
  46. package/dist/test/test_crunchy_with32bit.d.ts +2 -0
  47. package/dist/test/test_crunchy_with32bit.d.ts.map +1 -0
  48. package/dist/test/test_crunchy_with32bit.js +382 -0
  49. package/dist/test/test_ipaddress.d.ts +2 -0
  50. package/dist/test/test_ipaddress.d.ts.map +1 -0
  51. package/dist/test/test_ipaddress.js +182 -0
  52. package/dist/test/test_ipv4.d.ts +2 -0
  53. package/dist/test/test_ipv4.d.ts.map +1 -0
  54. package/dist/test/test_ipv4.js +561 -0
  55. package/dist/test/test_ipv6.d.ts +2 -0
  56. package/dist/test/test_ipv6.d.ts.map +1 -0
  57. package/dist/test/test_ipv6.js +313 -0
  58. package/dist/test/test_ipv6_loopback.d.ts +2 -0
  59. package/dist/test/test_ipv6_loopback.d.ts.map +1 -0
  60. package/dist/test/test_ipv6_loopback.js +40 -0
  61. package/dist/test/test_ipv6_mapped.d.ts +2 -0
  62. package/dist/test/test_ipv6_mapped.d.ts.map +1 -0
  63. package/dist/test/test_ipv6_mapped.js +89 -0
  64. package/dist/test/test_ipv6_unspec.d.ts +2 -0
  65. package/dist/test/test_ipv6_unspec.d.ts.map +1 -0
  66. package/dist/test/test_ipv6_unspec.js +39 -0
  67. package/dist/test/test_prefix128.d.ts +2 -0
  68. package/dist/test/test_prefix128.d.ts.map +1 -0
  69. package/dist/test/test_prefix128.js +35 -0
  70. package/dist/test/test_prefix32.d.ts +2 -0
  71. package/dist/test/test_prefix32.d.ts.map +1 -0
  72. package/dist/test/test_prefix32.js +126 -0
  73. package/dist/test/test_rle.d.ts +2 -0
  74. package/dist/test/test_rle.d.ts.map +1 -0
  75. package/dist/test/test_rle.js +141 -0
  76. package/dist/vitest.config.d.ts +3 -0
  77. package/dist/vitest.config.d.ts.map +1 -0
  78. package/dist/vitest.config.js +11 -0
  79. package/package.json +41 -37
  80. package/src/crunchy.ts +731 -0
  81. package/src/index.ts +23 -0
  82. package/src/ip_bits.ts +148 -0
  83. package/src/ip_version.ts +6 -0
  84. package/src/ipaddress.ts +1347 -0
  85. package/src/ipv4.ts +203 -0
  86. package/src/ipv6.ts +202 -0
  87. package/src/ipv6_loopback.ts +55 -0
  88. package/src/ipv6_mapped.ts +163 -0
  89. package/src/ipv6_unspec.ts +59 -0
  90. package/src/prefix.ts +170 -0
  91. package/src/prefix128.ts +42 -0
  92. package/src/prefix32.ts +32 -0
  93. package/src/rle.ts +85 -0
  94. package/test/test_crunchy_impls.ts +179 -0
  95. package/test/test_crunchy_with32bit.ts +510 -0
  96. package/test/test_ipaddress.ts +208 -0
  97. package/test/test_ipv4.ts +596 -0
  98. package/test/test_ipv6.ts +325 -0
  99. package/test/test_ipv6_loopback.ts +52 -0
  100. package/test/test_ipv6_mapped.ts +101 -0
  101. package/test/test_ipv6_unspec.ts +51 -0
  102. package/test/test_prefix128.ts +39 -0
  103. package/test/test_prefix32.ts +130 -0
  104. package/test/test_rle.ts +144 -0
  105. package/LICENSE +0 -20
  106. package/README.md +0 -960
  107. package/crunchy.d.ts +0 -55
  108. package/index.d.ts +0 -12
  109. package/ipaddress.js +0 -2869
  110. package/ipaddress.js.map +0 -1
  111. package/ipv4.d.ts +0 -14
  112. package/ipv6.d.ts +0 -12
  113. package/ipv6_loopback.d.ts +0 -5
  114. package/ipv6_mapped.d.ts +0 -5
  115. package/ipv6_unspec.d.ts +0 -5
  116. package/prefix128.d.ts +0 -6
  117. package/prefix32.d.ts +0 -6
  118. package/rle.d.ts +0 -14
@@ -0,0 +1,313 @@
1
+ import IPAddress from "../src/ipaddress.js";
2
+ // import Prefix128 from '../src/prefix128';
3
+ import Ipv6 from "../src/ipv6.js";
4
+ import Crunchy from "../src/crunchy.js";
5
+ class IPv6Test {
6
+ compress_addr = [];
7
+ valid_ipv6 = [];
8
+ invalid_ipv6 = [":1:2:3:4:5:6:7", ":1:2:3:4:5:6:7", "2002:516:2:200", "dd"];
9
+ networks = [];
10
+ ip = IPAddress.parse("2001:db8::8:800:200c:417a/64");
11
+ network = IPAddress.parse("2001:db8:8:800::/64");
12
+ arr = [8193, 3512, 0, 0, 8, 2048, 8204, 16762];
13
+ hex = "20010db80000000000080800200c417a";
14
+ }
15
+ describe("ipv6", () => {
16
+ function assertArrayEqual(a, b) {
17
+ assert.equal(a.length, b.length, "length missmatch");
18
+ for (let i = 0; i < a.length; ++i) {
19
+ assert.equal(a[i], b[i]);
20
+ }
21
+ }
22
+ function setup() {
23
+ const ip6t = new IPv6Test();
24
+ ip6t.compress_addr.push(["2001:db8:0000:0000:0008:0800:200c:417a", "2001:db8::8:800:200c:417a"]);
25
+ ip6t.compress_addr.push(["2001:db8:0:0:8:800:200c:417a", "2001:db8.8:800:200c:417a"]);
26
+ ip6t.compress_addr.push(["ff01:0:0:0:0:0:0:101", "ff01::101"]);
27
+ ip6t.compress_addr.push(["0:0:0:0:0:0:0:1", ".1"]);
28
+ ip6t.compress_addr.push(["0:0:0:0:0:0:0:0", "."]);
29
+ ip6t.valid_ipv6.push(["FEDC:BA98:7654:3210:FEDC:BA98:7654:3210", Crunchy.parse("338770000845734292534325025077361652240")]);
30
+ ip6t.valid_ipv6.push(["1080:0000:0000:0000:0008:0800:200C:417A", Crunchy.parse("21932261930451111902915077091070067066")]);
31
+ ip6t.valid_ipv6.push(["1080:0:0:0:8:800:200C:417A", Crunchy.parse("21932261930451111902915077091070067066")]);
32
+ ip6t.valid_ipv6.push(["1080:0::8:800:200C:417A", Crunchy.parse("21932261930451111902915077091070067066")]);
33
+ ip6t.valid_ipv6.push(["1080::8:800:200C:417A", Crunchy.parse("21932261930451111902915077091070067066")]);
34
+ ip6t.valid_ipv6.push(["FF01:0:0:0:0:0:0:43", Crunchy.parse("338958331222012082418099330867817087043")]);
35
+ ip6t.valid_ipv6.push(["FF01:0::0:0:43", Crunchy.parse("338958331222012082418099330867817087043")]);
36
+ ip6t.valid_ipv6.push(["FF01::43", Crunchy.parse("338958331222012082418099330867817087043")]);
37
+ ip6t.valid_ipv6.push(["0:0:0:0:0:0:0:1", Crunchy.parse("1")]);
38
+ ip6t.valid_ipv6.push(["0:0:0::0:0:1", Crunchy.parse("1")]);
39
+ ip6t.valid_ipv6.push(["::1", Crunchy.parse("1")]);
40
+ ip6t.valid_ipv6.push(["0:0:0:0:0:0:0:0", Crunchy.parse("0")]);
41
+ ip6t.valid_ipv6.push(["0:0:0::0:0:0", Crunchy.parse("0")]);
42
+ ip6t.valid_ipv6.push(["::", Crunchy.parse("0")]);
43
+ ip6t.valid_ipv6.push(["::/0", Crunchy.parse("0")]);
44
+ ip6t.valid_ipv6.push(["1080:0:0:0:8:800:200C:417A", Crunchy.parse("21932261930451111902915077091070067066")]);
45
+ ip6t.valid_ipv6.push(["1080::8:800:200C:417A", Crunchy.parse("21932261930451111902915077091070067066")]);
46
+ ip6t.networks.push(["2001:db8:1:1:1:1:1:1/32", "2001:db8::/32"]);
47
+ ip6t.networks.push(["2001:db8:1:1:1:1:1::/32", "2001:db8::/32"]);
48
+ ip6t.networks.push(["2001:db8::1/64", "2001:db8::/64"]);
49
+ return ip6t;
50
+ }
51
+ it("test_attribute_address", () => {
52
+ const addr = "2001:0db8:0000:0000:0008:0800:200c:417a";
53
+ assert.equal(addr, setup().ip.to_s_uncompressed());
54
+ });
55
+ it("test_initialize", () => {
56
+ assert.equal(false, setup().ip.is_ipv4());
57
+ for (const ip of setup().valid_ipv6) {
58
+ assert.isOk(IPAddress.parse(ip[0]));
59
+ }
60
+ for (const ip of setup().invalid_ipv6) {
61
+ assert.isNotOk(IPAddress.parse(ip));
62
+ }
63
+ assert.equal(64, setup().ip.prefix.num);
64
+ assert.isOk(IPAddress.parse("::10.1.1.1"));
65
+ });
66
+ it("test_attribute_groups", () => {
67
+ assertArrayEqual(setup().arr, setup().ip.parts());
68
+ });
69
+ it("test_method_hexs", () => {
70
+ assertArrayEqual(setup().ip.parts_hex_str(), ["2001", "0db8", "0000", "0000", "0008", "0800", "200c", "417a"]);
71
+ });
72
+ it("test_method_to_i", () => {
73
+ for (const i of setup().valid_ipv6) {
74
+ const ip = i[0];
75
+ const num = i[1];
76
+ assert.isOk(num.eq(IPAddress.parse(ip).host_address));
77
+ }
78
+ });
79
+ it("test_method_set_prefix", () => {
80
+ const ip = IPAddress.parse("2001:db8::8:800:200c:417a");
81
+ assert.equal(128, ip.prefix.num);
82
+ assert.equal("2001:db8::8:800:200c:417a/128", ip.to_string());
83
+ const nip = ip.change_prefix(64);
84
+ assert.equal(64, nip.prefix.num);
85
+ assert.equal("2001:db8::8:800:200c:417a/64", nip.to_string());
86
+ });
87
+ it("test_method_mapped", () => {
88
+ assert.equal(false, setup().ip.is_mapped());
89
+ const ip6 = IPAddress.parse("::ffff:1234:5678");
90
+ assert.equal(true, ip6.is_mapped());
91
+ });
92
+ it("test_method_group", () => {
93
+ const s = setup();
94
+ assertArrayEqual(s.ip.parts(), s.arr);
95
+ });
96
+ it("test_method_ipv4()", () => {
97
+ assert.equal(false, setup().ip.is_ipv4());
98
+ });
99
+ it("test_method_ipv6", () => {
100
+ assert.equal(true, setup().ip.is_ipv6());
101
+ });
102
+ it("test_method_network_known", () => {
103
+ assert.equal(true, setup().network.is_network());
104
+ assert.equal(false, setup().ip.is_network());
105
+ });
106
+ it("test_method_network_u128", () => {
107
+ assert.isOk(Ipv6.from_int(Crunchy.parse("42540766411282592856903984951653826560"), 64).eq(setup().ip.network()));
108
+ });
109
+ it("test_method_broadcast_u128", () => {
110
+ assert.isOk(Ipv6.from_int(Crunchy.parse("42540766411282592875350729025363378175"), 64).eq(setup().ip.broadcast()));
111
+ });
112
+ it("test_method_size", () => {
113
+ let ip = IPAddress.parse("2001:db8::8:800:200c:417a/64");
114
+ assert.isOk(Crunchy.one().shl(64).eq(ip.size()));
115
+ ip = IPAddress.parse("2001:db8::8:800:200c:417a/32");
116
+ assert.isOk(Crunchy.one().shl(96).eq(ip.size()));
117
+ ip = IPAddress.parse("2001:db8::8:800:200c:417a/120");
118
+ assert.isOk(Crunchy.one().shl(8).eq(ip.size()));
119
+ ip = IPAddress.parse("2001:db8::8:800:200c:417a/124");
120
+ assert.isOk(Crunchy.one().shl(4).eq(ip.size()));
121
+ });
122
+ it("test_method_includes", () => {
123
+ const ip = setup().ip;
124
+ assert.equal(true, ip.includes(ip));
125
+ // test prefix on same address
126
+ let included = IPAddress.parse("2001:db8::8:800:200c:417a/128");
127
+ let not_included = IPAddress.parse("2001:db8::8:800:200c:417a/46");
128
+ assert.equal(true, ip.includes(included));
129
+ assert.equal(false, ip.includes(not_included));
130
+ // test address on same prefix
131
+ included = IPAddress.parse("2001:db8::8:800:200c:0/64");
132
+ not_included = IPAddress.parse("2001:db8:1::8:800:200c:417a/64");
133
+ assert.equal(true, ip.includes(included));
134
+ assert.equal(false, ip.includes(not_included));
135
+ // general test
136
+ included = IPAddress.parse("2001:db8::8:800:200c:1/128");
137
+ not_included = IPAddress.parse("2001:db8:1::8:800:200c:417a/76");
138
+ assert.equal(true, ip.includes(included));
139
+ assert.equal(false, ip.includes(not_included));
140
+ });
141
+ it("test_method_to_hex", () => {
142
+ assert(setup().hex, setup().ip.to_hex());
143
+ });
144
+ it("test_method_to_s", () => {
145
+ assert.equal("2001:db8::8:800:200c:417a", setup().ip.to_s());
146
+ });
147
+ it("test_method_to_string", () => {
148
+ assert.equal("2001:db8::8:800:200c:417a/64", setup().ip.to_string());
149
+ });
150
+ it("test_method_to_string_uncompressed", () => {
151
+ const str = "2001:0db8:0000:0000:0008:0800:200c:417a/64";
152
+ assert.equal(str, setup().ip.to_string_uncompressed());
153
+ });
154
+ it("test_method_reverse", () => {
155
+ const str = "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.arpa";
156
+ assert.equal(str, IPAddress.parse("3ffe:505:2::f").dns_reverse());
157
+ });
158
+ it("test_method_dns_rev_domains", () => {
159
+ assertArrayEqual(IPAddress.parse("f000:f100::/3").dns_rev_domains(), ["e.ip6.arpa", "f.ip6.arpa"]);
160
+ assertArrayEqual(IPAddress.parse("fea3:f120::/15").dns_rev_domains(), ["2.a.e.f.ip6.arpa", "3.a.e.f.ip6.arpa"]);
161
+ assertArrayEqual(IPAddress.parse("3a03:2f80:f::/48").dns_rev_domains(), ["f.0.0.0.0.8.f.2.3.0.a.3.ip6.arpa"]);
162
+ assertArrayEqual(IPAddress.parse("f000:f100::1234/125").dns_rev_domains(), [
163
+ "0.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
164
+ "1.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
165
+ "2.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
166
+ "3.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
167
+ "4.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
168
+ "5.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
169
+ "6.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
170
+ "7.3.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.1.f.0.0.0.f.ip6.arpa",
171
+ ]);
172
+ });
173
+ it("test_method_compressed", () => {
174
+ assert.equal("1:1:1::1", IPAddress.parse("1:1:1:0:0:0:0:1").to_s());
175
+ assert.equal("1:0:1::1", IPAddress.parse("1:0:1:0:0:0:0:1").to_s());
176
+ assert.equal("1::1:1:1:2:3:1", IPAddress.parse("1:0:1:1:1:2:3:1").to_s());
177
+ assert.equal("1::1:1:0:2:3:1", IPAddress.parse("1:0:1:1::2:3:1").to_s());
178
+ assert.equal("1:0:0:1::1", IPAddress.parse("1:0:0:1:0:0:0:1").to_s());
179
+ assert.equal("1::1:0:0:1", IPAddress.parse("1:0:0:0:1:0:0:1").to_s());
180
+ assert.equal("1::1", IPAddress.parse("1:0:0:0:0:0:0:1").to_s());
181
+ // assert.equal("1:1.1:2:0:0:1", IPAddress.parse("1:1:0:1:2.1").to_s
182
+ });
183
+ it("test_method_unspecified", () => {
184
+ assert.equal(true, IPAddress.parse("::").is_unspecified());
185
+ assert.equal(false, setup().ip.is_unspecified());
186
+ });
187
+ it("test_method_loopback", () => {
188
+ assert.equal(true, IPAddress.parse("::1").is_loopback());
189
+ assert.equal(false, setup().ip.is_loopback());
190
+ });
191
+ it("test_method_network", () => {
192
+ for (const i of setup().networks) {
193
+ const addr = i[0];
194
+ const net = i[1];
195
+ const ip = IPAddress.parse(addr);
196
+ assert.equal(net, ip.network().to_string());
197
+ }
198
+ });
199
+ it("test_method_each", () => {
200
+ const ip = IPAddress.parse("2001:db8::4/125");
201
+ const arr = [];
202
+ ip.each((i) => arr.push(i.to_s()));
203
+ assertArrayEqual(arr, [
204
+ "2001:db8::",
205
+ "2001:db8::1",
206
+ "2001:db8::2",
207
+ "2001:db8::3",
208
+ "2001:db8::4",
209
+ "2001:db8::5",
210
+ "2001:db8::6",
211
+ "2001:db8::7",
212
+ ]);
213
+ });
214
+ it("test_method_each_net", function () {
215
+ // this.timeout(30000);
216
+ const test_addrs = [
217
+ "0000:0000:0000:0000:0000:0000:0000:0000",
218
+ "1111:1111:1111:1111:1111:1111:1111:1111",
219
+ "2222:2222:2222:2222:2222:2222:2222:2222",
220
+ "3333:3333:3333:3333:3333:3333:3333:3333",
221
+ "4444:4444:4444:4444:4444:4444:4444:4444",
222
+ "5555:5555:5555:5555:5555:5555:5555:5555",
223
+ "6666:6666:6666:6666:6666:6666:6666:6666",
224
+ "7777:7777:7777:7777:7777:7777:7777:7777",
225
+ "8888:8888:8888:8888:8888:8888:8888:8888",
226
+ "9999:9999:9999:9999:9999:9999:9999:9999",
227
+ "aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa:aaaa",
228
+ "bbbb:bbbb:bbbb:bbbb:bbbb:bbbb:bbbb:bbbb",
229
+ "cccc:cccc:cccc:cccc:cccc:cccc:cccc:cccc",
230
+ "dddd:dddd:dddd:dddd:dddd:dddd:dddd:dddd",
231
+ "eeee:eeee:eeee:eeee:eeee:eeee:eeee:eeee",
232
+ "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
233
+ ];
234
+ for (let prefix = 0; prefix < 128; ++prefix) {
235
+ const nr_networks = 1 << ((128 - prefix) % 4);
236
+ for (const adr of test_addrs) {
237
+ const net_adr = IPAddress.parse(`${adr}/${prefix}`);
238
+ const ret = net_adr.dns_networks();
239
+ assert.equal(ret[0].prefix.num % 4, 0);
240
+ assert.equal(ret.length, nr_networks);
241
+ assert.equal(net_adr.network().to_s(), ret[0].network().to_s());
242
+ assert.equal(net_adr.broadcast().to_s(), ret[ret.length - 1].broadcast().to_s());
243
+ // puts "//{adr}///{prefix} //{nr_networks} //{ret}"
244
+ }
245
+ }
246
+ const ret0 = [];
247
+ for (const i of IPAddress.parse("fd01:db8::4/3").dns_networks()) {
248
+ ret0.push(i.to_string());
249
+ }
250
+ assertArrayEqual(ret0, ["e000::/4", "f000::/4"]);
251
+ const ret1 = [];
252
+ for (const i of IPAddress.parse("3a03:2f80:f::/48").dns_networks()) {
253
+ ret1.push(i.to_string());
254
+ }
255
+ assertArrayEqual(ret1, ["3a03:2f80:f::/48"]);
256
+ }, 10000);
257
+ it("test_method_compare", () => {
258
+ const ip1 = IPAddress.parse("2001:db8:1::1/64");
259
+ const ip2 = IPAddress.parse("2001:db8:2::1/64");
260
+ const ip3 = IPAddress.parse("2001:db8:1::2/64");
261
+ const ip4 = IPAddress.parse("2001:db8:1::1/65");
262
+ // ip2 should be greater than ip1
263
+ assert.equal(true, ip2.gt(ip1));
264
+ assert.equal(false, ip1.gt(ip2));
265
+ assert.equal(false, ip2.lt(ip1));
266
+ // ip3 should be less than ip2
267
+ assert.equal(true, ip2.gt(ip3));
268
+ assert.equal(false, ip2.lt(ip3));
269
+ // ip1 should be less than ip3
270
+ assert.equal(true, ip1.lt(ip3));
271
+ assert.equal(false, ip1.gt(ip3));
272
+ assert.equal(false, ip3.lt(ip1));
273
+ // ip1 should be equal to itself
274
+ assert.equal(true, ip1.eq(ip1));
275
+ // ip4 should be greater than ip1
276
+ assert.equal(true, ip1.lt(ip4));
277
+ assert.equal(false, ip1.gt(ip4));
278
+ // test sorting
279
+ const r = [ip1, ip2, ip3, ip4].sort((a, b) => a.cmp(b));
280
+ const ret = [];
281
+ for (const i of r) {
282
+ ret.push(i.to_string());
283
+ }
284
+ assertArrayEqual(ret, ["2001:db8:1::1/64", "2001:db8:1::1/65", "2001:db8:1::2/64", "2001:db8:2::1/64"]);
285
+ });
286
+ // it("test_classmethod_expand", () => {
287
+ // let compressed = "2001:db8:0:cd30.";
288
+ // let expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000";
289
+ // assert.equal(expanded, @klass.expand(compressed));
290
+ // assert.equal(expanded, @klass.expand("2001:0db8:0.cd3"));
291
+ // assert.equal(expanded, @klass.expand("2001:0db8.cd30"));
292
+ // assert.equal(expanded, @klass.expand("2001:0db8.cd3"));
293
+ // }
294
+ it("test_classmethod_compress", () => {
295
+ const compressed = "2001:db8:0:cd30::";
296
+ const expanded = "2001:0db8:0000:cd30:0000:0000:0000:0000";
297
+ assert.equal(compressed, IPAddress.parse(expanded).to_s());
298
+ assert.equal("2001:db8::cd3", IPAddress.parse("2001:0db8:0::cd3").to_s());
299
+ assert.equal("2001:db8::cd30", IPAddress.parse("2001:0db8::cd30").to_s());
300
+ assert.equal("2001:db8::cd3", IPAddress.parse("2001:0db8::cd3").to_s());
301
+ });
302
+ it("test_classhmethod_parse_u128", () => {
303
+ for (const i of setup().valid_ipv6) {
304
+ const ip = i[0];
305
+ const num = i[1];
306
+ // console.log(">>>>>>>>", i);
307
+ assert.equal(IPAddress.parse(ip).to_s(), Ipv6.from_int(num, 128).to_s());
308
+ }
309
+ });
310
+ it("test_classmethod_parse_hex", () => {
311
+ assert.equal(setup().ip.to_string(), Ipv6.from_str(setup().hex, 16, 64).to_string());
312
+ });
313
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test_ipv6_loopback.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_ipv6_loopback.d.ts","sourceRoot":"","sources":["../../test/test_ipv6_loopback.ts"],"names":[],"mappings":""}
@@ -0,0 +1,40 @@
1
+ // import Prefix128 from '../src/prefix128';
2
+ import Ipv6Loopback from "../src/ipv6_loopback.js";
3
+ import Crunchy from "../src/crunchy.js";
4
+ class IPv6LoopbackTest {
5
+ ip;
6
+ s;
7
+ n;
8
+ string;
9
+ one;
10
+ constructor(obj) {
11
+ this.ip = obj.ip;
12
+ this.s = obj.s;
13
+ this.n = obj.n;
14
+ this.string = obj.string;
15
+ this.one = obj.one;
16
+ }
17
+ }
18
+ describe("ipv6_loopback", () => {
19
+ function setup() {
20
+ return new IPv6LoopbackTest({
21
+ ip: Ipv6Loopback.create(),
22
+ s: "::1",
23
+ n: "::1/128",
24
+ string: "0000:0000:0000:0000:0000:0000:0000:0001/128",
25
+ one: Crunchy.one(),
26
+ });
27
+ }
28
+ it("test_attributes", () => {
29
+ const s = setup();
30
+ assert.equal(128, s.ip.prefix.num);
31
+ assert.equal(true, s.ip.is_loopback());
32
+ assert.equal(s.s, s.ip.to_s());
33
+ assert.equal(s.n, s.ip.to_string());
34
+ assert.equal(s.string, s.ip.to_string_uncompressed());
35
+ assert.equal(s.one.toString(), s.ip.host_address.toString());
36
+ });
37
+ it("test_method_ipv6", () => {
38
+ assert.equal(true, setup().ip.is_ipv6());
39
+ });
40
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test_ipv6_mapped.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_ipv6_mapped.d.ts","sourceRoot":"","sources":["../../test/test_ipv6_mapped.ts"],"names":[],"mappings":""}
@@ -0,0 +1,89 @@
1
+ import IPAddress from "../src/ipaddress.js";
2
+ // import Prefix128 from '../src/prefix128';
3
+ // import Ipv6Unspec from '../src/ipv6_unspec';
4
+ import Ipv6Mapped from "../src/ipv6_mapped.js";
5
+ import Crunchy from "../src/crunchy.js";
6
+ class IPv6MappedTest {
7
+ ip;
8
+ s;
9
+ sstr;
10
+ string;
11
+ u128;
12
+ address;
13
+ valid_mapped = [];
14
+ valid_mapped_ipv6 = [];
15
+ valid_mapped_ipv6_conversion = [];
16
+ constructor(obj) {
17
+ this.ip = obj.ip;
18
+ this.s = obj.s;
19
+ this.sstr = obj.sstr;
20
+ this.string = obj.string;
21
+ this.u128 = obj.u128;
22
+ this.address = obj.address;
23
+ }
24
+ }
25
+ describe("ipv6_mapped", () => {
26
+ function setup() {
27
+ const ipv6 = new IPv6MappedTest({
28
+ ip: Ipv6Mapped.create("::172.16.10.1"),
29
+ s: "::ffff:172.16.10.1",
30
+ sstr: "::ffff:172.16.10.1/32",
31
+ string: "0000:0000:0000:0000:0000:ffff:ac10:0a01/128",
32
+ u128: Crunchy.parse("281473568475649"),
33
+ address: "::ffff:ac10:a01/128",
34
+ });
35
+ ipv6.valid_mapped.push(["::13.1.68.3", Crunchy.parse("281470899930115")]);
36
+ ipv6.valid_mapped.push(["0:0:0:0:0:ffff:129.144.52.38", Crunchy.parse("281472855454758")]);
37
+ ipv6.valid_mapped.push(["::ffff:129.144.52.38", Crunchy.parse("281472855454758")]);
38
+ ipv6.valid_mapped_ipv6.push(["::ffff:13.1.68.3", Crunchy.parse("281470899930115")]);
39
+ ipv6.valid_mapped_ipv6.push(["0:0:0:0:0:ffff:8190:3426", Crunchy.parse("281472855454758")]);
40
+ ipv6.valid_mapped_ipv6.push(["::ffff:8190:3426", Crunchy.parse("281472855454758")]);
41
+ ipv6.valid_mapped_ipv6_conversion.push(["::ffff:13.1.68.3", "13.1.68.3"]);
42
+ ipv6.valid_mapped_ipv6_conversion.push(["0:0:0:0:0:ffff:8190:3426", "129.144.52.38"]);
43
+ ipv6.valid_mapped_ipv6_conversion.push(["::ffff:8190:3426", "129.144.52.38"]);
44
+ return ipv6;
45
+ }
46
+ it("test_initialize", () => {
47
+ const s = setup();
48
+ assert.isOk(IPAddress.parse("::172.16.10.1"));
49
+ for (const i of s.valid_mapped) {
50
+ const ip = i[0];
51
+ const u128 = i[1];
52
+ // println("-{}--{}", ip, u128);
53
+ if (!IPAddress.parse(ip)) {
54
+ // console.log(IPAddress.parse(ip));
55
+ }
56
+ assert.isOk(IPAddress.parse(ip));
57
+ assert.equal(u128.toString(), IPAddress.parse(ip).host_address.toString());
58
+ }
59
+ for (const i of s.valid_mapped_ipv6) {
60
+ const ip = i[0];
61
+ const u128 = i[1];
62
+ // println("===={}=={:x}", ip, u128);
63
+ assert.isOk(IPAddress.parse(ip));
64
+ assert.equal(u128.toString(), IPAddress.parse(ip).host_address.toString());
65
+ }
66
+ });
67
+ it("test_mapped_from_ipv6_conversion", () => {
68
+ for (const i of setup().valid_mapped_ipv6_conversion) {
69
+ const ip6 = i[0];
70
+ const ip4 = i[1];
71
+ assert.equal(ip4, IPAddress.parse(ip6).mapped.to_s());
72
+ }
73
+ });
74
+ it("test_attributes", () => {
75
+ const s = setup();
76
+ assert.equal(s.address, s.ip.to_string());
77
+ assert.equal(128, s.ip.prefix.num);
78
+ assert.equal(s.s, s.ip.to_s_mapped());
79
+ assert.equal(s.sstr, s.ip.to_string_mapped());
80
+ assert.equal(s.string, s.ip.to_string_uncompressed());
81
+ assert.equal(s.u128.toString(), s.ip.host_address.toString());
82
+ });
83
+ it("test_method_ipv6", () => {
84
+ assert.isOk(setup().ip.is_ipv6());
85
+ });
86
+ it("test_mapped", () => {
87
+ assert.isOk(setup().ip.is_mapped());
88
+ });
89
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test_ipv6_unspec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_ipv6_unspec.d.ts","sourceRoot":"","sources":["../../test/test_ipv6_unspec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,39 @@
1
+ // import Prefix128 from '../src/prefix128.js';
2
+ import Ipv6Unspec from "../src/ipv6_unspec.js";
3
+ import Crunchy from "../src/crunchy.js";
4
+ class IPv6UnspecifiedTest {
5
+ ip;
6
+ to_s;
7
+ to_string;
8
+ to_string_uncompressed;
9
+ num;
10
+ constructor(obj) {
11
+ this.ip = obj.ip;
12
+ this.to_s = obj.to_s;
13
+ this.to_string = obj.to_string;
14
+ this.to_string_uncompressed = obj.to_string_uncompressed;
15
+ this.num = obj.num;
16
+ }
17
+ }
18
+ describe("ipv6_unspec", () => {
19
+ function setup() {
20
+ return new IPv6UnspecifiedTest({
21
+ ip: Ipv6Unspec.create(),
22
+ to_s: "::",
23
+ to_string: "::/128",
24
+ to_string_uncompressed: "0000:0000:0000:0000:0000:0000:0000:0000/128",
25
+ num: Crunchy.zero(),
26
+ });
27
+ }
28
+ it("test_attributes", () => {
29
+ assert.isOk(setup().ip.host_address.eq(setup().num));
30
+ assert.equal(128, setup().ip.prefix.num);
31
+ assert.equal(true, setup().ip.is_unspecified());
32
+ assert.equal(setup().to_s, setup().ip.to_s());
33
+ assert.equal(setup().to_string, setup().ip.to_string());
34
+ assert.equal(setup().to_string_uncompressed, setup().ip.to_string_uncompressed());
35
+ });
36
+ it("test_method_ipv6", () => {
37
+ assert.equal(true, setup().ip.is_ipv6());
38
+ });
39
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test_prefix128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_prefix128.d.ts","sourceRoot":"","sources":["../../test/test_prefix128.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import Prefix128 from "../src/prefix128.js";
2
+ import Crunchy from "../src/crunchy.js";
3
+ class Prefix128Test {
4
+ u128_hash = [];
5
+ }
6
+ describe("prefix128", () => {
7
+ function setup() {
8
+ const p128t = new Prefix128Test();
9
+ p128t.u128_hash.push([32, Crunchy.parse("340282366841710300949110269838224261120")]);
10
+ p128t.u128_hash.push([64, Crunchy.parse("340282366920938463444927863358058659840")]);
11
+ p128t.u128_hash.push([96, Crunchy.parse("340282366920938463463374607427473244160")]);
12
+ p128t.u128_hash.push([126, Crunchy.parse("340282366920938463463374607431768211452")]);
13
+ return p128t;
14
+ }
15
+ it("test_initialize", () => {
16
+ assert.isNotOk(Prefix128.create(129));
17
+ assert.isOk(Prefix128.create(64));
18
+ });
19
+ it("test_method_bits", () => {
20
+ const prefix = Prefix128.create(64);
21
+ let str = "";
22
+ for (let i = 0; i < 64; ++i) {
23
+ str += "1";
24
+ }
25
+ for (let i = 0; i < 64; ++i) {
26
+ str += "0";
27
+ }
28
+ assert.equal(str, prefix.bits());
29
+ });
30
+ it("test_method_to_u32", () => {
31
+ for (const hash of setup().u128_hash) {
32
+ assert.isOk(hash[1].eq(Prefix128.create(hash[0]).netmask()));
33
+ }
34
+ });
35
+ });
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test_prefix32.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_prefix32.d.ts","sourceRoot":"","sources":["../../test/test_prefix32.ts"],"names":[],"mappings":""}