Browse Source

initialize

master
Arthur Poulet 6 years ago
commit
3375ae94ad
No known key found for this signature in database GPG Key ID: 7C42395DCA99B923
  1. 3
      Gemfile
  2. 16
      Rakefile
  3. 10
      lib/ruby_email.rb
  4. 30
      test/unit_test.rb

3
Gemfile

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem 'nomorebeer' # action against drunk driving

16
Rakefile

@ -0,0 +1,16 @@
#encoding: utf-8
task :default => [:test]
task :test do
ruby "test/unit_test.rb"
end
namespace :test do
desc "Unitary tests."
task :test do
ruby "test/unit_test.rb"
end
end

10
lib/ruby_email.rb

@ -0,0 +1,10 @@
module RubyEmail
ATEXT = '([\w!#\$%&\'*\+\-/=\?\^_`\{\}\|~])'
#ATEXT = '\w'
ATOM = "#{ATEXT}+"
DOT_ATOM_TEXT = "(#{ATOM})(\.#{ATOM})*"
VALIDE = "(?<local>#{DOT_ATOM_TEXT})@(?<domain>#{DOT_ATOM_TEXT})"
REGEXP = Regexp.new "\\A#{VALIDE}\\Z"
end

30
test/unit_test.rb

@ -0,0 +1,30 @@
#!/usr/bin/env ruby
require "test/unit"
require_relative '../lib/ruby_email'
class TestRubyEmail < Test::Unit::TestCase
def test_simple_true
assert "toto@toto".match RubyEmail::REGEXP
assert "toto@toto.toto".match RubyEmail::REGEXP
assert "toto@toto.toto.toto".match RubyEmail::REGEXP
assert "toto@toto.toto.toto.toto".match RubyEmail::REGEXP
end
def test_simple_false
assert_nil "t".match RubyEmail::REGEXP
assert_nil "t@".match RubyEmail::REGEXP
assert_nil "@t".match RubyEmail::REGEXP
end
def test_deep
m = "toto@toto.toto.toto.toto".match RubyEmail::REGEXP
#require 'pry';binding.pry
assert m.names & %w(local domain)
assert_equal "toto", m["local"]
assert_equal "toto.toto.toto.toto", m["domain"]
end
end
Loading…
Cancel
Save