From 0d1ba2538b0b035cde654ff3b4c0d3be5ac74a17 Mon Sep 17 00:00:00 2001 From: Guido Fioravantti Date: Thu, 22 Oct 2015 16:18:46 +0200 Subject: [PATCH] Adds test for new CDB_Helper 173 --- test/CDB_HelperTest.sql | 64 ++++++++++++++++++++++ test/CDB_HelperTest_expected | 102 +++++++++++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 test/CDB_HelperTest.sql create mode 100644 test/CDB_HelperTest_expected diff --git a/test/CDB_HelperTest.sql b/test/CDB_HelperTest.sql new file mode 100644 index 0000000..10dfb7e --- /dev/null +++ b/test/CDB_HelperTest.sql @@ -0,0 +1,64 @@ +-- Test unique identifier creation with normal length normal relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'relname', NULL); + +-- Test unique identifier creation with prefix with normal length normal relname +SELECT * FROM cartodb.CDB_Unique_Identifier('prefix_', 'relname', NULL); + +-- Test unique identifier creation with suffix with normal length normal relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'relname', '_suffix'); + +-- Test unique identifier creation with long length normal relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL); + +-- Test unique identifier creation with prefix with long length normal relname +SELECT * FROM cartodb.CDB_Unique_Identifier('prefix_', 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL); + +-- Test new identifier is found when name is taken from previous case +CREATE TABLE prefix_largolargolargolargolargolargolargolargolargolargolar (name text); +SELECT * FROM cartodb.CDB_Unique_Identifier('prefix_', 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL); +DROP TABLE prefix_largolargolargolargolargolargolargolargolargolargolar; + +-- Test unique identifier creation with suffix with long length normal relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', '_suffix'); + +-- Test new identifier is found when name is taken from previous case +CREATE TABLE largolargolargolargolargolargolargolargolargolargolar_suffix (name text); +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', '_suffix'); +DROP TABLE largolargolargolargolargolargolargolargolargolargolar_suffix; + +-- Test unique identifier creation with normal length UTF8 relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'piraña', NULL); + +-- Test unique identifier creation with prefix with normal length UTF8 relname +SELECT * FROM cartodb.CDB_Unique_Identifier('prefix_', 'piraña', NULL); + +-- Test unique identifier creation with suffix with normal length UTF8 relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'piraña', '_suffix'); + +-- Test unique identifier creation with long length UTF8 relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL); + +-- Test unique identifier creation with prefix with long length UTF8 relname +SELECT * FROM cartodb.CDB_Unique_Identifier('prefix_', 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL); + +-- Test new identifier is found when name is taken from previous case +CREATE TABLE prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi (name text); +SELECT * FROM cartodb.CDB_Unique_Identifier('prefix_', 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL); +DROP TABLE prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi; + +-- Test unique identifier creation with suffix with long length UTF8 relname +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', '_suffix'); + +-- Test new identifier is found when name is taken from previous case +CREATE TABLE piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix (name text); +SELECT * FROM cartodb.CDB_Unique_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', '_suffix'); +DROP TABLE piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix; + +-- Test CDB_Trim_Octets simple case +SELECT * FROM cartodb.CDB_Octet_Trim('piraña', 1); + +-- Test CDB_Octet_Trim UTF8 case +SELECT * FROM cartodb.CDB_Octet_Trim('piraña', 2); + +-- Test CDB_Octet_Trim UTF8 case +SELECT * FROM cartodb.CDB_Octet_Trim('piraña', 3); diff --git a/test/CDB_HelperTest_expected b/test/CDB_HelperTest_expected new file mode 100644 index 0000000..885a831 --- /dev/null +++ b/test/CDB_HelperTest_expected @@ -0,0 +1,102 @@ + cdb_unique_identifier +----------------------- + relname +(1 row) + + cdb_unique_identifier +----------------------- + prefix_relname +(1 row) + + cdb_unique_identifier +----------------------- + relname_suffix +(1 row) + + cdb_unique_identifier +-------------------------------------------------------------- + largolargolargolargolargolargolargolargolargolargolargolargo +(1 row) + + cdb_unique_identifier +-------------------------------------------------------------- + prefix_largolargolargolargolargolargolargolargolargolargolar +(1 row) + +CREATE TABLE + cdb_unique_identifier +---------------------------------------------------------------- + prefix_largolargolargolargolargolargolargolargolargolargolar_0 +(1 row) + +DROP TABLE + cdb_unique_identifier +-------------------------------------------------------------- + largolargolargolargolargolargolargolargolargolargolar_suffix +(1 row) + +CREATE TABLE + cdb_unique_identifier +---------------------------------------------------------------- + largolargolargolargolargolargolargolargolargolargolar_suffix_0 +(1 row) + +DROP TABLE + cdb_unique_identifier +----------------------- + piraña +(1 row) + + cdb_unique_identifier +----------------------- + prefix_piraña +(1 row) + + cdb_unique_identifier +----------------------- + piraña_suffix +(1 row) + + cdb_unique_identifier +-------------------------------------------------- + piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácid +(1 row) + + cdb_unique_identifier +--------------------------------------------------- + prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi +(1 row) + +CREATE TABLE + cdb_unique_identifier +----------------------------------------------------- + prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_0 +(1 row) + +DROP TABLE + cdb_unique_identifier +--------------------------------------------------- + piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix +(1 row) + +CREATE TABLE + cdb_unique_identifier +----------------------------------------------------- + piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix_0 +(1 row) + +DROP TABLE + cdb_octet_trim +---------------- + pirañ +(1 row) + + cdb_octet_trim +---------------- + pira +(1 row) + + cdb_octet_trim +---------------- + pira +(1 row)