Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. use v6;
  2. use Test;
  3.  
  4. plan 38;
  5.  
  6. =begin description
  7.  
  8. Testing the C<:ignorecase> regex modifier - more tests are always welcome
  9.  
  10. There are still a few things missing, like lower case <-> title case <-> upper
  11. case tests
  12.  
  13. Note that the meaning of C<:i> does B<not> descend into subrules.
  14.  
  15. =end description
  16.  
  17. # tests for inline modifiers
  18. # L<S05/Modifiers/and Unicode-level modifiers can be>
  19.  
  20. ok("abcDEFghi" ~~ m/abc (:i def) ghi/, 'Match');
  21. ok(!( "abcDEFGHI" ~~ m/abc (:i def) ghi/ ), 'Mismatch');
  22.  
  23.  
  24. #L<S05/Modifiers/"The :i">
  25.  
  26. my regex mixedcase { Hello };
  27.  
  28. # without :i
  29.  
  30. ok "Hello" ~~ m/<&mixedcase>/, "match mixed case (subrule)";
  31. ok 'Hello' ~~ m/Hello/, "match mixed case (direct)";
  32.  
  33. ok "hello" !~~ m/<&mixedcase>/, "do not match lowercase (subrule)";
  34. ok "hello" !~~ m/Hello/, "do not match lowercase (direct)";
  35.  
  36. ok "hello" !~~ m:i/<&mixedcase>/, "no match with :i if matched by subrule";
  37. ok "hello" ~~ m:i/Hello/, "match with :i (direct)";
  38.  
  39. ok "hello" !~~ m:ignorecase/<&mixedcase>/, "no match with :ignorecase + subrule";
  40. ok "hello" ~~ m:ignorecase/Hello/, "match with :ignorecase (direct)";
  41. ok('Δ' ~~ m:i/δ/, ':i with greek chars');
  42.  
  43. # The German ß (&szlig;) maps to uppercase SS:
  44. #?rakudo.jvm 2 todo 'ignorecase and SS/&szlig; RT #121377'
  45. # RT #121377'
  46. ok('ß' ~~ m:i/SS/, "ß matches SS with :ignorecase");
  47. ok('SS' ~~ m:i/ß/, "SS matches ß with :ignorecase");
  48.  
  49.  
  50. #RT #76750
  51. ok('a' ~~ m/:i 'A'/, ':i descends into quotes');
  52.  
  53. # RT #76500
  54. {
  55. my $matcher = 'aA';
  56. nok 'aa' ~~ / $matcher/, 'interpolation: no match without :i';
  57. ok 'aa' ~~ /:i $matcher/, 'interpolation: match with :i';
  58. }
  59.  
  60. ok 'a' ~~ /:i A|B /, ':i and LTM sanity';
  61. ok 'a' ~~ /:i < A B > /, ':i and quote words';
  62.  
  63. ok 'A4' ~~ /:i a[3|4|5] | b[3|4] /, 'alternation sanity';
  64.  
  65. #RT #114362
  66. {
  67. ok "BLAR" ~~ /:ignorecase [blar | blubb]/, ":ignorecase works with |";
  68. ok "BluBb" ~~ /:ignorecase [blar || blubb]/, ":ignorecase works with |";
  69. }
  70.  
  71. # RT #114692
  72. {
  73. try EVAL '"ABC" ~~ /:iabc/';
  74. ok $!, "need whitespace after modifier";
  75. }
  76.  
  77. # RT #77410
  78. {
  79. ok "m" ~~ /:i <[M]>/, "ignore case of character classes";
  80. nok "m" ~~ /<[M]>/, "ignore case of character classes";
  81. nok "n" ~~ /:i <[M]>/, "ignore case of character classes";
  82. }
  83. # RT #126793
  84. {
  85. #?rakudo.jvm 1 todo "ligatures don't casefold on JVM"
  86. ok 'st' ~~ /:i st/, ":i haystack 'st' needle 'st'";
  87. #?rakudo 10 todo "ligatures in the haystack of case insensensitive regex don't work"
  88. for 1..10 {
  89. my $haystack = ('a'..'z').pick($_).join ~ 'st';
  90. ok $haystack ~~ /:i st/, ":i haystack: '$haystack' needle: 'st'";
  91. }
  92. }
  93. nok (88.chr ~ 875.chr ~ 8413.chr) ~~ /:i x /, 'case insensitive regex works for haystacks which have synthetic graphemes';
  94. ok (88.chr ~ 875.chr ~ 8413.chr ~ 'x') ~~ /:i x /, 'case insensitive regex works for haystacks which have synthetic graphemes';
  95.  
  96. # vim: syn=perl6 sw=4 ts=4 expandtab
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement