From 497f92f602f9e5136d1e352e6080a734e67c2d2d Mon Sep 17 00:00:00 2001 From: Siddhant Date: Tue, 20 Oct 2020 19:53:58 +0700 Subject: [PATCH] Added test cases for kebab-case enums --- tests/postgres/derives.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/postgres/derives.rs b/tests/postgres/derives.rs index bd45d8433..254486c25 100644 --- a/tests/postgres/derives.rs +++ b/tests/postgres/derives.rs @@ -66,6 +66,14 @@ enum ColorScreamingSnake { BlueBlack, } +#[derive(PartialEq, Debug, sqlx::Type)] +#[sqlx(rename = "color-kebab-case")] +#[sqlx(rename_all = "kebab-case")] +enum ColorKebabCase { + RedGreen, + BlueBlack, +} + // "Strong" enum can map to a custom type #[derive(PartialEq, Debug, sqlx::Type)] #[sqlx(rename = "mood")] @@ -133,11 +141,13 @@ DROP TYPE IF EXISTS color_lower CASCADE; DROP TYPE IF EXISTS color_snake CASCADE; DROP TYPE IF EXISTS color_upper CASCADE; DROP TYPE IF EXISTS color_screaming_snake CASCADE; +DROP TYPE IF EXISTS color-kebab-case CASCADE; CREATE TYPE color_lower AS ENUM ( 'red', 'green', 'blue' ); CREATE TYPE color_snake AS ENUM ( 'red_green', 'blue_black' ); CREATE TYPE color_upper AS ENUM ( 'RED', 'GREEN', 'BLUE' ); CREATE TYPE color_screaming_snake AS ENUM ( 'RED_GREEN', 'BLUE_BLACK' ); +CREATE TYPE color-kebab-case AS ENUM ( 'red-green', 'blue-black' ); CREATE TABLE people ( id serial PRIMARY KEY, @@ -264,6 +274,18 @@ SELECT id, mood FROM people WHERE id = $1 assert!(rec.0); assert_eq!(rec.1, ColorScreamingSnake::RedGreen); + let rec: (bool, ColorKebabCase) = sqlx::query_as( + " + SELECT $1 = 'red-green'::color-kebab-case, $1 + ", + ) + .bind(&ColorKebabCase::RedGreen) + .fetch_one(&mut conn) + .await?; + + assert!(rec.0); + assert_eq!(rec.1, ColorKebabCase::RedGreen); + Ok(()) }