diff --git a/lib/HarfBuzz/Map.rakumod b/lib/HarfBuzz/Map.rakumod index 17da8bc..f5dd5c9 100644 --- a/lib/HarfBuzz/Map.rakumod +++ b/lib/HarfBuzz/Map.rakumod @@ -2,7 +2,7 @@ unit class HarfBuzz::Map; use HarfBuzz::Set; use HarfBuzz::Raw; -use HarfBuzz::Raw::Defs :types; +use HarfBuzz::Raw::Defs :types, :hb-set-value; has hb_map:D $!raw handles = hb_map::create(); method raw { $!raw } @@ -21,12 +21,13 @@ method values { } } -method exists(UInt:D $i --> Int) { - $!raw.exists($i).so; +method exists(UInt:D() $k --> Int) { + $!raw.exists($k).so; } -method AT-POS(UInt:D $i --> Int) { - $i < $.elems ?? $!raw.get($i) !! Int +method AT-KEY(UInt:D() $k --> Int) { + my $v := $!raw.get($k); + $v == HB_SET_VALUE_INVALID ?? Int !! $v; } submethod DESTROY { .destroy with $!raw } diff --git a/t/face.t b/t/face.t index a126301..6a5d0c2 100644 --- a/t/face.t +++ b/t/face.t @@ -21,10 +21,12 @@ subtest 'unicode-set', { subtest 'unicode-to-gid-map', { my HarfBuzz::Map $unicode-map = $face.unicode-to-gid-map; ok $unicode-map.exists(42), 'exists'; + nok $unicode-map.exists(31), '!exists'; my HarfBuzz::Set $keys = $unicode-map.keys; my HarfBuzz::Set $values = $unicode-map.values; is $values.array[10], 11, 'values'; is $unicode-map.elems, 854, 'elems'; - is $unicode-map[42], 11; + is $unicode-map{42}, 11; + is-deeply $unicode-map{31}, Int; }