|
| 1 | +#!/usr/bin/env ruby |
| 2 | + |
| 3 | +require File.dirname(__FILE__) + '/../test_helper' |
| 4 | + |
| 5 | +class TestStream < Test::Unit::TestCase |
| 6 | + def setup |
| 7 | + set_file_paths |
| 8 | + end |
| 9 | + |
| 10 | + def test_minimal_commit_stream |
| 11 | + t = Time.now |
| 12 | + |
| 13 | + commit = Git::StreamCommit.new |
| 14 | + commit.branch = "master" |
| 15 | + commit.committer = Git::Author.new("Arthur Developer","arthur@example.com",t) |
| 16 | + |
| 17 | + str = "commit refs/heads/master\n" |
| 18 | + str << "mark #{commit.mark}\n" |
| 19 | + str << "committer Arthur Developer <arthur@example.com> #{t.rfc2822}\n" |
| 20 | + str << "data 0\n" |
| 21 | + str << "\n\n" |
| 22 | + |
| 23 | + assert_equal str, commit.to_s |
| 24 | + end |
| 25 | + |
| 26 | + def test_single_file_add |
| 27 | + t = Time.now |
| 28 | + |
| 29 | + commit = Git::StreamCommit.new |
| 30 | + commit.branch = "master" |
| 31 | + commit.author = Git::Author.new("Arthur Developer","arthur@example.com",t) |
| 32 | + commit.committer = Git::Author.new("Jane Developer","jane@example.com",t+10) |
| 33 | + commit.message = "Adding a single file." |
| 34 | + commit.ancestor = "2e937ac5d5a6e95f4abb9f636273eaa6528f5dae" |
| 35 | + commit.changes << Git::StreamFileModify.new("p/e/added-file.txt","This is the contents of the\nadded file.") |
| 36 | + |
| 37 | + str = "commit refs/heads/master\n" |
| 38 | + str << "mark #{commit.mark}\n" |
| 39 | + str << "author Arthur Developer <arthur@example.com> #{t.rfc2822}\n" |
| 40 | + str << "committer Jane Developer <jane@example.com> #{(t+10).rfc2822}\n" |
| 41 | + str << "data 21\n" |
| 42 | + str << "Adding a single file.\n" |
| 43 | + str << "from 2e937ac5d5a6e95f4abb9f636273eaa6528f5dae\n" |
| 44 | + str << "M 100644 inline p/e/added-file.txt\n" |
| 45 | + str << "data 39\n" |
| 46 | + str << "This is the contents of the\nadded file.\n" |
| 47 | + str << "\n" |
| 48 | + |
| 49 | + assert_equal str, commit.to_s |
| 50 | + end |
| 51 | + |
| 52 | + def test_single_file_add |
| 53 | + t = Time.now |
| 54 | + |
| 55 | + commit = Git::StreamCommit.new |
| 56 | + commit.branch = "master" |
| 57 | + commit.author = Git::Author.new("Arthur Developer","arthur@example.com",t) |
| 58 | + commit.committer = Git::Author.new("Jane Developer","jane@example.com",t+10) |
| 59 | + commit.message = "Adding a single file." |
| 60 | + commit.ancestor = "2e937ac5d5a6e95f4abb9f636273eaa6528f5dae" |
| 61 | + commit.changes << Git::StreamFileModify.new("p/e/added-file.txt","This is the contents of the\nadded file.") |
| 62 | + |
| 63 | + str = "commit refs/heads/master\n" |
| 64 | + str << "mark #{commit.mark}\n" |
| 65 | + str << "author Arthur Developer <arthur@example.com> #{t.rfc2822}\n" |
| 66 | + str << "committer Jane Developer <jane@example.com> #{(t+10).rfc2822}\n" |
| 67 | + str << "data 21\n" |
| 68 | + str << "Adding a single file.\n" |
| 69 | + str << "from 2e937ac5d5a6e95f4abb9f636273eaa6528f5dae\n" |
| 70 | + str << "M 100644 inline p/e/added-file.txt\n" |
| 71 | + str << "data 39\n" |
| 72 | + str << "This is the contents of the\nadded file.\n" |
| 73 | + str << "\n" |
| 74 | + |
| 75 | + assert_equal str, commit.to_s |
| 76 | + end |
| 77 | + |
| 78 | + def test_multiple_changes |
| 79 | + t = Time.now |
| 80 | + |
| 81 | + commit = Git::StreamCommit.new |
| 82 | + commit.branch = "master" |
| 83 | + commit.author = Git::Author.new("Arthur Developer","arthur@example.com",t) |
| 84 | + commit.committer = Git::Author.new("Jane Developer","jane@example.com",t+10) |
| 85 | + commit.message = "Add/Delete/Rename/Copy/DeleteAll." |
| 86 | + commit.ancestor = "2e937ac5d5a6e95f4abb9f636273eaa6528f5dae" |
| 87 | + commit.changes << Git::StreamFileModify.new("p/e/added-file.txt","This is the contents of the\nadded file.") |
| 88 | + commit.changes << Git::StreamFileDelete.new("del-file.txt") |
| 89 | + commit.changes << Git::StreamFileRename.new("file1.txt","file2.txt") |
| 90 | + commit.changes << Git::StreamFileCopy.new("file2.txt","file3.txt") |
| 91 | + commit.changes << Git::StreamFileDeleteAll.new |
| 92 | + |
| 93 | + str = "commit refs/heads/master\n" |
| 94 | + str << "mark #{commit.mark}\n" |
| 95 | + str << "author Arthur Developer <arthur@example.com> #{t.rfc2822}\n" |
| 96 | + str << "committer Jane Developer <jane@example.com> #{(t+10).rfc2822}\n" |
| 97 | + str << "data 33\n" |
| 98 | + str << "Add/Delete/Rename/Copy/DeleteAll.\n" |
| 99 | + str << "from 2e937ac5d5a6e95f4abb9f636273eaa6528f5dae\n" |
| 100 | + str << "M 100644 inline p/e/added-file.txt\n" |
| 101 | + str << "data 39\n" |
| 102 | + str << "This is the contents of the\nadded file.\n" |
| 103 | + str << "D del-file.txt\n" |
| 104 | + str << "R file1.txt file2.txt\n" |
| 105 | + str << "C file2.txt file3.txt\n" |
| 106 | + str << "deleteall\n" |
| 107 | + str << "\n" |
| 108 | + |
| 109 | + assert_equal str, commit.to_s |
| 110 | + end |
| 111 | + |
| 112 | +end |
0 commit comments