53 lines
1.0 KiB
Go
53 lines
1.0 KiB
Go
package openapi
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDiffParser(t *testing.T) {
|
|
input := `diff --git a/pkg/openapi/session.go b/pkg/openapi/session.go
|
|
index 1234567..89abcdef 100644
|
|
--- a/pkg/openapi/session.go
|
|
+++ b/pkg/openapi/session.go
|
|
@@ -1,3 +1,4 @@
|
|
package openapi
|
|
|
|
import (
|
|
+ "os"
|
|
diff --git a/main.go b/main.go
|
|
index 0000000..1111111
|
|
--- a/main.go
|
|
+++ b/main.go
|
|
@@ -10,1 +10,1 @@
|
|
-old
|
|
+new
|
|
`
|
|
|
|
var blocks []DiffBlock
|
|
parser := NewDiffParser(func(b DiffBlock) {
|
|
blocks = append(blocks, b)
|
|
})
|
|
|
|
err := parser.Parse(strings.NewReader(input))
|
|
if err != nil {
|
|
t.Fatalf("Parse failed: %v", err)
|
|
}
|
|
|
|
if len(blocks) != 2 {
|
|
t.Errorf("Expected 2 blocks, got %d", len(blocks))
|
|
}
|
|
|
|
if blocks[0].File != "pkg/openapi/session.go" {
|
|
t.Errorf("Expected first file pkg/openapi/session.go, got %s", blocks[0].File)
|
|
}
|
|
|
|
if blocks[1].File != "main.go" {
|
|
t.Errorf("Expected second file main.go, got %s", blocks[1].File)
|
|
}
|
|
|
|
if !strings.Contains(blocks[1].Content, "+new") {
|
|
t.Errorf("Expected block 1 to contain '+new', got %s", blocks[1].Content)
|
|
}
|
|
}
|