Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from vladimir-tikhonov/smiles-and-emojis-matcher
Smiles and emojis matcher
- Loading branch information
Showing
7 changed files
with
100 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
require 'regexy/version' | ||
|
||
module Regexy | ||
autoload :Regexp, 'regexy/regexp' | ||
autoload :Regexp, 'regexy/regexp' | ||
autoload :RegexpWithMode, 'regexy/regexp' | ||
autoload :Web, 'regexy/web' | ||
autoload :Web, 'regexy/web' | ||
autoload :Text, 'regexy/text' | ||
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,6 @@ | ||
module Regexy | ||
module Text | ||
autoload :Smile, 'regexy/text/smile' | ||
autoload :Emoji, 'regexy/text/emoji' | ||
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,13 @@ | ||
# encoding: UTF-8 | ||
|
||
module Regexy | ||
module Text | ||
class Emoji < Regexy::Regexp | ||
SMILE_REGEX = /([\u{1F600}-\u{1F6FF}])/i | ||
|
||
def initialize(*args) | ||
super(SMILE_REGEX, *args) | ||
end | ||
end | ||
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,11 @@ | ||
module Regexy | ||
module Text | ||
class Smile < Regexy::Regexp | ||
SMILE_REGEX = /\A((?<![\\:;x])[:8bx;][-=]?[dx\)\(0op\*\#s\\\/](?![\)\(\*\/\\\#]))\z/i | ||
|
||
def initialize(*args) | ||
super(SMILE_REGEX, *args) | ||
end | ||
end | ||
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,11 @@ | ||
# encoding: UTF-8 | ||
|
||
describe Regexy::Text::Emoji do | ||
let(:r) { Regexy::Text::Emoji.new } | ||
|
||
it 'accepts valid emoji characters' do | ||
128512.upto(128767).each do |p| # rubynius doesn't want to iterate through unicode chars | ||
expect([p].pack('U*') =~ r).to be_truthy | ||
end | ||
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,35 @@ | ||
describe Regexy::Text::Smile do | ||
VALID_SMILES = [ | ||
':)', ':=)', ':-)', ':(', | ||
':=(', ':-(', ':D', ':=D', | ||
':-D', ':d', ':=d', ':-d', | ||
'8=)', '8-)', 'B=)', 'B-)', | ||
';)', ';-)', ';=)', ':o', | ||
':=o', ':-o', ':O', ':=O', | ||
':-O', ';(', ';-(', ';=(', | ||
':*', ':=*', ':-*', ':P', | ||
':=P', ':-P', ':p', ':=p', | ||
':-p', ':S', ':-S', ':=S', | ||
':s', ':-s', ':=s', ':x', | ||
':-X', ':#', ':-#', ':=x', | ||
':=X', ':=#', 'xd', ':\\', ':D', ':/' | ||
] | ||
|
||
INVALID_SMILES = [ | ||
'://', '::)' | ||
] | ||
|
||
let(:r) { Regexy::Text::Smile.new } | ||
|
||
it 'accept valid smiles' do | ||
VALID_SMILES.each do |smile| | ||
expect(smile =~ r).to be_truthy | ||
end | ||
end | ||
|
||
it 'does not accept invalid smiles' do | ||
INVALID_SMILES.each do |smile| | ||
expect(smile =~ r).to be_nil | ||
end | ||
end | ||
end |