The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
BEGIN {
  unless (eval {; require Types::Standard; 1 } && !$@) {
    require Test::More;
    Test::More::plan(skip_all =>
      'these tests require Types::Standard'
    );
  }
}

use Test::More;
use strict; use warnings FATAL => 'all';

use List::Objects::WithUtils;
use Types::Standard -all;

my $immh = immhash_of Int() => ( foo => 1, bar => 2 );

ok $immh->type == Int, 'type ok';

ok $immh->get('foo') == 1 && $immh->get('bar') == 2, 'get ok';

eval {; immhash_of Int() => ( foo => 'baz' ) };
ok $@ =~ /constraint/, 'immhash_of invalid type died';

for my $method
  (@List::Objects::WithUtils::Role::Hash::Immutable::ImmutableMethods) {
  local $@;
  eval {; $immh->$method };
  ok $@ =~ /implemented/, "$method dies"
}

eval {; $immh->{foo} = 3 };
ok $@ =~ /read-only/, 'hash item set dies';

eval {; delete $immh->{foo} };
ok $@ =~ /read-only/, 'hash item delete dies';

eval {; $immh->{quux} = 4 };
ok $@ =~ /read-only/, 'hash item insert dies';

done_testing;