unified_diff 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/unified_diff/chunk.rb +12 -0
- data/lib/unified_diff/diff.rb +16 -1
- data/test/test_chunk.rb +9 -0
- data/test/test_unified_diff.rb +21 -4
- data/unified_diff.gemspec +5 -5
- metadata +6 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/unified_diff/chunk.rb
CHANGED
@@ -13,6 +13,18 @@ module UnifiedDiff
|
|
13
13
|
end
|
14
14
|
|
15
15
|
|
16
|
+
# Render the chunk as it appeared in the original unified diff
|
17
|
+
#
|
18
|
+
# @return [String] the chunk as it appeared in the original unified diff
|
19
|
+
def to_s
|
20
|
+
"@@ "+
|
21
|
+
"-#{@original_range.begin},#{@original_range.count} " +
|
22
|
+
"+#{@modified_range.begin},#{@modified_range.count} " +
|
23
|
+
"@@\n" +
|
24
|
+
@raw_lines.join("\n") +
|
25
|
+
"\n"
|
26
|
+
end
|
27
|
+
|
16
28
|
# Return an array of lines that were removed from the original version of the chunk
|
17
29
|
#
|
18
30
|
# @return [Array] the lines that were removed from the original
|
data/lib/unified_diff/diff.rb
CHANGED
@@ -12,11 +12,22 @@ module UnifiedDiff
|
|
12
12
|
REMOVED_PATTERN = /-(.*)/
|
13
13
|
UNCHANGED_PATTERN = / (.*)/
|
14
14
|
|
15
|
+
# Create and parse a unified diff
|
16
|
+
#
|
17
|
+
# @param [String] a string containing a unified diff
|
18
|
+
# @return [Diff] the parsed diff
|
15
19
|
def initialize(diff)
|
16
20
|
@original = diff
|
17
21
|
parse
|
18
22
|
end
|
19
23
|
|
24
|
+
# Render the diff as it appeared originally
|
25
|
+
#
|
26
|
+
# @return [String] the original unified diff
|
27
|
+
def to_s
|
28
|
+
@original
|
29
|
+
end
|
30
|
+
|
20
31
|
private
|
21
32
|
|
22
33
|
def parse
|
@@ -28,7 +39,11 @@ module UnifiedDiff
|
|
28
39
|
when NEW_FILE_PATTERN
|
29
40
|
@modified_file, @modified_timestamp = $1, Time.parse($2)
|
30
41
|
when CHUNK_PATTERN
|
31
|
-
|
42
|
+
old_begin = $1.to_i
|
43
|
+
old_end = old_begin + $2.to_i
|
44
|
+
new_begin = $3.to_i
|
45
|
+
new_end = new_begin + $4.to_i
|
46
|
+
@working_chunk = Chunk.new(original: (old_begin...old_end), modified: (new_begin...new_end))
|
32
47
|
@chunks << @working_chunk
|
33
48
|
when ADDED_PATTERN
|
34
49
|
@working_chunk.send(:insert_addition, $1)
|
data/test/test_chunk.rb
CHANGED
@@ -42,4 +42,13 @@ class TestChunk < MiniTest::Unit::TestCase
|
|
42
42
|
@chunk.send(:insert_unchanged, 'bar')
|
43
43
|
assert_equal ['foo'], @chunk.added_lines
|
44
44
|
end
|
45
|
+
|
46
|
+
def test_to_s
|
47
|
+
@chunk.send(:insert_addition,'foo')
|
48
|
+
to_s = <<-TO_S.unindent
|
49
|
+
@@ -1,2 +1,3 @@
|
50
|
+
+foo
|
51
|
+
TO_S
|
52
|
+
assert_equal to_s, @chunk.to_s
|
53
|
+
end
|
45
54
|
end
|
data/test/test_unified_diff.rb
CHANGED
@@ -2,7 +2,7 @@ require 'helper'
|
|
2
2
|
|
3
3
|
class TestUnifiedDiff < MiniTest::Unit::TestCase
|
4
4
|
def setup
|
5
|
-
|
5
|
+
@original = <<-DIFF.unindent
|
6
6
|
--- original.txt 2011-05-31 11:14:13.000000000 -0500
|
7
7
|
+++ modified.txt 2011-05-31 11:14:44.000000000 -0500
|
8
8
|
@@ -1,5 +1,5 @@
|
@@ -13,7 +13,7 @@ class TestUnifiedDiff < MiniTest::Unit::TestCase
|
|
13
13
|
qux
|
14
14
|
quux
|
15
15
|
DIFF
|
16
|
-
@diff = UnifiedDiff.parse(
|
16
|
+
@diff = UnifiedDiff.parse(@original)
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_setup_method_does_something
|
@@ -32,8 +32,21 @@ class TestUnifiedDiff < MiniTest::Unit::TestCase
|
|
32
32
|
|
33
33
|
def test_parses_chunk_header
|
34
34
|
@chunk = @diff.chunks.first
|
35
|
-
assert_equal (1
|
36
|
-
assert_equal (1
|
35
|
+
assert_equal (1...6), @chunk.original_range
|
36
|
+
assert_equal (1...6), @chunk.modified_range
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parses_chunk_header_length_properly
|
40
|
+
diff = <<-DIFF.unindent
|
41
|
+
--- original.txt 2011-05-31 11:14:13.000000000 -0500
|
42
|
+
+++ modified.txt 2011-05-31 11:14:44.000000000 -0500
|
43
|
+
@@ -2,5 +3,5 @@
|
44
|
+
foo
|
45
|
+
DIFF
|
46
|
+
@diff = UnifiedDiff.parse(diff)
|
47
|
+
@chunk = @diff.chunks.first
|
48
|
+
assert_equal (2...7), @chunk.original_range
|
49
|
+
assert_equal (3...8), @chunk.modified_range
|
37
50
|
end
|
38
51
|
|
39
52
|
def test_parses_unchanged_line
|
@@ -76,4 +89,8 @@ class TestUnifiedDiff < MiniTest::Unit::TestCase
|
|
76
89
|
@diff = UnifiedDiff.parse(diff)
|
77
90
|
assert_equal 2, @diff.chunks.length
|
78
91
|
end
|
92
|
+
|
93
|
+
def test_to_s
|
94
|
+
assert_equal @original, @diff.to_s
|
95
|
+
end
|
79
96
|
end
|
data/unified_diff.gemspec
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{unified_diff}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.authors = [
|
11
|
+
s.authors = ["Ryan Neufeld"]
|
12
12
|
s.date = %q{2011-06-01}
|
13
13
|
s.description = %q{unified_diff parses unified diff contents into easy-to-use Ruby objects}
|
14
14
|
s.email = %q{ryan@ryanneufeld.ca}
|
@@ -33,9 +33,9 @@ Gem::Specification.new do |s|
|
|
33
33
|
"unified_diff.gemspec"
|
34
34
|
]
|
35
35
|
s.homepage = %q{http://github.com/rkneufeld/unified_diff}
|
36
|
-
s.licenses = [
|
37
|
-
s.require_paths = [
|
38
|
-
s.rubygems_version = %q{1.
|
36
|
+
s.licenses = ["MIT"]
|
37
|
+
s.require_paths = ["lib"]
|
38
|
+
s.rubygems_version = %q{1.6.2}
|
39
39
|
s.summary = %q{Parse unified diffs in style}
|
40
40
|
|
41
41
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: unified_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Ryan Neufeld
|
@@ -10,7 +10,8 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-06-01 00:00:00
|
13
|
+
date: 2011-06-01 00:00:00 -05:00
|
14
|
+
default_executable:
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: minitest
|
@@ -80,6 +81,7 @@ files:
|
|
80
81
|
- test/test_chunk.rb
|
81
82
|
- test/test_unified_diff.rb
|
82
83
|
- unified_diff.gemspec
|
84
|
+
has_rdoc: true
|
83
85
|
homepage: http://github.com/rkneufeld/unified_diff
|
84
86
|
licenses:
|
85
87
|
- MIT
|
@@ -93,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
93
95
|
requirements:
|
94
96
|
- - ">="
|
95
97
|
- !ruby/object:Gem::Version
|
96
|
-
hash:
|
98
|
+
hash: -1003861306608030008
|
97
99
|
segments:
|
98
100
|
- 0
|
99
101
|
version: "0"
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
requirements: []
|
107
109
|
|
108
110
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.
|
111
|
+
rubygems_version: 1.6.2
|
110
112
|
signing_key:
|
111
113
|
specification_version: 3
|
112
114
|
summary: Parse unified diffs in style
|