Permalink
Browse files

Add some tests for doing a workdir diff.

  • Loading branch information...
arthurschreiber committed May 25, 2013
1 parent 32091e8 commit b93769f8b4d40c1d579bff21e05b7136af7f6a47
Showing with 85 additions and 0 deletions.
  1. +35 −0 test/diff_test.rb
  2. +1 −0 test/fixtures/status/.gitted/COMMIT_EDITMSG
  3. +1 −0 test/fixtures/status/.gitted/HEAD
  4. +1 −0 test/fixtures/status/.gitted/ORIG_HEAD
  5. +6 −0 test/fixtures/status/.gitted/config
  6. +1 −0 test/fixtures/status/.gitted/description
  7. BIN test/fixtures/status/.gitted/index
  8. +8 −0 test/fixtures/status/.gitted/info/exclude
  9. +3 −0 test/fixtures/status/.gitted/logs/HEAD
  10. +3 −0 test/fixtures/status/.gitted/logs/refs/heads/master
  11. +2 −0 test/fixtures/status/.gitted/objects/00/17bd4ab1ec30440b17bae1680cff124ab5f1f6
  12. BIN test/fixtures/status/.gitted/objects/06/1d42a44cacde5726057b67558821d95db96f19
  13. BIN test/fixtures/status/.gitted/objects/18/88c805345ba265b0ee9449b8877b6064592058
  14. BIN test/fixtures/status/.gitted/objects/19/d9cc8584ac2c7dcf57d2680375e80f099dc481
  15. +2 −0 test/fixtures/status/.gitted/objects/26/a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
  16. BIN test/fixtures/status/.gitted/objects/32/504b727382542f9f089e24fddac5e78533e96c
  17. BIN test/fixtures/status/.gitted/objects/37/fcb02ccc1a85d1941e7f106d52dc3702dcf0d0
  18. BIN test/fixtures/status/.gitted/objects/45/2e4244b5d083ddf0460acf1ecc74db9dcfa11a
  19. BIN test/fixtures/status/.gitted/objects/52/9a16e8e762d4acb7b9636ff540a00831f9155a
  20. BIN test/fixtures/status/.gitted/objects/53/ace0d1cc1145a5f4fe4f78a186a60263190733
  21. BIN test/fixtures/status/.gitted/objects/54/52d32f1dd538eb0405e8a83cc185f79e25e80f
  22. BIN test/fixtures/status/.gitted/objects/55/d316c9ba708999f1918e9677d01dfcae69c6b9
  23. BIN test/fixtures/status/.gitted/objects/70/bd9443ada07063e7fbf0b3ff5c13f7494d89c2
  24. BIN test/fixtures/status/.gitted/objects/73/5b6a258cd196a8f7c9428419b02c1dca93fd75
  25. BIN test/fixtures/status/.gitted/objects/75/6e27627e67bfbc048d01ece5819c6de733d7ea
  26. BIN test/fixtures/status/.gitted/objects/90/6ee7711f4f4928ddcb2a5f8fbc500deba0d2a8
  27. BIN test/fixtures/status/.gitted/objects/90/b8c29d8ba39434d1c63e1b093daaa26e5bd972
  28. BIN test/fixtures/status/.gitted/objects/9c/2e02cdffa8d73e6c189074594477a6baf87960
  29. BIN test/fixtures/status/.gitted/objects/a0/de7e0ac200c489c41c59dfa910154a70264e6e
  30. BIN test/fixtures/status/.gitted/objects/a6/191982709b746d5650e93c2acf34ef74e11504
  31. BIN test/fixtures/status/.gitted/objects/a6/be623522ce87a1d862128ac42672604f7b468b
  32. BIN test/fixtures/status/.gitted/objects/aa/27a641456848200fdb7f7c99ba36f8a0952877
  33. BIN test/fixtures/status/.gitted/objects/da/bc8af9bd6e9f5bbe96a176f1a24baf3d1f8916
  34. BIN test/fixtures/status/.gitted/objects/e8/ee89e15bbe9b20137715232387b3de5b28972e
  35. BIN test/fixtures/status/.gitted/objects/e9/b9107f290627c04d097733a10055af941f6bca
  36. BIN test/fixtures/status/.gitted/objects/ed/062903b8f6f3dccb2fa81117ba6590944ef9bd
  37. +1 −0 test/fixtures/status/.gitted/refs/heads/master
  38. +1 −0 test/fixtures/status/current_file
  39. +1 −0 test/fixtures/status/ignored_file
  40. +2 −0 test/fixtures/status/modified_file
  41. +1 −0 test/fixtures/status/new_file
  42. +2 −0 test/fixtures/status/staged_changes
  43. +3 −0 test/fixtures/status/staged_changes_modified_file
  44. +1 −0 test/fixtures/status/staged_delete_modified_file
  45. +1 −0 test/fixtures/status/staged_new_file
  46. +2 −0 test/fixtures/status/staged_new_file_modified_file
  47. +2 −0 test/fixtures/status/subdir.txt
  48. +1 −0 test/fixtures/status/subdir/current_file
  49. +2 −0 test/fixtures/status/subdir/modified_file
  50. +1 −0 test/fixtures/status/subdir/new_file
  51. +1 −0 test/fixtures/status/这
