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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
# frozen_string_literal: true
RSpec.describe TTY::Prompt::Distance, ".distance" do
let(:object) { described_class.new }
subject(:distance) { object.distance(*strings) }
context "when nil" do
let(:strings) { [nil, nil] }
it { is_expected.to eql(0) }
end
context "when empty" do
let(:strings) { ["", ""] }
it { is_expected.to eql(0) }
end
context "with one non empty" do
let(:strings) { ["abc", ""] }
it { is_expected.to eql(3) }
end
context "when single char" do
let(:strings) { %w[a abc] }
it { is_expected.to eql(2) }
end
context "when similar" do
let(:strings) { %w[abc abc] }
it { is_expected.to eql(0) }
end
context "when similar" do
let(:strings) { %w[abc acb] }
it { is_expected.to eql(1) }
end
context "when end similar" do
let(:strings) { %w[saturday sunday] }
it { is_expected.to eql(3) }
end
context "when contain similar" do
let(:strings) { %w[which witch] }
it { is_expected.to eql(2) }
end
context "when prefix" do
let(:strings) { %w[sta status] }
it { is_expected.to eql(3) }
end
context "when similar" do
let(:strings) { %w[smellyfish jellyfish] }
it { is_expected.to eql(2) }
end
context "when unicode" do
let(:strings) { %w[マラソン五輪代表 ララソン五輪代表] }
it { is_expected.to eql(1) }
end
end
|