diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2022-11-08 21:09:55 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2022-11-11 17:00:31 +0100 |
| commit | 3fb84dc0aedd604360532fa6442f756389d4d677 (patch) | |
| tree | 7bc970d68f505681575db6adac6c9181c5a865cf | |
| parent | 78a97ea8621c3fc04c65bc6f5104b247f5601095 (diff) | |
| download | perlweeklychallenge-club-3fb84dc0aedd604360532fa6442f756389d4d677.tar.gz perlweeklychallenge-club-3fb84dc0aedd604360532fa6442f756389d4d677.tar.bz2 perlweeklychallenge-club-3fb84dc0aedd604360532fa6442f756389d4d677.zip | |
Solution to task 1
| -rwxr-xr-x | challenge-190/jo-37/perl/ch-1.pl | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/challenge-190/jo-37/perl/ch-1.pl b/challenge-190/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..d191a344c2 --- /dev/null +++ b/challenge-190/jo-37/perl/ch-1.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl -s + +use v5.16; +use Test2::V0; + +our ($tests, $examples); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV; +usage: $0 [-examples] [-tests] [STR] + +-examples + run the examples from the challenge + +-tests + run some tests + +STR + String to check for appropriate capital usage + +EOS + + +### Input and Output + +say 0 + !!check_caps(shift); + + +### Implementation + +# There is no need to restrict this task to ASCII letters. For Unicode +# characters there are properties "Letter uppercase" and "Letter +# lowercase". Using these here. +sub check_caps { + shift =~ /^\p{Lu}?(?:\p{Lu}*|\p{Ll}*)$/; +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + ok check_caps('Perl'), 'Example 1'; + ok check_caps('TPF'), 'Example 2'; + ok !check_caps('PyThon'), 'Example 3'; + ok check_caps('raku'), 'Example 4'; + } + + SKIP: { + skip "tests" unless $tests; + + ok check_caps('Περλ'), 'Example 1 greek'; + ok check_caps('ΤΠΦ'), 'Example 2 greek'; + ok !check_caps('ΠυΘων'), 'Example 3 greek'; + ok check_caps('ρακου'), 'Example 4 greek'; + ok check_caps('Π'), 'single uppercase'; + ok check_caps('ρ'), 'single lowercase'; + ok !check_caps('1etter'), 'not a letter'; + + } + + done_testing; + exit; +} |
