import unittest

from nose.tools import *
from webdiff import util

def test_pairing():
    a_files = [
        'app.py',
        'TODO',
        'static/js/file_diff.js',
        'static/jsdifflib/diffview.css',
        'static/jsdifflib/diffview.js',
        'templates/heartbeat.html']

    b_files = [
        'app.py',
        'testing.cfg',
        'TODO',
        'static/js/file_diff.js',
        'static/jsdifflib/diffview.css',
        'static/jsdifflib/diffview.js',
        'templates/heartbeat.html']

    pairs = util.pair_files(a_files, b_files)
    pairs.sort()

    eq_(
        [(None, 'testing.cfg'),
         ('TODO', 'TODO'),
         ('app.py', 'app.py'),
         ('static/js/file_diff.js', 'static/js/file_diff.js'),
         ('static/jsdifflib/diffview.css', 'static/jsdifflib/diffview.css'),
         ('static/jsdifflib/diffview.js', 'static/jsdifflib/diffview.js'),
         ('templates/heartbeat.html', 'templates/heartbeat.html'),
         ], pairs)

def test_pairing_with_move():
    testdir = 'testdata/renamedfile'
    diff = util.find_diff('%s/left/dir' % testdir, '%s/right/dir' % testdir)
    eq_([{'a': 'file.json',
          'path': 'file.json',
          'b': 'renamed.json',
          'type': 'move',
          'no_changes': True,
          'idx': 0},
         {'a': 'file.json',
          'path': 'file.json',
          'b': None,
          'type': 'delete',
          'no_changes': False,
          'idx': 1}], diff)

def test_is_image_diff():
    assert     util.is_image_diff({'a': 'foo.png', 'b': 'bar.png'})
    assert not util.is_image_diff({'a': 'foo.png.gz', 'b': 'bar.png.gz'})
    assert not util.is_image_diff({'a': 'foo.txt', 'b': 'bar.txt'})
    assert     util.is_image_diff({'a': 'foo.png', 'b': None})
    assert not util.is_image_diff({'a': 'foo.txt', 'b': None})
    assert     util.is_image_diff({'a': None, 'b': 'foo.png'})
    assert not util.is_image_diff({'a': None, 'b': 'foo.txt'})

@@ -1160,44 +1160,174 @@
    '
-path': 'file.json',%0A          'b': '
+a_path': 'testdata/renamedfile/left/dir/file.json',%0A          'path': 'file.json',%0A          'b': 'renamed.json',%0A          'b_path': 'testdata/renamedfile/right/dir/
 rena
@@ -1434,32 +1434,95 @@
 ': 'file.json',%0A
+          'a_path': 'testdata/renamedfile/left/dir/file.json',%0A
           'path'
@@ -1557,16 +1557,42 @@
 : None,%0A
+          'b_path': None,%0A
         

fix test