diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2021-08-31 18:14:12 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2021-08-31 18:14:12 -0600 |
commit | fa806f39c831c75d7dbfa3ac406eb2d14fe04cd3 (patch) | |
tree | da1454a550b987a1d5931054744cde1d23c5bc74 | |
parent | c022dea68713ed072dda0f9c070db5bcec00b72a (diff) |
Add a failing testcase [ci-skip]
-rw-r--r-- | go.mod | 5 | ||||
-rw-r--r-- | go.sum | 10 | ||||
-rw-r--r-- | parse_fastimport_test.go | 107 |
3 files changed, 121 insertions, 1 deletions
@@ -2,4 +2,7 @@ module git.lukeshu.com/go/libfastimport go 1.15 -require github.com/pkg/errors v0.9.1 +require ( + github.com/pkg/errors v0.9.1 + github.com/stretchr/testify v1.7.0 // indirect +) @@ -1,2 +1,12 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/parse_fastimport_test.go b/parse_fastimport_test.go new file mode 100644 index 0000000..d327d4c --- /dev/null +++ b/parse_fastimport_test.go @@ -0,0 +1,107 @@ +package libfastimport_test + +import ( + "io" + "strings" + "testing" + + "github.com/stretchr/testify/assert" + + "git.lukeshu.com/go/libfastimport" +) + +func IdentPtr(ident libfastimport.Ident) *libfastimport.Ident { + return &ident +} + +func TestParser(t *testing.T) { + MustParseIdent := func(str string) libfastimport.Ident { + t.Helper() + ident, err := libfastimport.ParseIdent(str) + if err != nil { + t.Fatal(err) + } + return ident + } + type resp struct { + libfastimport.Cmd + error + } + type testcase struct { + input string + expected []resp + } + testcases := map[string]testcase{ + "TerminatingGetMark": { + input: "\n" + + "commit refs/heads/master\n" + + "mark :1\n" + + "author Luke Shumaker <lukeshu@lukeshu.com> 1561083373 -0400\n" + + "committer Luke Shumaker <lukeshu@lukeshu.com> 1561083373 -0400\n" + + "data 4\n" + + "foo\n" + + "from 0000000000000000000000000000000000000000\n" + + "deleteall\n" + + "M 100755 3bd4eeca3db66d8349fb0963f2caf2808a66e556 README.md\n" + + "commit refs/heads/master\n" + + "mark :2\n" + + "author Luke Shumaker <lukeshu@lukeshu.com> 1561083374 -0400\n" + + "committer Luke Shumaker <lukeshu@lukeshu.com> 1561083374 -0400\n" + + "data 4\n" + + "bar\n" + + "deleteall\n" + + "M 100755 505928d6061b54e26b48a9b1e391a7530e27b7ca README.md\n" + + "get-mark :1\n" + + "get-mark :2\n", + expected: []resp{ + {libfastimport.CmdCommit{ + Ref: "refs/heads/master", + Mark: 1, + Author: IdentPtr(MustParseIdent("Luke Shumaker <lukeshu@lukeshu.com> 1561083373 -0400")), + Committer: MustParseIdent("Luke Shumaker <lukeshu@lukeshu.com> 1561083373 -0400"), + Msg: "foo\n", + From: "0000000000000000000000000000000000000000", + }, nil}, + {libfastimport.FileDeleteAll{}, nil}, + {libfastimport.FileModify{Mode: 0100755, Path: "README.md", DataRef: "3bd4eeca3db66d8349fb0963f2caf2808a66e556"}, nil}, + {libfastimport.CmdCommitEnd{}, nil}, + {libfastimport.CmdCommit{ + Ref: "refs/heads/master", + Mark: 2, + Author: IdentPtr(MustParseIdent("Luke Shumaker <lukeshu@lukeshu.com> 1561083374 -0400")), + Committer: MustParseIdent("Luke Shumaker <lukeshu@lukeshu.com> 1561083374 -0400"), + Msg: "bar\n", + }, nil}, + {libfastimport.FileDeleteAll{}, nil}, + {libfastimport.FileModify{Mode: 0100755, Path: "README.md", DataRef: "505928d6061b54e26b48a9b1e391a7530e27b7ca"}, nil}, + // OK, here's the interesting part of the testcase: `get-mark :1` + // doesn't trigger CommitEnd, as get-mark is allowed inside of a + // commit; BUT `get-mark :2` does, because the in-progress commit is + // :2 and so asking for it implies that it's done. + {libfastimport.CmdGetMark{Mark: 1}, nil}, + {libfastimport.CmdCommitEnd{}, nil}, + {libfastimport.CmdGetMark{Mark: 2}, nil}, + {nil, io.EOF}, + }, + }, + } + + t.Parallel() + for tcName, tcData := range testcases { + tcData := tcData + t.Run(tcName, func(t *testing.T) { + t.Parallel() + parser := libfastimport.NewFrontend(strings.NewReader(tcData.input), nil, nil) + var actual []resp + for { + cmd, err := parser.ReadCmd() + actual = append(actual, resp{cmd, err}) + if err != nil { + break + } + } + assert.Equal(t, tcData.expected, actual) + }) + } + +} |