File: range_spec.rb

package info (click to toggle)
ruby-necromancer 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 308 kB
  • sloc: ruby: 1,578; sh: 4; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 1,007 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

RSpec.describe Necromancer::RangeConverters, "#call" do
  describe ":string -> :range" do
    subject(:converter) { described_class::StringToRangeConverter.new }

    {
      ""          => "",
      "a"         => "a",
      "1"         => 1..1,
      "1.0"       => 1.0..1.0,
      "1..10"     => 1..10,
      "1.0..10.0" => 1.0..10.0,
      "1-10"      => 1..10,
      "1 , 10"    => 1..10,
      "1...10"    => 1...10,
      "1 . . 10"  => 1..10,
      "-1..10"    => -1..10,
      "1..-10"    => 1..-10,
      "a..z"      => "a".."z",
      "a . . . z" => "a"..."z",
      "a-z"       => "a".."z",
      "A , Z"     => "A".."Z"
    }.each do |actual, expected|
      it "converts #{actual.inspect} to range type" do
        expect(converter.(actual)).to eql(expected)
      end
    end

    it "raises error for empty string in strict mode" do
      expect {
        converter.("", strict: true)
      }.to raise_error(Necromancer::ConversionTypeError)
    end
  end
end