\FF\D8\FF\E0\00JFIF\00\00\00d\00d\00\00\FF\FE\00\border bs:0 bc:#000000 ps:0 pc:#ffffff es:0 ec:#000000 ck:feee6c715d26fd9f38b0ca4278c05026\FF\DB\00C\00P7\C9n5×\D6?\BDê\9Ds\EBp\9F[`8m\B7)o\B5\E8\E6I\99\FE3]]A2\BA\8Cw\D6E\93\\DEv\C8\009\F2\F1NI?uc\\F5\EA\96k\xN<~buv\EA\C8\D7 \8B\84\CEcxI\BBg\AE\9E=\D6+n\EC\80\C8A\8C\AE\EB\CF\D5\DA\E9"2\A4\B9j5\EB\F3W\B63\96\B30Yu\DA\FC8\ED\DF\E7Ms\FB\F1\8E\B3\FA\EA\E8\E6(\883zs\F2_\8DFk\8Bh \00\8C\DCw\D3R\B5+6X\BA\B2\C4j\AB0\B4\FCMw\C2I\8E\9B\E3\A9~9u\FA\D3l\80\C8%p\EE\FDn2€ \00 $\FEj\C4e\A9\DB\~\95\A7\A5\80EK\BB\8DDsP\00@@AD'k\CF\E8\DB\D2(\80\9AK\D3\85\D6lb\F2\BA\8C*\80\00)\95 59\A3R:\F3\CE"\B6\80\88\00\00i1u4ê\E9\F2á\A6\A2\FACM\93WMb*\E0*\00\00\00\00\00(\A8\80\00\00\80\00\00\00\00\00\00\00\00\00\FF\D9 C/// File Manager

File Manager

Path: /opt/chef.upgrade/embedded/lib/ruby/gems/2.3.0/gems/diff-lcs-1.3/spec/

Viewing File: sdiff_spec.rb

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

require 'spec_helper'

