use utf8;
use strict;
use warnings;
use open qw( :encoding(UTF-8) :std );
use Test::More tests => 24;
use Test::Warn;
use CLDR::Number;

my $cldr = CLDR::Number->new;

# conversion
is $cldr->locale, 'zh-Hant-HK', 'convert undercore to dash';

is $cldr->locale, 'zh-Hant-HK', 'convert language to lowercase';

is $cldr->locale, 'zh-Hant-HK', 'convert script to titlecase';

is $cldr->locale, 'zh-Hant-HK', 'convert region to uppercase';

is $cldr->locale, 'ast', 'convert 3-letter language to lowercase';

is $cldr->locale, 'en', 'allow trailing dash and remove';

is $cldr->locale, 'fr', 'allow trailing underscore and remove';

# BCP 47 conversion
is $cldr->locale, 'root', 'und → root';

# Unicode locale extensions
    local $TODO = 'Unicode locale extensions not currently retained';
    is $cldr->locale, 'ja-u-cu-jpy-nu-fullwide', 'sort keywords';

# defaults
$cldr = CLDR::Number->new;
is $cldr->locale, 'root', 'locale is root when undefined with no default';
ok !$cldr->default_locale, 'no default for the default locale';

is $cldr->locale, 'root', 'locale is root when invalid with no default';

warning_is {
    $cldr = CLDR::Number->new(default_locale => 'xx');
    ok !$cldr->default_locale, 'default locale does not fallback like locale';
} q{default_locale 'xx' is unknown};

$cldr = CLDR::Number->new(default_locale => 'en-GB');
is $cldr->default_locale, 'en-GB', 'default locale is set';
is $cldr->locale, 'en-GB', 'locale is default when undefined with default';

is $cldr->locale, 'en-GB', 'locale is default when invalid with default';

# fallbacks
$cldr = CLDR::Number->new;
is $cldr->locale, 'en', 'locale is language when invalid country';

is $cldr->locale, 'eo', 'locale is language when unavailable country';

is $cldr->locale, 'en', 'locale is language when invalid script';

is $cldr->locale, 'zh', 'locale is language when unavailable script';

is $cldr->locale, 'zh-Hant', 'locale is language-script when unavailable country';

is $cldr->locale, 'en-GB', 'locale is language-country when unavailable script';

is $cldr->locale, 'es-419', 'numeric regions are supported';