Closed eserte closed 4 years ago
In older versions of Type::Tiny::Enum, the values
method and the @{}
overload would return the enum values sorted alphabetically and filtered to remove duplicates. The deduping and sorting was never documented. And it was inconsistent with Moose::Meta::TypeConstraint::Enum's values
method which doesn't dedupe or sort the list. (And Type::Tiny::Enum tries to emulate the Moose API where possible.)
Since 1.006000, values
and @{}
now return the original list of values, not sorted or deduped. (But non-strings are stringified.) There's a new method called unique_values
that returns a sorted deduped list.
I've had a quick look at the Raisin code and it looks like having Moose and Type::Tiny's behaviour match up here will actually be helpful as you're supporting both kinds of Enum. The test case can be fixed by just changing qw( foo bar )
to qw( bar foo )
when you create the type (rather than when you test it in the expected bit). That way $enum->values
will return bar first in both older and newer releases of Type::Tiny.
Thanks @tobyink. Fixed as suggested.
You've changed the expected
. The way you've changed it, it will work on 1.006000 but I think it will fail on older versions.
You want something like this:
{
method => 'POST',
params => [
Raisin::Param->new(
named => 0,
type => 'required',
spec => { name => 'enum', type => Enum[qw(bar foo)], default => 'foo', in => 'body' }, # the change is here
)
],
expected => [
{
default => 'foo',
description => '',
in => 'body',
name => 'enum',
required => JSON::MaybeXS::true,
type => 'string',
enum => [qw(bar foo)],
}
]
},
This way, whether Enum sorts qw(bar foo)
or leaves it in its original order doesn't matter, because the original order is already sorted.
On my smokers I see the following test failure:
Statistical analysis suggests that this problem happens if Type::Tiny 1.006000 is installed (@tobyink: FYI):