Skip to content

Commit

Permalink
Test some more edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
jaynetics committed Nov 29, 2024
1 parent b757fd7 commit aa5563f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/regexp_parser/scanner/scanner.rl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
group_options = '?' . ( [^!#'():<=>~]+ . ':'? ) ?;

group_name_id_ab = ([^!=0-9\->] | utf8_multibyte) . ([^>] | utf8_multibyte)*;
group_name_id_sq = ([^0-9\-'] | utf8_multibyte) . ([^'] | utf8_multibyte)*;
group_name_id_sq = ([^0-9\-'] | utf8_multibyte) . ([^'] | utf8_multibyte)*;
group_number = '-'? . [0-9]+;
group_level = [+\-] . [0-9]+;

Expand Down
8 changes: 6 additions & 2 deletions spec/scanner/groups_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# Named groups
# Names that start with a hyphen or digit (ascii or other) are invalid.
# ")" is only allowed as first char of the name.
# "!" is allowed anywhere, but ?<!...> is treated as a lookbehind by Ruby.
# "!" and "=" are allowed anywhere, but (?<!…>…) and (?<=…>…) are treated as lookbehinds by Ruby.
include_examples 'scan', '(?<name>abc)', 0 => [:group, :named_ab, '(?<name>', 0, 8]
include_examples 'scan', "(?'name'abc)", 0 => [:group, :named_sq, "(?'name'", 0, 8]
include_examples 'scan', '(?<name_1>abc)', 0 => [:group, :named_ab, '(?<name_1>', 0,10]
Expand All @@ -17,6 +17,10 @@
include_examples 'scan', "(?'name-1'abc)", 0 => [:group, :named_sq, "(?'name-1'", 0,10]
include_examples 'scan', "(?<name'1>abc)", 0 => [:group, :named_ab, "(?<name'1>", 0,10]
include_examples 'scan', "(?'name>1'abc)", 0 => [:group, :named_sq, "(?'name>1'", 0,10]
include_examples 'scan', "(?<n!me1'>abc)", 0 => [:group, :named_ab, "(?<n!me1'>", 0,10]
include_examples 'scan', "(?'!ame1>'abc)", 0 => [:group, :named_sq, "(?'!ame1>'", 0,10]
include_examples 'scan', "(?<n=me1'>abc)", 0 => [:group, :named_ab, "(?<n=me1'>", 0,10]
include_examples 'scan', "(?'=ame1>'abc)", 0 => [:group, :named_sq, "(?'=ame1>'", 0,10]
include_examples 'scan', '(?<üüuuüü>abc)', 0 => [:group, :named_ab, '(?<üüuuüü>', 0,10]
include_examples 'scan', "(?'üüuuüü'abc)", 0 => [:group, :named_sq, "(?'üüuuüü'", 0,10]
include_examples 'scan', "(?<😋1234😋>abc)", 0 => [:group, :named_ab, "(?<😋1234😋>", 0,10]
Expand All @@ -38,10 +42,10 @@
include_examples 'scan', '(?=abc)', 0 => [:assertion, :lookahead, '(?=', 0, 3]
include_examples 'scan', '(?!abc)', 0 => [:assertion, :nlookahead, '(?!', 0, 3]
include_examples 'scan', '(?<=abc)', 0 => [:assertion, :lookbehind, '(?<=', 0, 4]
include_examples 'scan', '(?<=x>)y', 0 => [:assertion, :lookbehind, '(?<=', 0, 4]
include_examples 'scan', '(?<!abc)', 0 => [:assertion, :nlookbehind, '(?<!', 0, 4]
include_examples 'scan', '(?<!x)y>', 0 => [:assertion, :nlookbehind, '(?<!', 0, 4]
include_examples 'scan', '(?<!x>)y', 0 => [:assertion, :nlookbehind, '(?<!', 0, 4]
include_examples 'scan', '(?<=x>)y', 0 => [:assertion, :lookbehind, '(?<=', 0, 4]

# Options
include_examples 'scan', '(?-mix:abc)', 0 => [:group, :options, '(?-mix:', 0, 7]
Expand Down

0 comments on commit aa5563f

Please sign in to comment.