mirror of
https://github.com/discourse/discourse.git
synced 2025-02-08 04:18:23 +00:00
add onpdiff tests
This commit is contained in:
parent
206ef3dc08
commit
ccd0f9c371
@ -15,11 +15,11 @@ class ONPDiff
|
|||||||
end
|
end
|
||||||
|
|
||||||
def diff
|
def diff
|
||||||
@diff ||= build_diff_script(compose)
|
@diff ||= build_edit_script(compose)
|
||||||
end
|
end
|
||||||
|
|
||||||
def short_diff
|
def short_diff
|
||||||
@short_diff ||= build_short_diff_script(compose)
|
@short_diff ||= build_short_edit_script(compose)
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
@ -78,7 +78,7 @@ class ONPDiff
|
|||||||
y
|
y
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_diff_script(shortest_path)
|
def build_edit_script(shortest_path)
|
||||||
ses = []
|
ses = []
|
||||||
x, y = 1, 1
|
x, y = 1, 1
|
||||||
px, py = 0, 0
|
px, py = 0, 0
|
||||||
@ -108,7 +108,7 @@ class ONPDiff
|
|||||||
ses
|
ses
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_short_diff_script(shortest_path)
|
def build_short_edit_script(shortest_path)
|
||||||
ses = []
|
ses = []
|
||||||
x, y = 1, 1
|
x, y = 1, 1
|
||||||
px, py = 0, 0
|
px, py = 0, 0
|
||||||
|
35
spec/components/onpdiff_spec.rb
Normal file
35
spec/components/onpdiff_spec.rb
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
require 'spec_helper'
|
||||||
|
require 'onpdiff'
|
||||||
|
|
||||||
|
describe ONPDiff do
|
||||||
|
|
||||||
|
describe "diff" do
|
||||||
|
|
||||||
|
it "returns an empty array when there is no content to diff" do
|
||||||
|
ONPDiff.new("", "").diff.should == []
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an array with the operation code for each element" do
|
||||||
|
ONPDiff.new("abcd", "abef").diff.should == [["a", :common], ["b", :common], ["e", :add], ["f", :add], ["c", :delete], ["d", :delete]]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "short_diff" do
|
||||||
|
|
||||||
|
it "returns an empty array when there is no content to diff" do
|
||||||
|
ONPDiff.new("", "").short_diff.should == []
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an array with the operation code for each element" do
|
||||||
|
ONPDiff.new("abc", "acd").short_diff.should == [["a", :common], ["b", :delete], ["c", :common], ["d", :add]]
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns an array with sequencially similar operations merged" do
|
||||||
|
ONPDiff.new("abcd", "abef").short_diff.should == [["ab", :common], ["ef", :add], ["cd", :delete]]
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user