#!/usr/bin/env perl use 5.025009; use strict; use warnings; use utf8; use open IO => qw{:encoding(utf8) :std}; use charnames ':full'; BEGIN { my @types = qw{CONTROL PRINT COMBINE UNKNOWN}; eval 'use enum @types'; sub type_name { $types[$_[0]] } } use Test::More; my @tests = ( [ '0000' => CONTROL ], [ '0009' => CONTROL ], [ '000a' => CONTROL ], [ '0020' => PRINT ], [ '0021' => PRINT ], [ '0030' => PRINT ], [ '0040' => PRINT ], [ '0041' => PRINT ], [ '0060' => PRINT ], [ '0061' => PRINT ], [ '007e' => PRINT ], [ '007f' => CONTROL ], [ '00a0' => PRINT ], [ '0300' => COMBINE ], [ '034f' => COMBINE ], [ '2000' => PRINT ], [ '200d' => CONTROL ], [ '2028' => CONTROL ], [ '2029' => CONTROL ], [ 'fe00' => CONTROL ], [ '1f3fb' => PRINT ], [ 'e0100' => CONTROL ], [ '10ffff' => CONTROL ], ); plan tests => scalar @tests; for my $test (@tests) { my ($input, $exp) = $test->@*; is(type_of($input), $exp, "Checking '@{[sprintf q{%04X}, hex $input]}'" . " is of type '@{[type_name($exp)]}'" . " (Got: '@{[type_name(type_of($input))]}')." ); } sub type_of { my ($input) = @_; my $char = chr hex $input; return CONTROL if $char =~ / [ \p{C} \p{Zl} \p{Zp} \p{VS} ] /xx; return PRINT if $char =~ / [ \p{L} \p{N} \p{P} \p{S} \p{Zs} ] /xx; return COMBINE if $char =~ / [ \p{M} ] /xx; return UNKNOWN; } #### 1..23 ok 1 - Checking '0000' is of type 'CONTROL' (Got: 'CONTROL'). ... ok 23 - Checking '10FFFF' is of type 'CONTROL' (Got: 'CONTROL').