dirb 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ This project has been renamed to diffy.
2
+
3
+ See https://github.com/samg/diffy.
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dirb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 2
8
8
  - 0
9
- - 0
10
- version: 2.0.0
9
+ - 1
10
+ version: 2.0.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sam Goldstein
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-20 00:00:00 -08:00
18
+ date: 2010-12-07 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -26,26 +26,24 @@ executables: []
26
26
  extensions: []
27
27
 
28
28
  extra_rdoc_files:
29
- - LICENSE
30
- - README.md
29
+ - README
31
30
  files:
32
- - .gitignore
33
- - CHANGELOG
34
- - LICENSE
35
- - README.md
36
- - Rakefile
37
- - VERSION
38
- - dirb.gemspec
39
- - lib/dirb.rb
40
- - lib/dirb/diff.rb
41
- - lib/dirb/format.rb
42
- - lib/dirb/html_formatter.rb
43
- - spec/dirb_spec.rb
31
+ - README
44
32
  has_rdoc: true
45
- homepage: http://github.com/samg/dirb/tree/master
33
+ homepage: http://github.com/samg/diffy/tree/master
46
34
  licenses: []
47
35
 
48
- post_install_message:
36
+ post_install_message: |
37
+ ######################################################
38
+
39
+ Hello! The dirb gem has changed it's name to just diffy. Rather than
40
+ installing `dirb`, you should install `diffy`. Please update your
41
+ dependencies accordingly.
42
+
43
+ Thanks!
44
+
45
+ #######################################################
46
+
49
47
  rdoc_options:
50
48
  - --inline-source
51
49
  - --charset=UTF-8
@@ -75,6 +73,6 @@ rubyforge_project:
75
73
  rubygems_version: 1.3.7
76
74
  signing_key:
77
75
  specification_version: 3
