From e431f3ecb132dc7a6b8820ff5684071558e3508f Mon Sep 17 00:00:00 2001 From: go-jet Date: Fri, 19 Jul 2019 17:19:58 +0200 Subject: [PATCH] Additional unit tests. --- bool_expression_test.go | 10 +++++++ date_expression_test.go | 45 ++++++++++++++++++++++++++++++ float_expression_test.go | 10 +++++++ internal/utils/utils.go | 4 --- internal/utils/utils_test.go | 1 + string_expression_test.go | 10 +++++++ time_expression_test.go | 24 ++++++++++++---- timestamp_expression_test.go | 52 +++++++++++++++++++++++++++++++++++ timestampz_expression_test.go | 52 +++++++++++++++++++++++++++++++++++ timez_expression_test.go | 51 ++++++++++++++++++++++++++++++++++ utils_test.go | 22 +++++++++++++-- 11 files changed, 269 insertions(+), 12 deletions(-) create mode 100644 date_expression_test.go create mode 100644 timestamp_expression_test.go create mode 100644 timestampz_expression_test.go create mode 100644 timez_expression_test.go diff --git a/bool_expression_test.go b/bool_expression_test.go index dd05e94..70ab9f8 100644 --- a/bool_expression_test.go +++ b/bool_expression_test.go @@ -15,6 +15,16 @@ func TestBoolExpressionNOT_EQ(t *testing.T) { assertClauseSerialize(t, table1ColBool.NOT_EQ(Bool(true)), "(table1.col_bool != $1)", true) } +func TestBoolExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColBool.IS_DISTINCT_FROM(table2ColBool), "(table1.col_bool IS DISTINCT FROM table2.col_bool)") + assertClauseSerialize(t, table1ColBool.IS_DISTINCT_FROM(Bool(false)), "(table1.col_bool IS DISTINCT FROM $1)", false) +} + +func TestBoolExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColBool.IS_NOT_DISTINCT_FROM(table2ColBool), "(table1.col_bool IS NOT DISTINCT FROM table2.col_bool)") + assertClauseSerialize(t, table1ColBool.IS_NOT_DISTINCT_FROM(Bool(false)), "(table1.col_bool IS NOT DISTINCT FROM $1)", false) +} + func TestBoolExpressionIS_TRUE(t *testing.T) { assertClauseSerialize(t, table1ColBool.IS_TRUE(), "table1.col_bool IS TRUE") assertClauseSerialize(t, (Int(2).EQ(table1ColInt)).IS_TRUE(), diff --git a/date_expression_test.go b/date_expression_test.go new file mode 100644 index 0000000..2565c67 --- /dev/null +++ b/date_expression_test.go @@ -0,0 +1,45 @@ +package jet + +import "testing" + +var dateVar = Date(2000, 12, 30) + +func TestDateExpressionEQ(t *testing.T) { + assertClauseSerialize(t, table1ColDate.EQ(table2ColDate), "(table1.col_date = table2.col_date)") + assertClauseSerialize(t, table1ColDate.EQ(dateVar), "(table1.col_date = $1::date)", "2000-12-30") +} + +func TestDateExpressionNOT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColDate.NOT_EQ(table2ColDate), "(table1.col_date != table2.col_date)") + assertClauseSerialize(t, table1ColDate.NOT_EQ(dateVar), "(table1.col_date != $1::date)", "2000-12-30") +} + +func TestDateExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColDate.IS_DISTINCT_FROM(table2ColDate), "(table1.col_date IS DISTINCT FROM table2.col_date)") + assertClauseSerialize(t, table1ColDate.IS_DISTINCT_FROM(dateVar), "(table1.col_date IS DISTINCT FROM $1::date)", "2000-12-30") +} + +func TestDateExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColDate.IS_NOT_DISTINCT_FROM(table2ColDate), "(table1.col_date IS NOT DISTINCT FROM table2.col_date)") + assertClauseSerialize(t, table1ColDate.IS_NOT_DISTINCT_FROM(dateVar), "(table1.col_date IS NOT DISTINCT FROM $1::date)", "2000-12-30") +} + +func TestDateExpressionGT(t *testing.T) { + assertClauseSerialize(t, table1ColDate.GT(table2ColDate), "(table1.col_date > table2.col_date)") + assertClauseSerialize(t, table1ColDate.GT(dateVar), "(table1.col_date > $1::date)", "2000-12-30") +} + +func TestDateExpressionGT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColDate.GT_EQ(table2ColDate), "(table1.col_date >= table2.col_date)") + assertClauseSerialize(t, table1ColDate.GT_EQ(dateVar), "(table1.col_date >= $1::date)", "2000-12-30") +} + +func TestDateExpressionLT(t *testing.T) { + assertClauseSerialize(t, table1ColDate.LT(table2ColDate), "(table1.col_date < table2.col_date)") + assertClauseSerialize(t, table1ColDate.LT(dateVar), "(table1.col_date < $1::date)", "2000-12-30") +} + +func TestDateExpressionLT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColDate.LT_EQ(table2ColDate), "(table1.col_date <= table2.col_date)") + assertClauseSerialize(t, table1ColDate.LT_EQ(dateVar), "(table1.col_date <= $1::date)", "2000-12-30") +} diff --git a/float_expression_test.go b/float_expression_test.go index 1b83868..e9103e9 100644 --- a/float_expression_test.go +++ b/float_expression_test.go @@ -14,6 +14,16 @@ func TestFloatExpressionNOT_EQ(t *testing.T) { assertClauseSerialize(t, table1ColFloat.NOT_EQ(Float(2.11)), "(table1.col_float != $1)", float64(2.11)) } +func TestFloatExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColFloat.IS_DISTINCT_FROM(table2ColFloat), "(table1.col_float IS DISTINCT FROM table2.col_float)") + assertClauseSerialize(t, table1ColFloat.IS_DISTINCT_FROM(Float(2.11)), "(table1.col_float IS DISTINCT FROM $1)", float64(2.11)) +} + +func TestFloatExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColFloat.IS_NOT_DISTINCT_FROM(table2ColFloat), "(table1.col_float IS NOT DISTINCT FROM table2.col_float)") + assertClauseSerialize(t, table1ColFloat.IS_NOT_DISTINCT_FROM(Float(2.11)), "(table1.col_float IS NOT DISTINCT FROM $1)", float64(2.11)) +} + func TestFloatExpressionGT(t *testing.T) { assertClauseSerialize(t, table1ColFloat.GT(table2ColFloat), "(table1.col_float > table2.col_float)") assertClauseSerialize(t, table1ColFloat.GT(Float(2.11)), "(table1.col_float > $1)", float64(2.11)) diff --git a/internal/utils/utils.go b/internal/utils/utils.go index eb2e1b7..85aeec2 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -14,10 +14,6 @@ import ( // ToGoIdentifier converts database to Go identifier. func ToGoIdentifier(databaseIdentifier string) string { - if len(databaseIdentifier) == 0 { - return databaseIdentifier - } - return snaker.SnakeToCamel(replaceInvalidChars(databaseIdentifier)) } diff --git a/internal/utils/utils_test.go b/internal/utils/utils_test.go index 7a3a370..7e96925 100644 --- a/internal/utils/utils_test.go +++ b/internal/utils/utils_test.go @@ -6,6 +6,7 @@ import ( ) func TestToGoIdentifier(t *testing.T) { + assert.Equal(t, ToGoIdentifier(""), "") assert.Equal(t, ToGoIdentifier("uuid"), "UUID") assert.Equal(t, ToGoIdentifier("col1"), "Col1") assert.Equal(t, ToGoIdentifier("PG-13"), "Pg13") diff --git a/string_expression_test.go b/string_expression_test.go index 8dd7b18..a1209ce 100644 --- a/string_expression_test.go +++ b/string_expression_test.go @@ -17,6 +17,16 @@ func TestStringNOT_EQ(t *testing.T) { assertClauseSerialize(t, table3StrCol.NOT_EQ(String("JOHN")), "(table3.col2 != $1)", "JOHN") } +func TestStringExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table3StrCol.IS_DISTINCT_FROM(table2ColStr), "(table3.col2 IS DISTINCT FROM table2.col_str)") + assertClauseSerialize(t, table3StrCol.IS_DISTINCT_FROM(String("JOHN")), "(table3.col2 IS DISTINCT FROM $1)", "JOHN") +} + +func TestStringExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table3StrCol.IS_NOT_DISTINCT_FROM(table2ColStr), "(table3.col2 IS NOT DISTINCT FROM table2.col_str)") + assertClauseSerialize(t, table3StrCol.IS_NOT_DISTINCT_FROM(String("JOHN")), "(table3.col2 IS NOT DISTINCT FROM $1)", "JOHN") +} + func TestStringGT(t *testing.T) { exp := table3StrCol.GT(table2ColStr) assertClauseSerialize(t, exp, "(table3.col2 > table2.col_str)") diff --git a/time_expression_test.go b/time_expression_test.go index 1a328a5..44d54ad 100644 --- a/time_expression_test.go +++ b/time_expression_test.go @@ -4,34 +4,46 @@ import ( "testing" ) +var timeVar = Time(10, 20, 0, 0) + func TestTimeExpressionEQ(t *testing.T) { assertClauseSerialize(t, table1ColTime.EQ(table2ColTime), "(table1.col_time = table2.col_time)") - assertClauseSerialize(t, table1ColTime.EQ(Time(10, 20, 0, 0)), "(table1.col_time = $1::time without time zone)", "10:20:00.000") + assertClauseSerialize(t, table1ColTime.EQ(timeVar), "(table1.col_time = $1::time without time zone)", "10:20:00.000") } func TestTimeExpressionNOT_EQ(t *testing.T) { assertClauseSerialize(t, table1ColTime.NOT_EQ(table2ColTime), "(table1.col_time != table2.col_time)") - assertClauseSerialize(t, table1ColTime.NOT_EQ(Time(10, 20, 0, 0)), "(table1.col_time != $1::time without time zone)", "10:20:00.000") + assertClauseSerialize(t, table1ColTime.NOT_EQ(timeVar), "(table1.col_time != $1::time without time zone)", "10:20:00.000") +} + +func TestTimeExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTime.IS_DISTINCT_FROM(table2ColTime), "(table1.col_time IS DISTINCT FROM table2.col_time)") + assertClauseSerialize(t, table1ColTime.IS_DISTINCT_FROM(timeVar), "(table1.col_time IS DISTINCT FROM $1::time without time zone)", "10:20:00.000") +} + +func TestTimeExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTime.IS_NOT_DISTINCT_FROM(table2ColTime), "(table1.col_time IS NOT DISTINCT FROM table2.col_time)") + assertClauseSerialize(t, table1ColTime.IS_NOT_DISTINCT_FROM(timeVar), "(table1.col_time IS NOT DISTINCT FROM $1::time without time zone)", "10:20:00.000") } func TestTimeExpressionLT(t *testing.T) { assertClauseSerialize(t, table1ColTime.LT(table2ColTime), "(table1.col_time < table2.col_time)") - assertClauseSerialize(t, table1ColTime.LT(Time(10, 20, 0, 0)), "(table1.col_time < $1::time without time zone)", "10:20:00.000") + assertClauseSerialize(t, table1ColTime.LT(timeVar), "(table1.col_time < $1::time without time zone)", "10:20:00.000") } func TestTimeExpressionLT_EQ(t *testing.T) { assertClauseSerialize(t, table1ColTime.LT_EQ(table2ColTime), "(table1.col_time <= table2.col_time)") - assertClauseSerialize(t, table1ColTime.LT_EQ(Time(10, 20, 0, 0)), "(table1.col_time <= $1::time without time zone)", "10:20:00.000") + assertClauseSerialize(t, table1ColTime.LT_EQ(timeVar), "(table1.col_time <= $1::time without time zone)", "10:20:00.000") } func TestTimeExpressionGT(t *testing.T) { assertClauseSerialize(t, table1ColTime.GT(table2ColTime), "(table1.col_time > table2.col_time)") - assertClauseSerialize(t, table1ColTime.GT(Time(10, 20, 0, 0)), "(table1.col_time > $1::time without time zone)", "10:20:00.000") + assertClauseSerialize(t, table1ColTime.GT(timeVar), "(table1.col_time > $1::time without time zone)", "10:20:00.000") } func TestTimeExpressionGT_EQ(t *testing.T) { assertClauseSerialize(t, table1ColTime.GT_EQ(table2ColTime), "(table1.col_time >= table2.col_time)") - assertClauseSerialize(t, table1ColTime.GT_EQ(Time(10, 20, 0, 0)), "(table1.col_time >= $1::time without time zone)", "10:20:00.000") + assertClauseSerialize(t, table1ColTime.GT_EQ(timeVar), "(table1.col_time >= $1::time without time zone)", "10:20:00.000") } func TestTimeExp(t *testing.T) { diff --git a/timestamp_expression_test.go b/timestamp_expression_test.go new file mode 100644 index 0000000..1c44091 --- /dev/null +++ b/timestamp_expression_test.go @@ -0,0 +1,52 @@ +package jet + +import "testing" + +var timestamp = Timestamp(2000, 1, 31, 10, 20, 0, 0) + +func TestTimestampExpressionEQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.EQ(table2ColTimestamp), "(table1.col_timestamp = table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.EQ(timestamp), + "(table1.col_timestamp = $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionNOT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.NOT_EQ(table2ColTimestamp), "(table1.col_timestamp != table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.NOT_EQ(timestamp), "(table1.col_timestamp != $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.IS_DISTINCT_FROM(table2ColTimestamp), "(table1.col_timestamp IS DISTINCT FROM table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.IS_DISTINCT_FROM(timestamp), "(table1.col_timestamp IS DISTINCT FROM $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.IS_NOT_DISTINCT_FROM(table2ColTimestamp), "(table1.col_timestamp IS NOT DISTINCT FROM table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.IS_NOT_DISTINCT_FROM(timestamp), "(table1.col_timestamp IS NOT DISTINCT FROM $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionLT(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.LT(table2ColTimestamp), "(table1.col_timestamp < table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.LT(timestamp), "(table1.col_timestamp < $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionLT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.LT_EQ(table2ColTimestamp), "(table1.col_timestamp <= table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.LT_EQ(timestamp), "(table1.col_timestamp <= $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionGT(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.GT(table2ColTimestamp), "(table1.col_timestamp > table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.GT(timestamp), "(table1.col_timestamp > $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExpressionGT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestamp.GT_EQ(table2ColTimestamp), "(table1.col_timestamp >= table2.col_timestamp)") + assertClauseSerialize(t, table1ColTimestamp.GT_EQ(timestamp), "(table1.col_timestamp >= $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} + +func TestTimestampExp(t *testing.T) { + assertClauseSerialize(t, TimestampExp(table1ColFloat), "table1.col_float") + assertClauseSerialize(t, TimestampExp(table1ColFloat).LT(timestamp), + "(table1.col_float < $1::timestamp without time zone)", "2000-01-31 10:20:00.000") +} diff --git a/timestampz_expression_test.go b/timestampz_expression_test.go new file mode 100644 index 0000000..3451b3f --- /dev/null +++ b/timestampz_expression_test.go @@ -0,0 +1,52 @@ +package jet + +import "testing" + +var timestampz = Timestampz(2000, 1, 31, 10, 20, 0, 0, 2) + +func TestTimestampzExpressionEQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.EQ(table2ColTimestampz), "(table1.col_timestampz = table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.EQ(timestampz), + "(table1.col_timestampz = $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionNOT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.NOT_EQ(table2ColTimestampz), "(table1.col_timestampz != table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.NOT_EQ(timestampz), "(table1.col_timestampz != $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.IS_DISTINCT_FROM(table2ColTimestampz), "(table1.col_timestampz IS DISTINCT FROM table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.IS_DISTINCT_FROM(timestampz), "(table1.col_timestampz IS DISTINCT FROM $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.IS_NOT_DISTINCT_FROM(table2ColTimestampz), "(table1.col_timestampz IS NOT DISTINCT FROM table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.IS_NOT_DISTINCT_FROM(timestampz), "(table1.col_timestampz IS NOT DISTINCT FROM $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionLT(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.LT(table2ColTimestampz), "(table1.col_timestampz < table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.LT(timestampz), "(table1.col_timestampz < $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionLT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.LT_EQ(table2ColTimestampz), "(table1.col_timestampz <= table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.LT_EQ(timestampz), "(table1.col_timestampz <= $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionGT(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.GT(table2ColTimestampz), "(table1.col_timestampz > table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.GT(timestampz), "(table1.col_timestampz > $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExpressionGT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimestampz.GT_EQ(table2ColTimestampz), "(table1.col_timestampz >= table2.col_timestampz)") + assertClauseSerialize(t, table1ColTimestampz.GT_EQ(timestampz), "(table1.col_timestampz >= $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} + +func TestTimestampzExp(t *testing.T) { + assertClauseSerialize(t, TimestampzExp(table1ColFloat), "table1.col_float") + assertClauseSerialize(t, TimestampzExp(table1ColFloat).LT(timestampz), + "(table1.col_float < $1::timestamp with time zone)", "2000-01-31 10:20:00.000 +002") +} diff --git a/timez_expression_test.go b/timez_expression_test.go new file mode 100644 index 0000000..1d2c641 --- /dev/null +++ b/timez_expression_test.go @@ -0,0 +1,51 @@ +package jet + +import "testing" + +var timezVar = Timez(10, 20, 0, 0, 4) + +func TestTimezExpressionEQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.EQ(table2ColTimez), "(table1.col_timez = table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.EQ(timezVar), "(table1.col_timez = $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionNOT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.NOT_EQ(table2ColTimez), "(table1.col_timez != table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.NOT_EQ(timezVar), "(table1.col_timez != $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionIS_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.IS_DISTINCT_FROM(table2ColTimez), "(table1.col_timez IS DISTINCT FROM table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.IS_DISTINCT_FROM(timezVar), "(table1.col_timez IS DISTINCT FROM $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionIS_NOT_DISTINCT_FROM(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.IS_NOT_DISTINCT_FROM(table2ColTimez), "(table1.col_timez IS NOT DISTINCT FROM table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.IS_NOT_DISTINCT_FROM(timezVar), "(table1.col_timez IS NOT DISTINCT FROM $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionLT(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.LT(table2ColTimez), "(table1.col_timez < table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.LT(timezVar), "(table1.col_timez < $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionLT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.LT_EQ(table2ColTimez), "(table1.col_timez <= table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.LT_EQ(timezVar), "(table1.col_timez <= $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionGT(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.GT(table2ColTimez), "(table1.col_timez > table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.GT(timezVar), "(table1.col_timez > $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExpressionGT_EQ(t *testing.T) { + assertClauseSerialize(t, table1ColTimez.GT_EQ(table2ColTimez), "(table1.col_timez >= table2.col_timez)") + assertClauseSerialize(t, table1ColTimez.GT_EQ(timezVar), "(table1.col_timez >= $1::time with time zone)", "10:20:00.000 +04") +} + +func TestTimezExp(t *testing.T) { + assertClauseSerialize(t, TimezExp(table1ColFloat), "table1.col_float") + assertClauseSerialize(t, TimezExp(table1ColFloat).LT(Timez(1, 1, 1, 1, 4)), + "(table1.col_float < $1::time with time zone)", string("01:01:01.001 +04")) +} diff --git a/utils_test.go b/utils_test.go index 8429349..2f0ea75 100644 --- a/utils_test.go +++ b/utils_test.go @@ -10,7 +10,11 @@ var table1ColInt = IntegerColumn("col_int") var table1ColFloat = FloatColumn("col_float") var table1Col3 = IntegerColumn("col3") var table1ColTime = TimeColumn("col_time") +var table1ColTimez = TimezColumn("col_timez") +var table1ColTimestamp = TimestampColumn("col_timestamp") +var table1ColTimestampz = TimestampzColumn("col_timestampz") var table1ColBool = BoolColumn("col_bool") +var table1ColDate = DateColumn("col_date") var table1 = NewTable( "db", @@ -20,7 +24,12 @@ var table1 = NewTable( table1ColFloat, table1Col3, table1ColTime, - table1ColBool) + table1ColTimez, + table1ColBool, + table1ColDate, + table1ColTimestamp, + table1ColTimestampz, +) var table2Col3 = IntegerColumn("col3") var table2Col4 = IntegerColumn("col4") @@ -29,6 +38,10 @@ var table2ColFloat = FloatColumn("col_float") var table2ColStr = StringColumn("col_str") var table2ColBool = BoolColumn("col_bool") var table2ColTime = TimeColumn("col_time") +var table2ColTimez = TimezColumn("col_timez") +var table2ColTimestamp = TimestampColumn("col_timestamp") +var table2ColTimestampz = TimestampzColumn("col_timestampz") +var table2ColDate = DateColumn("col_date") var table2 = NewTable( "db", @@ -39,7 +52,12 @@ var table2 = NewTable( table2ColFloat, table2ColStr, table2ColBool, - table2ColTime) + table2ColTime, + table2ColTimez, + table2ColDate, + table2ColTimestamp, + table2ColTimestampz, +) var table3Col1 = IntegerColumn("col1") var table3ColInt = IntegerColumn("col_int")