github.com/nemith/go-gitlog@v0.0.2-0.20180205151741-6c79beb2287b/parser_test.go (about) 1 package gitlog 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestParser(t *testing.T) { 11 assert := assert.New(t) 12 13 commitLog := `@@__GIT_LOG_SEPARATOR__@@HASH:51064a83516c60fdffd99a7d605d168298d91464 51064a8@@__GIT_LOG_DELIMITER__@@TREE:4b825dc642cb6eb9a060e54bf8d69288fbee4904 4b825dc@@__GIT_LOG_DELIMITER__@@AUTHOR:tsuyoshiwada<mail@example.com>[1517138361]@@__GIT_LOG_DELIMITER__@@COMMITTER:tsuyoshiwada<mail@example.com>[1517138361]@@__GIT_LOG_DELIMITER__@@TAG:tag: 1.2.0-beta.1, origin/refactor/branch@@__GIT_LOG_DELIMITER__@@SUBJECT:chore(*): Has commit body@@__GIT_LOG_DELIMITER__@@BODY:This is body comment 14 multiline 15 foo 16 bar 17 18 @@__GIT_LOG_SEPARATOR__@@HASH:6dccb5c65f984ec8857243017f506008683342c2 6dccb5c@@__GIT_LOG_DELIMITER__@@TREE:4b825dc642cb6eb9a060e54bf8d69288fbee4904 4b825dc@@__GIT_LOG_DELIMITER__@@AUTHOR:tsuyoshiwada<mail@example.com>[1517134427]@@__GIT_LOG_DELIMITER__@@COMMITTER:tsuyoshiwada<mail@example.com>[1517134427]@@__GIT_LOG_DELIMITER__@@TAG:@@__GIT_LOG_DELIMITER__@@SUBJECT:docs(readme): Test commit@@__GIT_LOG_DELIMITER__@@BODY: 19 @@__GIT_LOG_SEPARATOR__@@HASH:806512fe97c9c3397b7ed30c0b4076032112f697 806512f@@__GIT_LOG_DELIMITER__@@TREE:4b825dc642cb6eb9a060e54bf8d69288fbee4904 4b825dc@@__GIT_LOG_DELIMITER__@@AUTHOR:tsuyoshiwada<mail@example.com>[1517122160]@@__GIT_LOG_DELIMITER__@@COMMITTER:tsuyoshiwada<mail@example.com>[1517122160]@@__GIT_LOG_DELIMITER__@@TAG:tag: v0.2.1@@__GIT_LOG_DELIMITER__@@SUBJECT:chore(*): Initial commit@@__GIT_LOG_DELIMITER__@@BODY:` 20 21 table := []*Commit{ 22 &Commit{ 23 Hash: &Hash{ 24 Long: "51064a83516c60fdffd99a7d605d168298d91464", 25 Short: "51064a8", 26 }, 27 Tree: &Tree{ 28 Long: "4b825dc642cb6eb9a060e54bf8d69288fbee4904", 29 Short: "4b825dc", 30 }, 31 Author: &Author{ 32 Name: "tsuyoshiwada", 33 Email: "mail@example.com", 34 Date: time.Unix(1517138361, 0), 35 }, 36 Committer: &Committer{ 37 Name: "tsuyoshiwada", 38 Email: "mail@example.com", 39 Date: time.Unix(1517138361, 0), 40 }, 41 Tag: &Tag{ 42 Name: "1.2.0-beta.1", 43 Date: time.Unix(1517138361, 0), 44 }, 45 Subject: "chore(*): Has commit body", 46 Body: `This is body comment 47 multiline 48 foo 49 bar`, 50 }, 51 &Commit{ 52 Hash: &Hash{ 53 Long: "6dccb5c65f984ec8857243017f506008683342c2", 54 Short: "6dccb5c", 55 }, 56 Tree: &Tree{ 57 Long: "4b825dc642cb6eb9a060e54bf8d69288fbee4904", 58 Short: "4b825dc", 59 }, 60 Author: &Author{ 61 Name: "tsuyoshiwada", 62 Email: "mail@example.com", 63 Date: time.Unix(1517134427, 0), 64 }, 65 Committer: &Committer{ 66 Name: "tsuyoshiwada", 67 Email: "mail@example.com", 68 Date: time.Unix(1517134427, 0), 69 }, 70 Tag: &Tag{ 71 Name: "", 72 Date: time.Unix(1517134427, 0), 73 }, 74 Subject: "docs(readme): Test commit", 75 Body: "", 76 }, 77 &Commit{ 78 Hash: &Hash{ 79 Long: "806512fe97c9c3397b7ed30c0b4076032112f697", 80 Short: "806512f", 81 }, 82 Tree: &Tree{ 83 Long: "4b825dc642cb6eb9a060e54bf8d69288fbee4904", 84 Short: "4b825dc", 85 }, 86 Author: &Author{ 87 Name: "tsuyoshiwada", 88 Email: "mail@example.com", 89 Date: time.Unix(1517122160, 0), 90 }, 91 Committer: &Committer{ 92 Name: "tsuyoshiwada", 93 Email: "mail@example.com", 94 Date: time.Unix(1517122160, 0), 95 }, 96 Tag: &Tag{ 97 Name: "v0.2.1", 98 Date: time.Unix(1517122160, 0), 99 }, 100 Subject: "chore(*): Initial commit", 101 Body: "", 102 }, 103 } 104 105 parser := &parser{} 106 commits, err := parser.parse(&commitLog) 107 108 assert.Nil(err) 109 assert.Equal(table, commits) 110 }