-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
85 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Regexp::Expression | ||
module Shared | ||
def negative? | ||
false | ||
end | ||
|
||
# not an alias so as to respect overrides of #negative? | ||
def negated? | ||
negative? | ||
end | ||
end | ||
|
||
Anchor::NonWordBoundary.class_eval { def negative?; true end } | ||
Assertion::NegativeLookahead.class_eval { def negative?; true end } | ||
Assertion::NegativeLookbehind.class_eval { def negative?; true end } | ||
CharacterSet.class_eval { def negative?; negative end } | ||
CharacterType::Base.class_eval { def negative?; token.start_with?('non') end } | ||
PosixClass.class_eval { def negative?; type == :nonposixclass end } | ||
UnicodeProperty::Base.class_eval { def negative?; type == :nonproperty end } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe('Expression::Base#negative?') do | ||
include_examples 'parse', //, [] => [:root, negative?: false] | ||
include_examples 'parse', /a/, [0] => [:literal, negative?: false] | ||
|
||
include_examples 'parse', /\b/, [0] => [:word_boundary, negative?: false] | ||
include_examples 'parse', /\B/, [0] => [:nonword_boundary, negative?: true] | ||
|
||
include_examples 'parse', /(?=)/, [0] => [:lookahead, negative?: false] | ||
include_examples 'parse', /(?!)/, [0] => [:nlookahead, negative?: true] | ||
|
||
include_examples 'parse', /(?<=)/, [0] => [:lookbehind, negative?: false] | ||
include_examples 'parse', /(?<!)/, [0] => [:nlookbehind, negative?: true] | ||
|
||
include_examples 'parse', /[a]/, [0] => [:character, negative?: false] | ||
include_examples 'parse', /[^a]/, [0] => [:character, negative?: true] | ||
|
||
include_examples 'parse', /\d/, [0] => [:digit, negative?: false] | ||
include_examples 'parse', /\D/, [0] => [:nondigit, negative?: true] | ||
|
||
include_examples 'parse', /[[:word:]]/, [0, 0] => [:word, negative?: false] | ||
include_examples 'parse', /[[:^word:]]/, [0, 0] => [:word, negative?: true] | ||
|
||
include_examples 'parse', /\p{word}/, [0] => [:word, negative?: false] | ||
include_examples 'parse', /\p{^word}/, [0] => [:word, negative?: true] | ||
|
||
include_examples 'parse', //, [] => [:root, negated?: false] | ||
include_examples 'parse', /[^a]/, [0] => [:character, negated?: true] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters