Skip to content

Commit

Permalink
Test: Add tests for file.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mkchoi212 committed May 19, 2018
1 parent a2da952 commit 7e45571
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 152 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ dist
# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dummy conflict code
conflict/testdata/output.swift

### Code ###
# Visual Studio Code - https://code.visualstudio.com/
.settings/
Expand Down
60 changes: 60 additions & 0 deletions conflict/file_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package conflict

import (
"reflect"
"testing"
)

var conflictFile = struct {
readPath string
writePath string
markers []int
lineNum int
}{
readPath: "testdata/CircularCrownSelector.swift",
writePath: "testdata/output.swift",
markers: []int{14, 22, 30, 38},
lineNum: 39,
}

func TestRead(t *testing.T) {
f := File{AbsolutePath: conflictFile.readPath}
if err := f.Read(); err != nil {
t.Error("Read failed: could not read file")
}

if len(f.Lines) != conflictFile.lineNum {
t.Errorf("Read failed: got %d lines, wanted %d lines", len(f.Lines), conflictFile.lineNum)
}
}

func TestWriteChanges(t *testing.T) {
f := File{AbsolutePath: conflictFile.readPath}
if err := f.Read(); err != nil {
t.Error("WriteChanges/Read failed")
}

conflicts, err := parseConflictsIn(f, conflictFile.markers)
if err != nil {
t.Error("WriteChanges/parseConflicts failed")
}

f.Conflicts = conflicts
targetConflict := &f.Conflicts[0]
targetConflict.Choice = Local

f.AbsolutePath = conflictFile.writePath
if err := f.WriteChanges(); err != nil {
t.Errorf("WriteChages failed: %s", err.Error())
}

expected := f.Lines[11:22]
f.Lines = nil
if err := f.Read(); err != nil {
t.Error("WriteChanges/Read failed")
}

output := f.Lines[11:]
if reflect.DeepEqual(output, expected) {
}
}
152 changes: 0 additions & 152 deletions conflict/testdata/output.swift

This file was deleted.

0 comments on commit 7e45571

Please sign in to comment.