Sha256: 276f788085eb42ac3b373ed3ab8c111c2b9469a917c76f2c69b90d39cb1a4c24

Contents?: true

Size: 1.77 KB

Versions: 18

Compression:

Stored size: 1.77 KB

Contents

require 'recog/fingerprint/regexp_factory'

describe Recog::Fingerprint::RegexpFactory do

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

    it "should have the right number of flags" do
      expect(subject.size).to be 5
    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

    context 'with invalid flags' do
      let(:flags) { %w(SYN ACK FIN) } # oh, wrong flags!
      specify 'raises and lists supported/unsupported flags' do
        expect { subject }.to raise_error(/SYN,ACK,FIN. Must be one of: .+/)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
recog-2.0.5 spec/lib/recog/fingerprint/regexp_factory.rb
recog-2.0.4 spec/lib/recog/fingerprint/regexp_factory.rb
recog-2.0.2 spec/lib/recog/fingerprint/regexp_factory.rb
recog-2.0.1 spec/lib/recog/fingerprint/regexp_factory.rb
recog-2.0.0 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.29 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.28 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.27 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.26 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.25 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.24 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.23 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.22 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.21 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.20 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.19 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.18 spec/lib/recog/fingerprint/regexp_factory.rb
recog-1.0.17 spec/lib/recog/fingerprint/regexp_factory.rb