public inbox for [email protected]  
help / color / mirror / Atom feed
From: Christoph Berg <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: int4->bool test coverage
Date: Thu, 21 Dec 2023 11:56:22 +0100
Message-ID: <[email protected]> (raw)

I was surprised to learn that 2 is a valid boolean (thanks Berge):

# select 2::boolean;
 bool
──────
 t

... while '2' is not:

# select '2'::boolean;
ERROR:  22P02: invalid input syntax for type boolean: "2"
LINE 1: select '2'::boolean;
               ^
LOCATION:  boolin, bool.c:151


The first cast is the int4_bool function, but it isn't covered by the
regression tests at all. The attached patch adds tests.

Christoph


Attachments:

  [text/x-diff] 0001-Add-tests-for-int4_bool.patch (1.4K, ../[email protected]/2-0001-Add-tests-for-int4_bool.patch)
  download | inline diff:
From 5752d75122db323b4066dd604d0c7a19077641a6 Mon Sep 17 00:00:00 2001
From: Christoph Berg <[email protected]>
Date: Thu, 21 Dec 2023 11:43:28 +0100
Subject: [PATCH] Add tests for int4_bool

This cast was previously not covered at all by the regression tests.
---
 src/test/regress/expected/boolean.out | 19 +++++++++++++++++++
 src/test/regress/sql/boolean.sql      |  6 ++++++
 2 files changed, 25 insertions(+)

diff --git a/src/test/regress/expected/boolean.out b/src/test/regress/expected/boolean.out
index ee9c244bf8..ff9440df7e 100644
--- a/src/test/regress/expected/boolean.out
+++ b/src/test/regress/expected/boolean.out
@@ -566,6 +566,25 @@ SELECT isnul OR istrue OR isfalse FROM booltbl4;
  t
 (1 row)
 
+-- Casts
+SELECT 0::boolean;
+ bool 
+------
+ f
+(1 row)
+
+SELECT 1::boolean;
+ bool 
+------
+ t
+(1 row)
+
+SELECT 2::boolean;
+ bool 
+------
+ t
+(1 row)
+
 --
 -- Clean up
 -- Many tables are retained by the regression test, but these do not seem
diff --git a/src/test/regress/sql/boolean.sql b/src/test/regress/sql/boolean.sql
index bc9937d692..cde6cd3576 100644
--- a/src/test/regress/sql/boolean.sql
+++ b/src/test/regress/sql/boolean.sql
@@ -251,6 +251,12 @@ SELECT istrue OR isfalse OR isnul FROM booltbl4;
 SELECT isnul OR istrue OR isfalse FROM booltbl4;
 
 
+-- Casts
+SELECT 0::boolean;
+SELECT 1::boolean;
+SELECT 2::boolean;
+
+
 --
 -- Clean up
 -- Many tables are retained by the regression test, but these do not seem
-- 
2.43.0



view thread (2+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: int4->bool test coverage
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox