BEGIN;
SELECT plan(10);

SELECT has_function('current_season');
SELECT function_lang_is('current_season', 'sql');
SELECT function_returns('current_season', 'integer');

INSERT INTO seasons (started_at, ended_at) VALUES (NOW(), NOW() + interval '3 months');
SELECT results_eq(
    'SELECT current_season()',
    'SELECT 1',
    'should select a season'
);

SELECT has_function('category_score');
SELECT function_lang_is('category_score', 'plpgsql');
SELECT function_returns('category_score', 'smallint');

SELECT results_eq(
    $$SELECT category_score('win')$$,
    'SELECT 1::smallint'
);

SELECT results_eq(
    'SELECT category_score(''superbowl''),'
        || 'category_score(''conference'')',
    'SELECT 10::smallint, 10::smallint'
);

SELECT results_eq(
    'SELECT category_score(''playoffs''), '
        || 'category_score(''divisional''),'
        || 'category_score(''champion'')',
    'SELECT 5::smallint, 5::smallint, 5::smallint'
);

SELECT * FROM finish();
ROLLBACK;
