I noticed that the file src/backend/utils/adt/inet_cidr_ntop.c has no test coverage at all. The only way to reach this appears to be by calling abbrev(cidr). It was easy to add a test case for this into the existing, otherwise pretty complete, cidr tests.
From 4bba4782c81ec6cab3d85e045abc89a85092e2d0 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 8 Feb 2021 15:03:49 +0100
Subject: [PATCH] Add test case for abbrev(cidr)

This will in particular add some good test coverage for
inet_cidr_ntop.c, which was previously completely uncovered.
---
 src/test/regress/expected/inet.out | 22 ++++++++++++++++++++++
 src/test/regress/sql/inet.sql      |  1 +
 2 files changed, 23 insertions(+)

diff --git a/src/test/regress/expected/inet.out 
b/src/test/regress/expected/inet.out
index 298af7e913..d5bf9e2aaa 100644
--- a/src/test/regress/expected/inet.out
+++ b/src/test/regress/expected/inet.out
@@ -88,6 +88,28 @@ SELECT i AS inet, host(i), text(i), family(i) FROM INET_TBL;
  ::4.3.2.1/24     | ::4.3.2.1     | ::4.3.2.1/24     |      6
 (17 rows)
 
+SELECT c AS cidr, abbrev(c) FROM INET_TBL;
+        cidr        |       abbrev       
+--------------------+--------------------
+ 192.168.1.0/24     | 192.168.1/24
+ 192.168.1.0/26     | 192.168.1.0/26
+ 192.168.1.0/24     | 192.168.1/24
+ 192.168.1.0/24     | 192.168.1/24
+ 192.168.1.0/24     | 192.168.1/24
+ 192.168.1.0/24     | 192.168.1/24
+ 10.0.0.0/8         | 10/8
+ 10.0.0.0/32        | 10.0.0.0/32
+ 10.1.2.3/32        | 10.1.2.3/32
+ 10.1.2.0/24        | 10.1.2/24
+ 10.1.0.0/16        | 10.1/16
+ 10.0.0.0/8         | 10/8
+ 10.0.0.0/8         | 10/8
+ 10.0.0.0/8         | 10/8
+ 10:23::f1/128      | 10:23::f1/128
+ 10:23::8000/113    | 10:23::8000/113
+ ::ffff:1.2.3.4/128 | ::ffff:1.2.3.4/128
+(17 rows)
+
 SELECT c AS cidr, broadcast(c),
   i AS inet, broadcast(i) FROM INET_TBL;
         cidr        |    broadcast     |       inet       |               
broadcast               
diff --git a/src/test/regress/sql/inet.sql b/src/test/regress/sql/inet.sql
index 23e5b93e69..d2ac85bb7f 100644
--- a/src/test/regress/sql/inet.sql
+++ b/src/test/regress/sql/inet.sql
@@ -34,6 +34,7 @@ CREATE TABLE INET_TBL (c cidr, i inet);
 -- now test some support functions
 
 SELECT i AS inet, host(i), text(i), family(i) FROM INET_TBL;
+SELECT c AS cidr, abbrev(c) FROM INET_TBL;
 SELECT c AS cidr, broadcast(c),
   i AS inet, broadcast(i) FROM INET_TBL;
 SELECT c AS cidr, network(c) AS "network(cidr)",
-- 
2.30.0

Reply via email to