File: tdiff_examples.rb

package info (click to toggle)
ruby-tdiff 0.3.3-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 172 kB
  • sloc: ruby: 266; makefile: 3
file content (40 lines) | stat: -rw-r--r-- 1,128 bytes parent folder | download | duplicates (2)
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
require 'spec_helper'
require 'helpers/trees'

shared_examples_for 'TDiff' do |method|
  include Helpers::Trees

  it "should tell if two trees are identical" do
    expect(@tree.send(method,@tree).all? { |change,node|
      change == ' '
    }).to eq(true)
  end

  it "should stop if the root nodes have changed" do
    changes = @tree.send(method,@different_root).to_a

    expect(changes.length).to eq(2)

    expect(changes[0][0]).to eq('-')
    expect(changes[0][1]).to eq(@tree)

    expect(changes[1][0]).to eq('+')
    expect(changes[1][1]).to eq(@different_root)
  end

  it "should tell when sub-nodes are added" do
    changes = @tree.send(method,@added).select { |change,node| change == '+' }

    expect(changes.length).to eq(1)
    expect(changes[0][0]).to eq('+')
    expect(changes[0][1]).to eq(@added.children[0].children[1])
  end

  it "should tell when sub-nodes are removed" do
    changes = @tree.send(method,@removed).select { |change,node| change == '-' }

    expect(changes.length).to eq(1)
    expect(changes[0][0]).to eq('-')
    expect(changes[0][1]).to eq(@tree.children[0].children[1])
  end
end