Sha256: ab0f3685a31ed46b4164c46f0bfdafa48da5783e5120922bcdf18b77bdec9acb

Contents?: true

Size: 1.51 KB

Versions: 17

Compression:

Stored size: 1.51 KB

Contents

require 'recog/fingerprint/regexp_factory'

describe Recog::Fingerprint::RegexpFactory do

  describe 'FLAG_MAP' do
    subject { described_class::FLAG_MAP }

    it "should have three flags" do
      expect(subject.size).to be 3
    end
  end

  describe '.build' do
    subject { described_class.build(pattern, options) }

    let(:pattern) { 'Apache/(\d+)' }
    let(:options) { [ 'REG_ICASE' ] }

    it { is_expected.to be_a(Regexp) }
    it { is_expected.to match('Apache/2') }

  end

  describe '.build_options' do
    subject { described_class.build_options(flags) }

    let(:flags) { [ ] }
    it { is_expected.to be_a(Fixnum) }

    specify "sets NOENCODING" do
      expect(subject & Regexp::NOENCODING).to_not be_zero
    end

    context 'with REG_ICASE' do
      let(:flags) { [ 'REG_ICASE' ] }
      specify "sets NOENCODING & IGNORECASE" do
        expect(subject & Regexp::NOENCODING).to_not be_zero
        expect(subject & Regexp::IGNORECASE).to_not be_zero
      end
    end

    context 'with REG_DOT_NEWLINE' do
      let(:flags) { [ 'REG_DOT_NEWLINE' ] }
      specify "sets NOENCODING & MULTILINE" do
        expect(subject & Regexp::NOENCODING).to_not be_zero
        expect(subject & Regexp::MULTILINE).to_not be_zero
      end
    end

    context 'with REG_LINE_ANY_CRLF' do
      let(:flags) { [ 'REG_LINE_ANY_CRLF' ] }
      specify "sets NOENCODING & MULTILINE" do
        expect(subject & Regexp::NOENCODING).to_not be_zero
        expect(subject & Regexp::MULTILINE).to_not be_zero
      end
    end

  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
recog-1.0.16 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.15 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.14 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.13 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.12 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.11 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.10 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.9 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.8 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.7 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.6 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.5 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.4 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.3 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.2 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.1 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.0 spec/lib/recog/fingerprint/regexp_factory.rb