Skip to content

Commit

Permalink
Add variadic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
theory committed Apr 12, 2024
1 parent 8c950c6 commit 78eec5b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/expected/is_valid.out
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ SELECT jsonschema_is_valid(:'user_schema_id', :'addr_schema'::jsonb, :'user_sche
t
(1 row)

-- Variadic array
SELECT jsonschema_is_valid(:'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::json[]);
jsonschema_is_valid
---------------------
t
(1 row)

SELECT jsonschema_is_valid(:'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::jsonb[]);
jsonschema_is_valid
---------------------
t
(1 row)

-- Invalid
SELECT jsonschema_is_valid('foo', :'addr_schema'::json);
INFO: error loading file:///Users/david/.pgenv/pgsql-16.2/data/foo: unsupported scheme in file:///Users/david/.pgenv/pgsql-16.2/data/foo
Expand Down
25 changes: 25 additions & 0 deletions test/expected/validates.out
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,31 @@ SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', :'addr_schema'::j
t
(1 row)

-- Variadic
SELECT jsonschema_validates(:'user'::json, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::json[] );
jsonschema_validates
----------------------
t
(1 row)

SELECT jsonschema_validates(:'user'::json, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::jsonb[] );
jsonschema_validates
----------------------
t
(1 row)

SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::jsonb[] );
jsonschema_validates
----------------------
t
(1 row)

SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::json[] );
jsonschema_validates
----------------------
t
(1 row)

-- Invalid User
\set invalid_user '{"username": "hello"}'
SELECT jsonschema_validates(:'invalid_user'::json, :'user_schema_id', :'addr_schema'::json, :'user_schema'::json );
Expand Down
4 changes: 4 additions & 0 deletions test/sql/is_valid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ SELECT jsonschema_is_valid(:'addr_schema_id', :'addr_schema'::jsonb);
SELECT jsonschema_is_valid(:'user_schema_id', :'addr_schema'::json, :'user_schema'::json);
SELECT jsonschema_is_valid(:'user_schema_id', :'addr_schema'::jsonb, :'user_schema'::jsonb);

-- Variadic array
SELECT jsonschema_is_valid(:'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::json[]);
SELECT jsonschema_is_valid(:'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::jsonb[]);

-- Invalid
SELECT jsonschema_is_valid('foo', :'addr_schema'::json);
SELECT jsonschema_is_valid('bar', :'addr_schema'::jsonb);
Expand Down
6 changes: 6 additions & 0 deletions test/sql/validates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ SELECT jsonschema_validates(:'user'::json, :'user_schema_id', :'addr_schema'::js
SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', :'addr_schema'::jsonb, :'user_schema'::jsonb );
SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', :'addr_schema'::json, :'user_schema'::json );

-- Variadic
SELECT jsonschema_validates(:'user'::json, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::json[] );
SELECT jsonschema_validates(:'user'::json, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::jsonb[] );
SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::jsonb[] );
SELECT jsonschema_validates(:'user'::jsonb, :'user_schema_id', VARIADIC ARRAY[:'addr_schema', :'user_schema']::json[] );

-- Invalid User
\set invalid_user '{"username": "hello"}'
SELECT jsonschema_validates(:'invalid_user'::json, :'user_schema_id', :'addr_schema'::json, :'user_schema'::json );
Expand Down

0 comments on commit 78eec5b

Please sign in to comment.