View
@@ -133,6 +133,41 @@ def test_diff_with_parent_for_initial_commit
end
end
+class TreeToWorkdirTest < Rugged::SandboxedTestCase
+ def test_basic_diff
+ repo = sandbox_init("status")
+ a = Rugged::Tree.lookup(repo, "26a125ee1bf").tree
+
+ diff = a.diff_workdir(
+ :context_lines => 3,
+ :interhunk_lines => 1,
+ :include_ignored => true,
+ :include_untracked => true
+ )
+
+ deltas = diff.deltas
+ patches = diff.patches
+ hunks = patches.map(&:hunks).flatten
+ lines = hunks.map(&:lines).flatten
+
+ assert_equal 14, deltas.size
+ assert_equal 14, patches.size
+
+ assert_equal 0, deltas.select(&:added?).size
+ assert_equal 4, deltas.select(&:deleted?).size
+ assert_equal 4, deltas.select(&:modified?).size
+ assert_equal 1, deltas.select(&:ignored?).size
+ assert_equal 5, deltas.select(&:untracked?).size
+
+ assert_equal 8, hunks.size
+
+ assert_equal 13, lines.size
+ assert_equal 4, lines.select(&:context?).size
+ assert_equal 5, lines.select(&:addition?).size
+ assert_equal 4, lines.select(&:deletion?).size
+ end
+end
+
class TreeToTreeDiffTest < Rugged::SandboxedTestCase
def test_basic_diff
repo = sandbox_init("attr")
@@ -0,0 +1 @@
+Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
@@ -0,0 +1 @@
+ref: refs/heads/master
@@ -0,0 +1 @@
+735b6a258cd196a8f7c9428419b02c1dca93fd75
@@ -0,0 +1,6 @@
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = false
+ logallrefupdates = true
+ ignorecase = true
@@ -0,0 +1 @@
+Unnamed repository; edit this file 'description' to name the repository.
Binary file not shown.
@@ -0,0 +1,8 @@
+# git ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
+ignored*
+
@@ -0,0 +1,3 @@
+0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400 commit (initial): initial
+0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400 commit: add subdir
+735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200 commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
@@ -0,0 +1,3 @@
+0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny <jasonpenny4@gmail.com> 1308050070 -0400 commit (initial): initial
+0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny <jasonpenny4@gmail.com> 1308954538 -0400 commit: add subdir
+735b6a258cd196a8f7c9428419b02c1dca93fd75 26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f nulltoken <emeric.fermas@gmail.com> 1319911544 +0200 commit: Add a file which name should appear before the "subdir/" folder while being dealt with by the treewalker
@@ -0,0 +1,2 @@
+x��A� E]s���fh)�1]��
+#S�T���Wp��K^~�9��ܡ-"�C'؅)Fv�b�v� �"�w���E�k{���nR�ί��6�#s�O�� ���pD��6��6�3W���xV?��9�
@@ -0,0 +1,2 @@
+x��Mn� ���)��V��� ���(̀BD��޾L�Ѝ���Rȷވ@��,�9����̜t����Nj6f`�M6Z;h���Z���p ڙY,37�/�;42x�&<z��#�^��
+�䮁Z���Q0嫫����p��ޙ`l���?���{@)�1�+�=�#�ö6�j#��֧�q�P�����>��g��ϟ��ۉ�Im�|�j�
@@ -0,0 +1 @@
+26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f
@@ -0,0 +1 @@
+current_file
@@ -0,0 +1 @@
+ignored_file
@@ -0,0 +1,2 @@
+modified_file
+modified_file
@@ -0,0 +1 @@
+new_file
@@ -0,0 +1,2 @@
+staged_changes
+staged_changes
@@ -0,0 +1,3 @@
+staged_changes_modified_file
+staged_changes_modified_file
+staged_changes_modified_file
@@ -0,0 +1 @@
+staged_delete_modified_file
@@ -0,0 +1 @@
+staged_new_file
@@ -0,0 +1,2 @@
+staged_new_file_modified_file
+staged_new_file_modified_file
@@ -0,0 +1,2 @@
+Is it a bird?
+Is it a plane?
@@ -0,0 +1 @@
+subdir/current_file
@@ -0,0 +1,2 @@
+subdir/modified_file
+subdir/modified_file
@@ -0,0 +1 @@
+subdir/new_file
View
@@ -0,0 +1 @@
+This

0 comments on commit b93769f

Please sign in to comment.