78
- summary: A convenient way to diff string in ruby
79
- test_files:
80
- - spec/dirb_spec.rb
76
+ summary: Renamed to diffy
77
+ test_files: []
78
+
data/.gitignore DELETED
@@ -1,2 +0,0 @@
1
- *.gem
2
- *.swp
data/CHANGELOG DELETED
@@ -1,5 +0,0 @@
1
- == 1.0.1 ==
2
- * Compatibility with ruby 1.8.6 and 1.9
3
-
4
- == 1.0.0 ==
5
- * HTML output and better documentation
data/LICENSE DELETED
@@ -1,19 +0,0 @@
1
- Copyright (c) 2010 Sam Goldstein
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of
4
- this software and associated documentation files (the "Software"), to deal in
5
- the Software without restriction, including without limitation the rights to
6
- use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
- of the Software, and to permit persons to whom the Software is furnished to do
8
- so, subject to the following conditions:
9
-
10
- The above copyright notice and this permission notice shall be included in all
11
- copies or substantial portions of the Software.
12
-
13
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
- SOFTWARE.
data/README.md DELETED
@@ -1,121 +0,0 @@
1
- Dirb - Easy Diffing With Ruby
2
- ============================
3
-
4
- Need diffs in your ruby app? Dirb has you covered. It provides a convenient
5
- way to generate a diff from two strings. Instead of reimplementing the LCS diff
6
- algorithm Dirb uses battle tested Unix diff to generate diffs, and focuses on
7
- providing a convenient interface, and getting out of your way.
8
-
9
- Supported Formats
10
- -----------------
11
-
12
- It provides several built in format options which can be passed to
13
- `Dirb::Diff#to_s`.
14
-
15
- * `:text` - Plain text output
16
- * `:color` - ANSI colorized text suitable for use in a terminal
17
- * `:html` - HTML output. Since version 2.0 this format does inline
18
- highlighting of the changes between two the changes within
19
- lines.
20
- * `:html_simple` - HTML output without inline highlighting. This may be
21
- useful in situations where high performance is required or
22
- simpler output is desired.
23
-
24
- A default format can be set like so:
25
-
26
- `Dirb::Diff.default_format = :html`
27
-
28
- Getting Started
29
- ---------------
30
-
31
- sudo gem install dirb
32
-
33
- Here's an example of using Dirb to diff two strings
34
-
35
- $ irb
36
- >> string1 = <<-TXT
37
- >" Hello how are you
38
- >" I'm fine
39
- >" That's great
40
- >" TXT
41
- => "Hello how are you\nI'm fine\nThat's great\n"
42
- >> string2 = <<-TXT
43
- >" Hello how are you?
44
- >" I'm fine
45
- >" That's swell
46
- >" TXT
47
- => "Hello how are you?\nI'm fine\nThat's swell\n"
48
- >> puts Dirb::Diff.new(string1, string2)
49
- -Hello how are you
50
- +Hello how are you?
51
- I'm fine
52
- -That's great
53
- +That's swell
54
-
55
- Outputing the diff as html is easy too.
56
-
57
- >> puts Dirb::Diff.new(string1, string2).to_s(:html_simple)
58
- <div class="diff">
59
- <ul>
60
- <li class="del"><del>Hello how are you</del></li>
61
- <li class="ins"><ins>Hello how are you?</ins></li>
62
- <li class="unchanged"><span>I'm fine</span></li>
63
- <li class="del"><del>That's great</del></li>
64
- <li class="ins"><ins>That's swell</ins></li>
65
- </ul>
66
- </div>
67
-
68
- Then try adding this css to your stylesheets:
69
-
70
- .diff{overflow:auto;}
71
- .diff ul{background:#fff;overflow:auto;font-size:13px;list-style:none;margin:0;padding:0;display:table;width:100%;}
72
- .diff del, .diff ins{display:block;text-decoration:none;}
73
- .diff li{padding:0; display:table-row;margin: 0;}
74
- .diff del, .diff ins, .diff span{white-space:pre;font-family:courier;}
75
- .diff li.ins{background:#9f9;}
76
- .diff li.del{background:#fcc;}
77
- .diff li.ins strong{font-weight:normal; background: #6f6 }
78
- .diff li.del strong{font-weight:normal; background: #f99 }
79
-
80
- You can also diff files instead of strings
81
-
82
- >> puts Dirb::Diff.new('/tmp/foo', '/tmp/bar', :source => 'files')
83
-
84
- Custom Formats
85
- --------------
86
-
87
- Dirb tries to make generating your own custom formatted output easy.
88
- `Dirb::Diff` provides an enumberable interface which lets you iterate over
89
- lines in the diff.
90
-
91
- >> Dirb::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each do |line|
92
- >* case line
93
- >> when /^\+/ then puts "line #{line.chomp} added"
94
- >> when /^-/ then puts "line #{line.chomp} removed"
95
- >> end
96
- >> end
97
- line +baz added
98
- => [" foo\n", " bar\n", "+baz\n"]
99
-
100
- You can also use `Dirb::Diff#each_chunk` to iterate each grouping of additions,
101
- deletions, and unchanged in a diff.
102
-
103
- >> Dirb::Diff.new("foo\nbar\nbang\nbaz\n", "foo\nbar\nbing\nbong\n").each_chunk.to_a
104
- => [" foo\n bar\n", "-bang\n-baz\n", "+bing\n+bong\n"]
105
-
106
- Use `#map`, `#inject`, or any of Enumerable's methods. Go crazy.
107
-
108
- Ruby Version Compatibility
109
- -------------------------
110
-
111
- Support for Ruby 1.8.6 was dropped beggining at version 2.0 in order to support
112
- the chainable enumerators available in 1.8.7 and 1.9.
113
-
114
- If you want to use Dirb and Ruby 1.8.6 then:
115
-
116
- $ gem install dirb -v1.1.0
117
-
118
- ---------------------------------------------------------------------
119
-
120
- Report bugs or request features at http://github.com/samg/Dirb/issues
121
-
data/Rakefile DELETED
@@ -1,39 +0,0 @@
1
- require 'spec/rake/spectask'
2
- require 'rake/rdoctask'
3
- require 'rake/gempackagetask'
4
-
5
- task :default => :spec
6
-
7
- desc "Run all specs in spec directory"
8
- Spec::Rake::SpecTask.new(:spec) do |t|
9
- t.spec_files = FileList['spec/**/*_spec.rb']
10
- t.spec_opts = %w{--color --format profile}
11
- end
12
-
13
- Rake::RDocTask.new do |rd|
14
- rd.main = "README"
15
- rd.rdoc_dir = 'doc'
16
- rd.rdoc_files.include("README", "**/*.rb")
17
- end
18
-
19
- begin
20
- require 'jeweler'
21
- Jeweler::Tasks.new do |s|
22
- s.name = %q{dirb}
23
-
24
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
25
- s.authors = ["Sam Goldstein"]
26
- s.date = %q{2010-06-28}
27
- s.description = %q{Convenient diffing in ruby}
28
- s.email = %q{sgrock@gmail.com}
29
- s.has_rdoc = true
30
- s.homepage = "http://github.com/samg/dirb/tree/master"
31
- s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
32
- s.require_paths = ["lib"]
33
- s.summary = %q{A convenient way to diff string in ruby}
34
-
35
- end
36
- rescue LoadError
37
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
38
- end
39
-
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 2.0.0
data/dirb.gemspec DELETED
@@ -1,52 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{dirb}
8
- s.version = "2.0.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Sam Goldstein"]
12
- s.date = %q{2010-11-20}
13
- s.description = %q{Convenient diffing in ruby}
14
- s.email = %q{sgrock@gmail.com}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.md"
18
- ]
19
- s.files = [
20
- ".gitignore",
21
- "CHANGELOG",
22
- "LICENSE",
23
- "README.md",
24
- "Rakefile",
25
- "VERSION",
26
- "dirb.gemspec",
27
- "lib/dirb.rb",
28
- "lib/dirb/diff.rb",
29
- "lib/dirb/format.rb",
30
- "lib/dirb/html_formatter.rb",
31
- "spec/dirb_spec.rb"
32
- ]
33
- s.homepage = %q{http://github.com/samg/dirb/tree/master}
34
- s.rdoc_options = ["--inline-source", "--charset=UTF-8"]
35
- s.require_paths = ["lib"]
36
- s.rubygems_version = %q{1.3.7}
37
- s.summary = %q{A convenient way to diff string in ruby}
38
- s.test_files = [
39
- "spec/dirb_spec.rb"
40
- ]
41
-
42
- if s.respond_to? :specification_version then
43
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
44
- s.specification_version = 3
45
-
46
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- else
48
- end
49
- else
50
- end
51
- end
52
-
data/lib/dirb.rb DELETED
@@ -1,12 +0,0 @@
1
- require 'tempfile'
2
- require 'open3'
3
- require 'erb'
4
- # 1.9 compatibility
5
- if defined? Enumerator and ! defined? Enumerable::Enumerator
6
- Enumerable::Enumerator = Enumerator
7
- end
8
-
9
- module Dirb; end
10
- require File.join(File.dirname(__FILE__), 'dirb', 'format')
11
- require File.join(File.dirname(__FILE__), 'dirb', 'html_formatter')
12
- require File.join(File.dirname(__FILE__), 'dirb', 'diff')
data/lib/dirb/diff.rb DELETED
@@ -1,105 +0,0 @@
1
- module Dirb
2
- class Diff
3
- class << self
4
- attr_writer :default_format
5
- def default_format
6
- @default_format || :text
7
- end
8
- end
9
- include Enumerable
10
- attr_reader :string1, :string2, :options, :diff
11
-
12
- # supported options
13
- # +:diff+:: A cli options string passed to diff
14
- # +:source+:: Either _strings_ or _files_. Determines whether string1
15
- # and string2 should be interpreted as strings or file paths.
16
- def initialize(string1, string2, options = {})
17
- @options = {:diff => '-U 10000', :source => 'strings'}.merge(options)
18
- if ! ['strings', 'files'].include?(@options[:source])
19
- raise ArgumentError, "Invalid :source option #{@options[:source].inspect}. Supported options are 'strings' and 'files'."
20
- end
21
- @string1, @string2 = string1, string2
22
- end
23
-
24
- def diff
25
- @diff ||= begin
26
- paths = case options[:source]
27
- when 'strings'
28
- [tempfile(string1), tempfile(string2)]
29
- when 'files'
30
- [string1, string2]
31
- end
32
- diff ||= Open3.popen3(
33
- *[ diff_bin, options[:diff], *paths ]
34
- ) { |i, o, e| o.read }
35
- if diff =~ /\A\s*\Z/
36
- diff = case options[:source]
37
- when 'strings' then string1
38
- when 'files' then File.read(string1)
39
- end.gsub(/^/, " ")
40
- end
41
- diff
42
- end
43
- end
44
-
45
- def each
46
- lines = diff.split("\n").reject{|x| x =~ /^---|\+\+\+|@@|\\\\/ }.
47
- map{|line| line + "\n"}
48
- if block_given?
49
- lines.each{|line| yield line}
50
- else
51
- Enumerable::Enumerator.new(lines)
52
- end
53
- end
54
-
55
- def each_chunk
56
- old_state = nil
57
- chunks = inject([]) do |cc, line|
58
- state = line.each_char.first
59
- if state == old_state
60
- cc.last << line
61
- else
62
- cc.push line.dup
63
- end
64
- old_state = state
65
- cc
66
- end
67
-
68
- if block_given?
69
- chunks.each{|chunk| yield chunk }
70
- else
71
- Enumerable::Enumerator.new(chunks)
72
- end
73
- end
74
-
75
- def tempfile(string)
76
- t = Tempfile.new('dirb')
77
- t.print(string)
78
- t.flush
79
- t.path
80
- end
81
-
82
- def to_s(format = nil)
83
- format ||= self.class.default_format
84
- formats = Format.instance_methods(false).map{|x| x.to_s}
85
- if formats.include? format.to_s
86
- enum = self
87
- enum.extend Format
88
- enum.send format
89
- else
90
- raise ArgumentError,
91
- "Format #{format.inspect} not found in #{formats.inspect}"
92
- end
93
- end
94
- private
95
-
96
- def diff_bin
97
- bin = `which diff`.chomp
98
- if bin.empty?
99
- raise "Can't find a diff executable in PATH #{ENV['PATH']}"
100
- end
101
- bin
102
- end
103
-
104
- end
105
- end
data/lib/dirb/format.rb DELETED
@@ -1,33 +0,0 @@
1
- module Dirb
2
- module Format
3
- # ANSI color output suitable for terminal output
4
- def color
5
- map do |line|
6
- case line
7
- when /^\+/
8
- "\033[32m#{line.chomp}\033[0m"
9
- when /^-/
10
- "\033[31m#{line.chomp}\033[0m"
11
- else
12
- line.chomp
13
- end
14
- end.join("\n") + "\n"
15
- end
16
-
17
- # Basic text output
18
- def text
19
- to_a.join
20
- end
21
-
22
- # Basic html output which does not attempt to highlight the changes
23
- # between lines, and is more performant.
24
- def html_simple
25
- HtmlFormatter.new(self).to_s
26
- end
27
-
28
- # Html output which does inline highlighting of changes between two lines.
29
- def html
30
- HtmlFormatter.new(self, :highlight_words => true).to_s
31
- end
32
- end
33
- end
@@ -1,90 +0,0 @@
1
- module Dirb
2
- class HtmlFormatter
3
- def initialize(diff, options = {})
4
- @diff = diff
5
- @options = options
6
- end
7
-
8
- def to_s
9
- if @options[:highlight_words]
10
- wrap_lines(highlighted_words)
11
- else
12
- wrap_lines(@diff.map{|line| wrap_line(ERB::Util.h(line))})
13
- end
14
- end
15
-
16
- private
17
- def wrap_line(line)
18
- cleaned = line.gsub(/^./, '').chomp
19
- case line
20
- when /^\+/
21
- ' <li class="ins"><ins>' + cleaned + '</ins></li>'
22
- when /^-/
23
- ' <li class="del"><del>' + cleaned + '</del></li>'
24
- when /^ /
25
- ' <li class="unchanged"><span>' + cleaned + '</span></li>'
26
- end
27
- end
28
-
29
- def wrap_lines(lines)
30
- %'<div class="diff">\n <ul>\n#{lines.join("\n")}\n </ul>\n</div>\n'
31
- end
32
-
33
- def highlighted_words
34
- chunks = @diff.each_chunk.to_a
35
- processed = []
36
- lines = chunks.each_with_index.map do |chunk1, index|
37
- next if processed.include? index
38
- processed << index
39
- chunk1 = chunk1
40
- chunk2 = chunks[index + 1]
41
- if not chunk2
42
- next chunk1
43
- end
44
-
45
- chunk1 = ERB::Util.h(chunk1)
46
- chunk2 = ERB::Util.h(chunk2)
47
-
48
- dir1 = chunk1.each_char.first
49
- dir2 = chunk2.each_char.first
50
- case [dir1, dir2]
51
- when ['-', '+']
52
- line_diff = Dirb::Diff.new(
53
- split_characters(chunk1),
54
- split_characters(chunk2)
55
- )
56
- hi1 = reconstruct_characters(line_diff, '-')
57
- hi2 = reconstruct_characters(line_diff, '+')
58
- processed << (index + 1)
59
- [hi1, hi2]
60
- else
61
- chunk1
62
- end
63
- end.flatten
64
- lines.map{|line| line.each_line.map(&:chomp).to_a if line }.flatten.compact.
65
- map{|line|wrap_line(line) }.compact
66
- end
67
-
68
- def split_characters(chunk)
69
- chunk.gsub(/^./, '').each_line.map do |line|
70
- line.chomp.split('') + ['\n']
71
- end.flatten.join("\n")
72
- end
73
-
74
- def reconstruct_characters(line_diff, type)
75
- line_diff.each_chunk.map do |l|
76
- re = /(^|\\n)#{Regexp.escape(type)}/
77
- case l
78
- when re
79
- "<strong>" + l.gsub(re, '').gsub("\n", '').
80
- gsub('\n', "</strong>\n<strong>") + "</strong>"
81
- when /^ /
82
- l.gsub(/^./, '').gsub("\n", '').
83
- gsub('\r', "\r").gsub('\n', "\n")
84
- end
85
- end.join('').split("\n").map do |l|
86
- type + l
87
- end
88
- end
89
- end
90
- end
data/spec/dirb_spec.rb DELETED
@@ -1,277 +0,0 @@
1
- require 'spec'
2
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'dirb'))
3
-
4
- describe Dirb::Diff do
5
-
6
- describe "diffing two files" do
7
- def tempfile(string)
8
- t = Tempfile.new('dirb-spec')
9
- t.print(string)
10
- t.flush
11
- t.path
12
- end
13
-
14
- it "should accept file paths as arguments" do
15
- string1 = "foo\nbar\nbang\n"
16
- string2 = "foo\nbang\n"
17
- path1, path2 = tempfile(string1), tempfile(string2)
18
- Dirb::Diff.new(path1, path2, :source => 'files').to_s.should == <<-DIFF
19
- foo
20
- -bar
21
- bang
22
- DIFF
23
- end
24
-
25
- describe "with no line different" do
26
- before do
27
- string1 = "foo\nbar\nbang\n"
28
- string2 = "foo\nbar\nbang\n"
29
- @path1, @path2 = tempfile(string1), tempfile(string2)
30
- end
31
-
32
- it "should show everything" do
33
- Dirb::Diff.new(@path1, @path2, :source => 'files').to_s.should == <<-DIFF
34
- foo
35
- bar
36
- bang
37
- DIFF
38
- end
39
- end
40
- end
41
-
42
- describe "#to_s" do
43
- describe "with no line different" do
44
- before do
45
- @string1 = "foo\nbar\nbang\n"
46
- @string2 = "foo\nbar\nbang\n"
47
- end
48
-
49
- it "should show everything" do
50
- Dirb::Diff.new(@string1, @string2).to_s.should == <<-DIFF
51
- foo
52
- bar
53
- bang
54
- DIFF
55
- end
56
- end
57
- describe "with one line different" do
58
- before do
59
- @string1 = "foo\nbar\nbang\n"
60
- @string2 = "foo\nbang\n"
61
- end
62
-
63
- it "should show one line removed" do
64
- Dirb::Diff.new(@string1, @string2).to_s.should == <<-DIFF
65
- foo
66
- -bar
67
- bang
68
- DIFF
69
- end
70
-
71
- it "to_s should accept a format key" do
72
- Dirb::Diff.new(@string1, @string2).to_s(:color).
73
- should == " foo\n\e[31m-bar\e[0m\n bang\n"
74
- end
75
-
76
- it "should accept a default format option" do
77
- old_format = Dirb::Diff.default_format
78
- Dirb::Diff.default_format = :color
79
- Dirb::Diff.new(@string1, @string2).to_s.
80
- should == " foo\n\e[31m-bar\e[0m\n bang\n"
81
- Dirb::Diff.default_format = old_format
82
- end
83
-
84
- it "should show one line added" do
85
- Dirb::Diff.new(@string2, @string1).to_s.should == <<-DIFF
86
- foo
87
- +bar
88
- bang
89
- DIFF
90
- end
91
- end
92
-
93
- describe "with one line changed" do
94
- before do
95
- @string1 = "foo\nbar\nbang\n"
96
- @string2 = "foo\nbong\nbang\n"
97
- end
98
- it "should show one line added and one removed" do
99
- Dirb::Diff.new(@string1, @string2).to_s.should == <<-DIFF
100
- foo
101
- -bar
102
- +bong
103
- bang
104
- DIFF
105
- end
106
- end
107
-
108
- describe "with totally different strings" do
109
- before do
110
- @string1 = "foo\nbar\nbang\n"
111
- @string2 = "one\ntwo\nthree\n"
112
- end
113
- it "should show one line added and one removed" do
114
- Dirb::Diff.new(@string1, @string2).to_s.should == <<-DIFF
115
- -foo
116
- -bar
117
- -bang
118
- +one
119
- +two
120
- +three
121
- DIFF
122
- end
123
- end
124
-
125
- describe "with a somewhat complicated diff" do
126
- before do
127
- @string1 = "foo\nbar\nbang\nwoot\n"
128
- @string2 = "one\ntwo\nthree\nbar\nbang\nbaz\n"
129
- @diff = Dirb::Diff.new(@string1, @string2)
130
- end
131
- it "should show one line added and one removed" do
132
- @diff.to_s.should == <<-DIFF
133
- -foo
134
- +one
135
- +two
136
- +three
137
- bar
138
- bang
139
- -woot
140
- +baz
141
- DIFF
142
- end
143
-
144
- it "should make an awesome simple html diff" do
145
- @diff.to_s(:html_simple).should == <<-HTML
146
- <div class="diff">
147
- <ul>
148
- <li class="del"><del>foo</del></li>
149
- <li class="ins"><ins>one</ins></li>
150
- <li class="ins"><ins>two</ins></li>
151
- <li class="ins"><ins>three</ins></li>
152
- <li class="unchanged"><span>bar</span></li>
153
- <li class="unchanged"><span>bang</span></li>
154
- <li class="del"><del>woot</del></li>
155
- <li class="ins"><ins>baz</ins></li>
156
- </ul>
157
- </div>
158
- HTML
159
- end
160
-
161
- it "should accept overrides to diff's options" do
162
- @diff = Dirb::Diff.new(@string1, @string2, :diff => "--rcs")
163
- @diff.to_s.should == <<-DIFF
164
- d1 1
165
- a1 3
166
- one
167
- two
168
- three
169
- d4 1
170
- a4 1
171
- baz
172
- DIFF
173
- end
174
- end
175
-
176
- describe "html" do
177
-
178
- it "should highlight the changes within the line" do
179
- @string1 = "hahaha\ntime flies like an arrow\nfoo bar\nbang baz\n"
180
- @string2 = "hahaha\nfruit flies like a banana\nbang baz\n"
181
- @diff = Dirb::Diff.new(@string1, @string2)
182
- html = <<-HTML
183
- <div class="diff">
184
- <ul>
185
- <li class="unchanged"><span>hahaha</span></li>
186
- <li class="del"><del><strong>t</strong>i<strong>me</strong> flies like a<strong>n arrow</strong></del></li>
187
- <li class="del"><del><strong>foo</strong> ba<strong>r</strong></del></li>
188
- <li class="ins"><ins><strong>fru</strong>i<strong>t</strong> flies like a ba<strong>nana</strong></ins></li>
189
- <li class="unchanged"><span>bang baz</span></li>
190
- </ul>
191
- </div>
192
- HTML
193
- @diff.to_s(:html).should == html
194
- end
195
-
196
- it "should not duplicate some lines" do
197
- @string1 = "hahaha\ntime flies like an arrow\n"
198
- @string2 = "hahaha\nfruit flies like a banana\nbang baz"
199
- @diff = Dirb::Diff.new(@string1, @string2)
200
- html = <<-HTML
201
- <div class="diff">
202
- <ul>
203
- <li class="unchanged"><span>hahaha</span></li>
204
- <li class="del"><del><strong>t</strong>i<strong>me</strong> flies like an a<strong>rrow</strong></del></li>
205
- <li class="ins"><ins><strong>fru</strong>i<strong>t</strong> flies like a<strong> ba</strong>n<strong>ana</strong></ins></li>
206
- <li class="ins"><ins><strong>bang</strong> <strong>b</strong>a<strong>z</strong></ins></li>
207
- </ul>
208
- </div>
209
- HTML
210
- @diff.to_s(:html).should == html
211
- end
212
-
213
- it "should escape html" do
214
- @string1 = "ha<br>haha\ntime flies like an arrow\n"
215
- @string2 = "ha<br>haha\nfruit flies like a banana\nbang baz"
216
- @diff = Dirb::Diff.new(@string1, @string2)
217
- html = <<-HTML
218
- <div class="diff">
219
- <ul>
220
- <li class="unchanged"><span>ha&lt;br&gt;haha</span></li>
221
- <li class="del"><del><strong>t</strong>i<strong>me</strong> flies like an a<strong>rrow</strong></del></li>
222
- <li class="ins"><ins><strong>fru</strong>i<strong>t</strong> flies like a<strong> ba</strong>n<strong>ana</strong></ins></li>
223
- <li class="ins"><ins><strong>bang</strong> <strong>b</strong>a<strong>z</strong></ins></li>
224
- </ul>
225
- </div>
226
- HTML
227
- @diff.to_s(:html).should == html
228
- end
229
-
230
- it "should highlight the changes within the line with windows style line breaks" do
231
- @string1 = "hahaha\r\ntime flies like an arrow\r\nfoo bar\r\nbang baz\n"
232
- @string2 = "hahaha\r\nfruit flies like a banana\r\nbang baz\n"
233
- @diff = Dirb::Diff.new(@string1, @string2)
234
- html = <<-HTML
235
- <div class="diff">
236
- <ul>
237
- <li class="unchanged"><span>hahaha</span></li>
238
- <li class="del"><del><strong>t</strong>i<strong>me</strong> flies like a<strong>n arrow</strong></del></li>
239
- <li class="del"><del><strong>foo</strong> ba<strong>r</strong></del></li>
240
- <li class="ins"><ins><strong>fru</strong>i<strong>t</strong> flies like a ba<strong>nana</strong></ins></li>
241
- <li class="unchanged"><span>bang baz</span></li>
242
- </ul>
243
- </div>
244
- HTML
245
- @diff.to_s(:html).should == html
246
- end
247
- end
248
-
249
- it "should escape diffed html in html output" do
250
- diff = Dirb::Diff.new("<script>alert('bar')</script>", "<script>alert('foo')</script>").to_s(:html)
251
- diff.should include('&lt;script&gt;')
252
- diff.should_not include('<script>')
253
- end
254
-
255
- it "should be easy to generate custom format" do
256
- Dirb::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").map do |line|
257
- case line
258
- when /^\+/ then "line #{line.chomp} added"
259
- when /^-/ then "line #{line.chomp} removed"
260
- end
261
- end.compact.join.should == "line +baz added"
262
- end
263
-
264
- it "should let you iterate over chunks instead of lines" do
265
- Dirb::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each_chunk.map do |chunk|
266
- chunk
267
- end.should == [" foo\n bar\n", "+baz\n"]
268
- end
269
-
270
- it "should allow chaining enumerable methods" do
271
- Dirb::Diff.new("foo\nbar\n", "foo\nbar\nbaz\n").each.map do |line|
272
- line
273
- end.should == [" foo\n", " bar\n", "+baz\n"]
274
- end
275
- end
276
- end
277
-