-- Test nominatim_fdw_version() returns a non-empty string
SELECT length(nominatim_fdw_version()) > 0 AS version_exists;

-- Test nominatim_fdw_version() contains expected components
SELECT 
    nominatim_fdw_version() ~ 'nominatim_fdw\s+[0-9]+\.[0-9]+' AS has_nominatim_fdw_version,
    nominatim_fdw_version() ~ 'PostgreSQL\s+[0-9]+' AS has_postgresql_version,
    nominatim_fdw_version() ~ 'libxml\s+[0-9]+\.[0-9]+' AS has_libxml_version,
    nominatim_fdw_version() ~ 'libcurl\s+[0-9]+\.[0-9]+' AS has_libcurl_version;

-- Test nominatim_fdw_settings() C function returns a non-empty string
SELECT length(nominatim_fdw_settings()) > 0 AS settings_exists;

-- Test nominatim_fdw_settings() C function contains expected core components
SELECT 
    nominatim_fdw_settings() ~ 'nominatim_fdw\s+[0-9]+\.[0-9]+' AS has_nominatim_fdw,
    nominatim_fdw_settings() ~ 'PostgreSQL\s+[0-9]+' AS has_postgresql,
    nominatim_fdw_settings() ~ 'libxml\s+[0-9]+\.[0-9]+' AS has_libxml,
    nominatim_fdw_settings() ~ 'libcurl\s+[0-9]+\.[0-9]+' AS has_libcurl;

-- Test nominatim_fdw_settings view returns expected components
SELECT component, version IS NOT NULL AS has_version
FROM nominatim_fdw_settings
ORDER BY component COLLATE "C" DESC;

-- Test that nominatim_fdw_settings view returns core components
SELECT 
    COUNT(*) >= 5 AS has_minimum_components,
    COUNT(*) FILTER (WHERE component = 'nominatim_fdw') = 1 AS has_nominatim_fdw,
    COUNT(*) FILTER (WHERE component = 'PostgreSQL') = 1 AS has_postgresql,
    COUNT(*) FILTER (WHERE component = 'libxml') = 1 AS has_libxml,
    COUNT(*) FILTER (WHERE component = 'libcurl') = 1 AS has_libcurl
FROM nominatim_fdw_settings;
