discourse/spec/components/onpdiff_spec.rb

36 lines
1004 B
Ruby
Raw Normal View History

2016-04-01 05:33:25 +08:00
require 'rails_helper'
2013-12-17 01:39:49 +08:00
require 'onpdiff'
describe ONPDiff do
describe "diff" do
it "returns an empty array when there is no content to diff" do
2015-01-10 00:34:37 +08:00
expect(ONPDiff.new("", "").diff).to eq([])
2013-12-17 01:39:49 +08:00
end
it "returns an array with the operation code for each element" do
2015-01-10 00:34:37 +08:00
expect(ONPDiff.new("abcd", "abef").diff).to eq([["a", :common], ["b", :common], ["e", :add], ["f", :add], ["c", :delete], ["d", :delete]])
2013-12-17 01:39:49 +08:00
end
end
describe "short_diff" do
it "returns an empty array when there is no content to diff" do
2015-01-10 00:34:37 +08:00
expect(ONPDiff.new("", "").short_diff).to eq([])
2013-12-17 01:39:49 +08:00
end
it "returns an array with the operation code for each element" do
2015-01-10 00:34:37 +08:00
expect(ONPDiff.new("abc", "acd").short_diff).to eq([["a", :common], ["b", :delete], ["c", :common], ["d", :add]])
2013-12-17 01:39:49 +08:00
end
it "returns an array with sequencially similar operations merged" do
2015-01-10 00:34:37 +08:00
expect(ONPDiff.new("abcd", "abef").short_diff).to eq([["ab", :common], ["ef", :add], ["cd", :delete]])
2013-12-17 01:39:49 +08:00
end
end
end