Sha256: 63796078fe994fa11e4bb35a490b44f3b8336507508217ba830c275aff24f7ce

Contents?: true

Size: 1.3 KB

Versions: 10

Compression:

Stored size: 1.3 KB

Contents

require "test_helper"

class RegexTest < ActiveSupport::TestCase

  context "email_regex" do

    should "match valid emails" do
      ["john@example.com",
       "john+locke@example.com",
       "john.locke@example.com",
       "john.locke@example.us"].each do |value|
        assert_match Typus::Regex::Email, value
      end
    end

    should "not match invalid emails" do
      [%Q(this_is_chelm@example.com\n<script>location.href="http://spammersite.com"</script>),
       "admin",
       "TEST@EXAMPLE.COM",
       "test@example",
       "test@example.c",
       "testexample.com"].each do |value|
        assert_no_match Typus::Regex::Email, value
      end
    end

  end

  context "uri_regex" do

    should "match valid urls" do
      ["http://example.com",
       "http://www.example.com",
       "http://www.example.es",
       "http://www.example.co.uk",
       "http://four.sentenc.es",
       "http://www.ex-ample.com"].each do |value|
        assert_match Typus::Regex::Url, value
      end
    end

    should "not match invalid urls" do
      [%Q(this_is_chelm@example.com\n<script>location.href="http://spammersite.com"</script>),
       "example.com",
       "http://examplecom",
       "http://ex+ample.com"].each do |value|
        assert_no_match Typus::Regex::Url, value
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
typus-3.0.11 test/lib/typus/regex_test.rb
typus-3.0.11.rc5 test/lib/typus/regex_test.rb
typus-3.0.11.rc4 test/lib/typus/regex_test.rb
typus-3.0.11.rc3 test/lib/typus/regex_test.rb
typus-3.0.11.rc2 test/lib/typus/regex_test.rb
typus-3.0.11.rc1 test/lib/typus/regex_test.rb
typus-3.0.10 test/lib/typus/regex_test.rb
typus-3.0.9 test/lib/typus/regex_test.rb
typus-3.0.8 test/lib/typus/regex_test.rb
typus-3.0.7 test/lib/typus/regex_test.rb