|
| 1 | +# -*- coding:binary -*- |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +RSpec.describe Msf::OptIntRange do |
| 6 | + valid_values = [ |
| 7 | + { :value => '1', :normalized => '1' }, |
| 8 | + { :value => '1,2', :normalized => '1,2' }, |
| 9 | + { :value => '1, 2, 3-5', :normalized => '1,2,3-5' }, |
| 10 | + ] |
| 11 | + invalid_values = [ |
| 12 | + { :value => "bbq" }, |
| 13 | + { :value => "0.1" }, |
| 14 | + { :value => "0xG" }, |
| 15 | + { :value => "FF" }, |
| 16 | + ] |
| 17 | + |
| 18 | + it_behaves_like "an option", valid_values, invalid_values, 'integer range' |
| 19 | + |
| 20 | + describe '.parse' do |
| 21 | + it 'parses a single number to a single number' do |
| 22 | + expect(described_class.parse('1')).to be_a Enumerator |
| 23 | + expect(described_class.parse('1').to_a).to eq [1] |
| 24 | + end |
| 25 | + |
| 26 | + it 'parses a range of numbers to multiple numbers' do |
| 27 | + expect(described_class.parse('1-3')).to be_a Enumerator |
| 28 | + expect(described_class.parse('1-3').to_a).to eq [1, 2, 3] |
| 29 | + end |
| 30 | + |
| 31 | + it 'parses a mixture to multiple numbers' do |
| 32 | + expect(described_class.parse('1-3,5')).to be_a Enumerator |
| 33 | + expect(described_class.parse('1-3,5').to_a).to eq [1, 2, 3, 5] |
| 34 | + end |
| 35 | + |
| 36 | + it 'parses a range with a single number exclusion' do |
| 37 | + expect(described_class.parse('1-3,!2')).to be_a Enumerator |
| 38 | + expect(described_class.parse('1-3,!2').to_a).to eq [1, 3] |
| 39 | + end |
| 40 | + |
| 41 | + it 'parses a range with a range number exclusion' do |
| 42 | + expect(described_class.parse('1-5,!2-3')).to be_a Enumerator |
| 43 | + expect(described_class.parse('1-5,!2-3').to_a).to eq [1, 4, 5] |
| 44 | + end |
| 45 | + end |
| 46 | +end |
| 47 | + |
| 48 | + |
0 commit comments