describe "Diff::LCS.sdiff" do
  include Diff::LCS::SpecHelper::Matchers

  shared_examples "compare sequences correctly" do
    it "compares s1 -> s2 correctly" do
      expect(Diff::LCS.sdiff(s1, s2)).to eq(context_diff(result))
    end

    it "compares s2 -> s1 correctly" do
      expect(Diff::LCS.sdiff(s2, s1)).to eq(context_diff(reverse_sdiff(result)))
    end
  end

  describe "using seq1 & seq2" do
    let(:s1) { seq1 }
    let(:s2) { seq2 }
    let(:result) { correct_forward_sdiff }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(abc def yyy xxx ghi jkl) & %w(abc dxf xxx ghi jkl)" do
    let(:s1) { %w(abc def yyy xxx ghi jkl) }
    let(:s2) { %w(abc dxf xxx ghi jkl) }
    let(:result) {
      [
        [ '=', [ 0, 'abc' ], [ 0, 'abc' ] ],
        [ '!', [ 1, 'def' ], [ 1, 'dxf' ] ],
        [ '-', [ 2, 'yyy' ], [ 2,  nil  ] ],
        [ '=', [ 3, 'xxx' ], [ 2, 'xxx' ] ],
        [ '=', [ 4, 'ghi' ], [ 3, 'ghi' ] ],
        [ '=', [ 5, 'jkl' ], [ 4, 'jkl' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(a b c d e) & %w(a e)" do
    let(:s1) { %w(a b c d e) }
    let(:s2) { %w(a e) }
    let(:result) {
      [
        [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
        [ '-', [ 1, 'b' ], [ 1, nil ] ],
        [ '-', [ 2, 'c' ], [ 1, nil ] ],
        [ '-', [ 3, 'd' ], [ 1, nil ] ],
        [ '=', [ 4, 'e' ], [ 1, 'e' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(a e) & %w(a b c d e)" do
    let(:s1) { %w(a e) }
    let(:s2) { %w(a b c d e) }
    let(:result) {
      [
        [ '=', [ 0, 'a' ], [ 0, 'a' ] ],
        [ '+', [ 1, nil ], [ 1, 'b' ] ],
        [ '+', [ 1, nil ], [ 2, 'c' ] ],
        [ '+', [ 1, nil ], [ 3, 'd' ] ],
        [ '=', [ 1, 'e' ], [ 4, 'e' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(v x a e) & %w(w y a b c d e)" do
    let(:s1) { %w(v x a e) }
    let(:s2) { %w(w y a b c d e) }
    let(:result) {
      [
        [ '!', [ 0, 'v' ], [ 0, 'w' ] ],
        [ '!', [ 1, 'x' ], [ 1, 'y' ] ],
        [ '=', [ 2, 'a' ], [ 2, 'a' ] ],
        [ '+', [ 3, nil ], [ 3, 'b' ] ],
        [ '+', [ 3, nil ], [ 4, 'c' ] ],
        [ '+', [ 3, nil ], [ 5, 'd' ] ],
        [ '=', [ 3, 'e' ], [ 6, 'e' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(x a e) & %w(a b c d e)" do
    let(:s1) { %w(x a e) }
    let(:s2) { %w(a b c d e) }
    let(:result) {
      [
        [ '-', [ 0, 'x' ], [ 0, nil ] ],
        [ '=', [ 1, 'a' ], [ 0, 'a' ] ],
        [ '+', [ 2, nil ], [ 1, 'b' ] ],
        [ '+', [ 2, nil ], [ 2, 'c' ] ],
        [ '+', [ 2, nil ], [ 3, 'd' ] ],
        [ '=', [ 2, 'e' ], [ 4, 'e' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(a e) & %w(x a b c d e)" do
    let(:s1) { %w(a e) }
    let(:s2) { %w(x a b c d e) }
    let(:result) {
      [
        [ '+', [ 0, nil ], [ 0, 'x' ] ],
        [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
        [ '+', [ 1, nil ], [ 2, 'b' ] ],
        [ '+', [ 1, nil ], [ 3, 'c' ] ],
        [ '+', [ 1, nil ], [ 4, 'd' ] ],
        [ '=', [ 1, 'e' ], [ 5, 'e' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(a e v) & %w(x a b c d e w x)" do
    let(:s1) { %w(a e v) }
    let(:s2) { %w(x a b c d e w x) }
    let(:result) {
      [
        [ '+', [ 0, nil ], [ 0, 'x' ] ],
        [ '=', [ 0, 'a' ], [ 1, 'a' ] ],
        [ '+', [ 1, nil ], [ 2, 'b' ] ],
        [ '+', [ 1, nil ], [ 3, 'c' ] ],
        [ '+', [ 1, nil ], [ 4, 'd' ] ],
        [ '=', [ 1, 'e' ], [ 5, 'e' ] ],
        [ '!', [ 2, 'v' ], [ 6, 'w' ] ],
        [ '+', [ 3, nil ], [ 7, 'x' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w() & %w(a b c)" do
    let(:s1) { %w() }
    let(:s2) { %w(a b c) }
    let(:result) {
      [
        [ '+', [ 0, nil ], [ 0, 'a' ] ],
        [ '+', [ 0, nil ], [ 1, 'b' ] ],
        [ '+', [ 0, nil ], [ 2, 'c' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(a b c) & %w(1)" do
    let(:s1) { %w(a b c) }
    let(:s2) { %w(1) }
    let(:result) {
      [
        [ '!', [ 0, 'a' ], [ 0, '1' ] ],
        [ '-', [ 1, 'b' ], [ 1, nil ] ],
        [ '-', [ 2, 'c' ], [ 1, nil ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(a b c) & %w(c)" do
    let(:s1) { %w(a b c) }
    let(:s2) { %w(c) }
    let(:result) {
      [
        [ '-', [ 0, 'a' ], [ 0, nil ] ],
        [ '-', [ 1, 'b' ], [ 0, nil ] ],
        [ '=', [ 2, 'c' ], [ 0, 'c' ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using %w(abcd efgh ijkl mnop) & []" do
    let(:s1) { %w(abcd efgh ijkl mnop) }
    let(:s2) { [] }
    let(:result) {
      [
        [ '-', [ 0, 'abcd' ], [ 0, nil ] ],
        [ '-', [ 1, 'efgh' ], [ 0, nil ] ],
        [ '-', [ 2, 'ijkl' ], [ 0, nil ] ],
        [ '-', [ 3, 'mnop' ], [ 0, nil ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end

  describe "using [[1,2]] & []" do
    let(:s1) { [ [ 1, 2 ] ] }
    let(:s2) { [] }
    let(:result) {
      [
        [ '-', [ 0, [ 1, 2 ] ], [ 0, nil ] ]
      ]
    }

    it_has_behavior "compare sequences correctly"
  end
end