tdiff 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +28 -0
- data/.gitignore +1 -0
- data/ChangeLog.md +9 -0
- data/Gemfile +14 -0
- data/LICENSE.txt +1 -1
- data/README.md +41 -35
- data/Rakefile +6 -31
- data/gemspec.yml +9 -4
- data/lib/tdiff/tdiff.rb +3 -1
- data/lib/tdiff/unordered.rb +3 -1
- data/lib/tdiff/version.rb +3 -1
- data/lib/tdiff.rb +5 -3
- data/spec/spec_helper.rb +0 -1
- data/spec/tdiff_examples.rb +14 -14
- data/spec/tdiff_spec.rb +13 -13
- data/spec/unordered_spec.rb +2 -2
- data/tdiff.gemspec +1 -4
- metadata +23 -58
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6d61fc5d074be499bc2ae185b6449d10354fe3dfd2dfda2ad1529f246dc1cb39
|
4
|
+
data.tar.gz: 4496f53bef15c4e46d195434458ded3a6f13b65afda56a755d5d3128a3b94463
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ab9b88ebc51c447c49c19b8823849d3b8b25f7d3c981bda20c74743415dd8e6062371a67493245160a6d31f004a3e06cf97357c57576c981b6f2a93da7af60d
|
7
|
+
data.tar.gz: 461c9fcc0bd2ad6d48a7801f6f847baadbabe6e55c4b75d3dd50e86400fdab477ecb910a70a8972cd6460261e149c639ae64af3d3b2a111d363cea5a6130a599
|
@@ -0,0 +1,28 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on: [ push, pull_request ]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
tests:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
strategy:
|
9
|
+
fail-fast: false
|
10
|
+
matrix:
|
11
|
+
ruby:
|
12
|
+
- '3.0'
|
13
|
+
- '3.1'
|
14
|
+
- '3.2'
|
15
|
+
- '3.3'
|
16
|
+
- jruby
|
17
|
+
- truffleruby
|
18
|
+
name: Ruby ${{ matrix.ruby }}
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v4
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
- name: Install dependencies
|
26
|
+
run: bundle install --jobs 4 --retry 3
|
27
|
+
- name: Run tests
|
28
|
+
run: bundle exec rake test
|
data/.gitignore
CHANGED
data/ChangeLog.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
### 0.4.0 / 2024-01-24
|
2
|
+
|
3
|
+
* Switched to using `require_relative` to improve load-times.
|
4
|
+
* Added `# frozen_string_literal: true` to all files.
|
5
|
+
|
6
|
+
### 0.3.4 / 2018-06-11
|
7
|
+
|
8
|
+
* Fixed shadowed variable warning (@bhollis).
|
9
|
+
|
1
10
|
### 0.3.3 / 2012-05-28
|
2
11
|
|
3
12
|
* Require ruby >= 1.8.7.
|
data/Gemfile
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
* [Source](https://github.com/postmodern/tdiff)
|
4
4
|
* [Issues](https://github.com/postmodern/tdiff/issues)
|
5
|
-
*
|
5
|
+
* [Documentation](https://rubydoc.info/gems/tdiff)
|
6
6
|
|
7
7
|
## Description
|
8
8
|
|
@@ -22,56 +22,62 @@ module.
|
|
22
22
|
|
23
23
|
Diff two HTML documents:
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
```ruby
|
26
|
+
require 'nokogiri'
|
27
|
+
require 'tdiff'
|
27
28
|
|
28
|
-
|
29
|
+
class Nokogiri::XML::Node
|
29
30
|
|
30
|
-
|
31
|
+
include TDiff
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
def tdiff_equal(node)
|
34
|
+
if (self.text? && node.text?)
|
35
|
+
self.text == node.text
|
36
|
+
elsif (self.respond_to?(:root) && node.respond_to?(:root))
|
37
|
+
self.root.tdiff_equal(node.root)
|
38
|
+
elsif (self.respond_to?(:name) && node.respond_to?(:name))
|
39
|
+
self.name == node.name
|
40
|
+
else
|
41
|
+
false
|
42
|
+
end
|
43
|
+
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def tdiff_each_child(node,&block)
|
46
|
+
node.children.each(&block)
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
51
|
+
doc1 = Nokogiri::HTML('<div><p>one</p> <p>three</p></div>')
|
52
|
+
doc2 = Nokogiri::HTML('<div><p>one</p> <p>two</p> <p>three</p></div>')
|
52
53
|
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
doc1.at('div').tdiff(doc2.at('div')) do |change,node|
|
55
|
+
puts "#{change} #{node.to_html}".ljust(30) + node.parent.path
|
56
|
+
end
|
57
|
+
```
|
56
58
|
|
57
59
|
### Output
|
58
60
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
```
|
62
|
+
+ <p>one</p> /html/body/div
|
63
|
+
+ /html/body/div
|
64
|
+
<p>one</p> /html/body/div
|
65
|
+
/html/body/div
|
66
|
+
<p>three</p> /html/body/div
|
67
|
+
- one /html/body/div/p[1]
|
68
|
+
+ two /html/body/div/p[2]
|
69
|
+
three /html/body/div/p[2]
|
70
|
+
```
|
67
71
|
|
68
72
|
## Requirements
|
69
73
|
|
70
|
-
* [ruby](http://www.ruby-lang.org/) >=
|
74
|
+
* [ruby](http://www.ruby-lang.org/) >= 2.0.0
|
71
75
|
|
72
76
|
## Install
|
73
77
|
|
74
|
-
|
78
|
+
```shell
|
79
|
+
$ gem install tdiff
|
80
|
+
```
|
75
81
|
|
76
82
|
## Copyright
|
77
83
|
|
data/Rakefile
CHANGED
@@ -1,36 +1,11 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'rubygems/tasks'
|
3
|
+
Gem::Tasks.new
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
require 'rubygems/tasks'
|
7
|
-
|
8
|
-
Gem::Tasks.new
|
9
|
-
rescue LoadError => e
|
10
|
-
warn e.message
|
11
|
-
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
12
|
-
end
|
13
|
-
|
14
|
-
begin
|
15
|
-
gem 'rspec', '~> 2.4'
|
16
|
-
require 'rspec/core/rake_task'
|
17
|
-
|
18
|
-
RSpec::Core::RakeTask.new
|
19
|
-
rescue LoadError => e
|
20
|
-
task :spec do
|
21
|
-
abort "Please run `gem install rspec` to install RSpec."
|
22
|
-
end
|
23
|
-
end
|
5
|
+
require 'rspec/core/rake_task'
|
6
|
+
RSpec::Core::RakeTask.new
|
24
7
|
task :test => :spec
|
25
8
|
task :default => :spec
|
26
9
|
|
27
|
-
|
28
|
-
|
29
|
-
require 'yard'
|
30
|
-
|
31
|
-
YARD::Rake::YardocTask.new
|
32
|
-
rescue LoadError => e
|
33
|
-
task :yard do
|
34
|
-
abort "Please run `gem install yard` to install YARD."
|
35
|
-
end
|
36
|
-
end
|
10
|
+
require 'yard'
|
11
|
+
YARD::Rake::YardocTask.new
|
data/gemspec.yml
CHANGED
@@ -10,9 +10,14 @@ email: postmodern.mod3@gmail.com
|
|
10
10
|
homepage: https://github.com/postmodern/tdiff#readme
|
11
11
|
has_yard: true
|
12
12
|
|
13
|
-
|
13
|
+
metadata:
|
14
|
+
documentation_uri: https://rubydoc.info/gems/tdiff
|
15
|
+
source_code_uri: https://github.com/postmodern/tdiff
|
16
|
+
bug_tracker_uri: https://github.com/postmodern/tdiff/issues
|
17
|
+
changelog_uri: https://github.com/postmodern/tdiff/blob/main/ChangeLog.md
|
18
|
+
rubygems_mfa_required: 'true'
|
19
|
+
|
20
|
+
required_ruby_version: ">= 2.0.0"
|
14
21
|
|
15
22
|
development_dependencies:
|
16
|
-
|
17
|
-
rspec: ~> 2.4
|
18
|
-
yard: ~> 0.7
|
23
|
+
bundler: ~> 2.0
|
data/lib/tdiff/tdiff.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
#
|
2
4
|
# {TDiff} adds the ability to calculate the differences between two tree-like
|
3
5
|
# objects. Simply include {TDiff} into the class which represents the tree
|
@@ -148,7 +150,7 @@ module TDiff
|
|
148
150
|
changes = nil
|
149
151
|
|
150
152
|
# recurse down through unchanged nodes
|
151
|
-
unchanged.each { |
|
153
|
+
unchanged.each { |a,b| a.tdiff_recursive(b,&block) }
|
152
154
|
unchanged = nil
|
153
155
|
end
|
154
156
|
end
|
data/lib/tdiff/unordered.rb
CHANGED
data/lib/tdiff/version.rb
CHANGED
data/lib/tdiff.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
data/spec/tdiff_examples.rb
CHANGED
@@ -5,36 +5,36 @@ shared_examples_for 'TDiff' do |method|
|
|
5
5
|
include Helpers::Trees
|
6
6
|
|
7
7
|
it "should tell if two trees are identical" do
|
8
|
-
|
9
|
-
change == ' '
|
10
|
-
|
8
|
+
expect(
|
9
|
+
@tree.send(method,@tree).all? { |change,node| change == ' ' }
|
10
|
+
).to be true
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should stop if the root nodes have changed" do
|
14
14
|
changes = @tree.send(method,@different_root).to_a
|
15
15
|
|
16
|
-
changes.length.
|
16
|
+
expect(changes.length).to be 2
|
17
17
|
|
18
|
-
changes[0][0].
|
19
|
-
changes[0][1].
|
18
|
+
expect(changes[0][0]).to be == '-'
|
19
|
+
expect(changes[0][1]).to be == @tree
|
20
20
|
|
21
|
-
changes[1][0].
|
22
|
-
changes[1][1].
|
21
|
+
expect(changes[1][0]).to be == '+'
|
22
|
+
expect(changes[1][1]).to be == @different_root
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should tell when sub-nodes are added" do
|
26
26
|
changes = @tree.send(method,@added).select { |change,node| change == '+' }
|
27
27
|
|
28
|
-
changes.length.
|
29
|
-
changes[0][0].
|
30
|
-
changes[0][1].
|
28
|
+
expect(changes.length).to be 1
|
29
|
+
expect(changes[0][0]).to be == '+'
|
30
|
+
expect(changes[0][1]).to be == @added.children[0].children[1]
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should tell when sub-nodes are removed" do
|
34
34
|
changes = @tree.send(method,@removed).select { |change,node| change == '-' }
|
35
35
|
|
36
|
-
changes.length.
|
37
|
-
changes[0][0].
|
38
|
-
changes[0][1].
|
36
|
+
expect(changes.length).to be 1
|
37
|
+
expect(changes[0][0]).to be == '-'
|
38
|
+
expect(changes[0][1]).to be == @tree.children[0].children[1]
|
39
39
|
end
|
40
40
|
end
|
data/spec/tdiff_spec.rb
CHANGED
@@ -11,24 +11,24 @@ describe TDiff do
|
|
11
11
|
it "should detect when the order of children has changed" do
|
12
12
|
changes = @tree.tdiff(@changed_order).to_a
|
13
13
|
|
14
|
-
changes.length.
|
14
|
+
expect(changes.length).to be == 6
|
15
15
|
|
16
|
-
changes[0][0].
|
17
|
-
changes[0][1].
|
16
|
+
expect(changes[0][0]).to be == ' '
|
17
|
+
expect(changes[0][1]).to be == @tree
|
18
18
|
|
19
|
-
changes[1][0].
|
20
|
-
changes[1][1].
|
19
|
+
expect(changes[1][0]).to be == '-'
|
20
|
+
expect(changes[1][1]).to be == @tree.children[0]
|
21
21
|
|
22
|
-
changes[2][0].
|
23
|
-
changes[2][1].
|
22
|
+
expect(changes[2][0]).to be == ' '
|
23
|
+
expect(changes[2][1]).to be == @tree.children[1]
|
24
24
|
|
25
|
-
changes[3][0].
|
26
|
-
changes[3][1].
|
25
|
+
expect(changes[3][0]).to be == '+'
|
26
|
+
expect(changes[3][1]).to be == @changed_order.children[1]
|
27
27
|
|
28
|
-
changes[4][0].
|
29
|
-
changes[4][1].
|
28
|
+
expect(changes[4][0]).to be == ' '
|
29
|
+
expect(changes[4][1]).to be == @tree.children[1].children[0]
|
30
30
|
|
31
|
-
changes[5][0].
|
32
|
-
changes[5][1].
|
31
|
+
expect(changes[5][0]).to be == ' '
|
32
|
+
expect(changes[5][1]).to be == @tree.children[1].children[1]
|
33
33
|
end
|
34
34
|
end
|
data/spec/unordered_spec.rb
CHANGED
@@ -11,7 +11,7 @@ describe TDiff::Unordered do
|
|
11
11
|
include TDiff::Unordered
|
12
12
|
end
|
13
13
|
|
14
|
-
base.
|
14
|
+
expect(base).to include(TDiff)
|
15
15
|
end
|
16
16
|
|
17
17
|
it_should_behave_like 'TDiff', :tdiff_unordered
|
@@ -21,6 +21,6 @@ describe TDiff::Unordered do
|
|
21
21
|
change != ' '
|
22
22
|
end
|
23
23
|
|
24
|
-
changes.
|
24
|
+
expect(changes).to be_empty
|
25
25
|
end
|
26
26
|
end
|
data/tdiff.gemspec
CHANGED
@@ -7,10 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
|
8
8
|
gem.name = gemspec.fetch('name')
|
9
9
|
gem.version = gemspec.fetch('version') do
|
10
|
-
|
11
|
-
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
12
|
-
|
13
|
-
require 'tdiff/version'
|
10
|
+
require_relative 'lib/tdiff/version'
|
14
11
|
TDiff::VERSION
|
15
12
|
end
|
16
13
|
|
metadata
CHANGED
@@ -1,64 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.4.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Postmodern
|
9
|
-
autorequire:
|
8
|
+
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
14
|
+
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '0
|
19
|
+
version: '2.0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '0
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rspec
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '2.4'
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '2.4'
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: yard
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: '0.7'
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.7'
|
26
|
+
version: '2.0'
|
62
27
|
description: Calculates the differences between two tree-like structures. Similar
|
63
28
|
to Rubys built-in TSort module.
|
64
29
|
email: postmodern.mod3@gmail.com
|
@@ -69,12 +34,14 @@ extra_rdoc_files:
|
|
69
34
|
- LICENSE.txt
|
70
35
|
- README.md
|
71
36
|
files:
|
72
|
-
- .document
|
73
|
-
- .gemtest
|
74
|
-
- .
|
75
|
-
- .
|
76
|
-
- .
|
37
|
+
- ".document"
|
38
|
+
- ".gemtest"
|
39
|
+
- ".github/workflows/ruby.yml"
|
40
|
+
- ".gitignore"
|
41
|
+
- ".rspec"
|
42
|
+
- ".yardopts"
|
77
43
|
- ChangeLog.md
|
44
|
+
- Gemfile
|
78
45
|
- LICENSE.txt
|
79
46
|
- README.md
|
80
47
|
- Rakefile
|
@@ -93,26 +60,24 @@ files:
|
|
93
60
|
homepage: https://github.com/postmodern/tdiff#readme
|
94
61
|
licenses:
|
95
62
|
- MIT
|
96
|
-
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
97
65
|
rdoc_options: []
|
98
66
|
require_paths:
|
99
67
|
- lib
|
100
68
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
69
|
requirements:
|
103
|
-
- -
|
70
|
+
- - ">="
|
104
71
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
72
|
+
version: 2.0.0
|
106
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
74
|
requirements:
|
109
|
-
- -
|
75
|
+
- - ">="
|
110
76
|
- !ruby/object:Gem::Version
|
111
77
|
version: '0'
|
112
78
|
requirements: []
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
specification_version: 3
|
79
|
+
rubygems_version: 3.4.10
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
117
82
|
summary: Calculates the differences between two tree-like structures.
|
118
83
|
test_files: []
|