Sha256: a9ae9ea7ee482797bb32ebf51085d83a97f7b99ec2ef054f06347be3474a2559

Contents?: true

Size: 1.93 KB

Versions: 212

Compression:

Stored size: 1.93 KB

Contents

# -*- ruby encoding: utf-8 -*-

require 'spec_helper'

if String.method_defined?(:encoding)
  require 'diff/lcs/hunk'

  describe Diff::LCS::Hunk do
    let(:old_data) { ["Tu avec carté {count} itém has".encode('UTF-16LE')] }
    let(:new_data) { ["Tu avec carte {count} item has".encode('UTF-16LE')] }
    let(:pieces)   { Diff::LCS.diff old_data, new_data }
    let(:hunk)     { Diff::LCS::Hunk.new(old_data, new_data, pieces[0], 3, 0) }

    it 'produces a unified diff from the two pieces' do
      expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
        @@ -1,2 +1,2 @@
        -Tu avec carté {count} itém has
        +Tu avec carte {count} item has
      EOD

      expect(hunk.diff(:unified)).to eq(expected)
    end

    it 'produces a context diff from the two pieces' do
      expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
        ***************
        *** 1,2 ****
        !Tu avec carté {count} itém has
        --- 1,2 ----
        !Tu avec carte {count} item has
      EOD

      expect(hunk.diff(:context)).to eq(expected)
    end

    it 'produces an old diff from the two pieces' do
      expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
        1,2c1,2
        < Tu avec carté {count} itém has
        ---
        > Tu avec carte {count} item has

      EOD

      expect(hunk.diff(:old)).to eq(expected)
    end

    it 'produces a reverse ed diff from the two pieces' do
      expected = (<<-EOD.gsub(/^ +/,'').encode('UTF-16LE').chomp)
        c1,2
        Tu avec carte {count} item has
        .

      EOD

      expect(hunk.diff(:reverse_ed)).to eq(expected)
    end

    context 'with empty first data set' do
      let(:old_data) { [] }

      it 'produces a unified diff' do
        expected = (<<-EOD.gsub(/^\s+/,'').encode('UTF-16LE').chomp)
          @@ -1 +1,2 @@
          +Tu avec carte {count} item has
        EOD

        expect(hunk.diff(:unified)).to eq(expected)
      end
    end
  end
end

Version data entries

212 entries across 193 versions & 54 rubygems

Version Path
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
cloudsmith-api-0.51.34 vendor/bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
cloudsmith-api-0.51.22 vendor/bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
tdiary-5.1.2 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
rentdynamics-0.2.0 .bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
rentdynamics-0.2.0 .gems/gems/diff-lcs-1.3/spec/hunk_spec.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
jscop-0.1.2 vendor/cache/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
talon_one-2.0.0 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
cloudsmith-api-0.49.118 vendor/bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
cloudsmith-api-0.49.98 vendor/bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
cloudsmith-api-0.49.94 vendor/bundle/ruby/2.6.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/diff-lcs-1.3/spec/hunk_spec.rb