% vim: syntax=prolog :- use_module(library(clpz)). :- use_module(library(format)). :- use_module(test). test("ip4", ( make_ip4(127, 0, 0, 1, Addr), Addr =:= 127*2^24 + 1 )). test("ip_format", ( make_ip4(127, 0, 0, 1, Addr), ip_format(ip4(Addr), Str), Str == "127.0.0.1" )). test("ip_format #2", ( make_ip4(192, 168, 0, 0, Addr), Ip = ip4_range(Addr, 24), ip_format(Ip, Str), Str == "192.168.0.0/24" )). test("ip4_parse #1", ( make_ip4(1, 2, 3, 4, Addr), ip4_parse("1.2.3.4", Ip), Ip == ip4(Addr) )). test("ip4_range_parse", ( make_ip4(1, 2, 3, 4, Addr), ip4_range_parse("1.2.3.4/24", Ip), Ip == ip4_range(Addr, 24) )). test("ip6_parse", ( make_ip6(1, 2, 3, 4, 5, 6, 10, 11, Addr), ip6_parse("1:2:3:4:5:6:a:b", Ip), Ip == ip6(Addr) )). test("ip6_parse #2", ( make_ip6(0, 2, 3, 4, 5, 6, 10, 11, Addr), ip6_parse("0:2:3:4:5:6:a:b", Ip), Ip == ip6(Addr) )). test("ip_parse #1", ( make_ip4(127, 0, 0, 1, Addr), ip_parse("127.0.0.1", Ip), Ip == ip4(Addr) )). test("ip_parse #2", ( ip_parse("192.168.10.4/24", R), make_ip4(192, 168, 10, 4, Addr), R == ip4_range(Addr, 24) )). test("ip_parse #3", ( make_ip6(0, 2, 3, 4, 5, 6, 10, 11, Addr), ip_parse("0:2:3:4:5:6:a:b", Ip), Ip == ip6(Addr) )). main :- consult(ip), findall(test(Name, Goal), test(Name, Goal), Tests), test:test_main(Tests).