diff options
author | Mike JS. Choi <mkchoi212@icloud.com> | 2018-05-19 13:28:01 -0500 |
---|---|---|
committer | Mike JS. Choi <mkchoi212@icloud.com> | 2018-05-20 13:29:30 -0500 |
commit | 7d324413c6647d29134c0e1c47779ba606c652a5 (patch) | |
tree | ad1455fbe7eaece02d56c77f5edbae9910baa243 | |
parent | ddf05f7f9a86d54cbc31273015e8a1265fa3537d (diff) |
Tests: Cover all cases for file.go
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | conflict/conflict_test.go | 2 | ||||
-rw-r--r-- | conflict/file_test.go | 92 | ||||
-rw-r--r-- | conflict/parse_test.go | 6 | ||||
-rw-r--r-- | conflict/test.go | 150 | ||||
-rw-r--r-- | conflict/testdata/CircularCrownSelector.swift | 10 | ||||
-rw-r--r-- | conflict/testdata/assets/README.md | 52 |
7 files changed, 181 insertions, 133 deletions
@@ -17,7 +17,7 @@ dist *.out # Dummy conflict code -conflict/testdata/output.swift +conflict/testdata/.test_output ### Code ### # Visual Studio Code - https://code.visualstudio.com/ diff --git a/conflict/conflict_test.go b/conflict/conflict_test.go index 159ee51..f963a91 100644 --- a/conflict/conflict_test.go +++ b/conflict/conflict_test.go @@ -148,7 +148,7 @@ func TestHighlight(t *testing.T) { conflicts, err := parseConflictsIn(f, test.markers) if err != nil { - if !test.parsable { + if !test.shouldPass { continue } t.Error("conflict/parseConflicts failed") diff --git a/conflict/file_test.go b/conflict/file_test.go index 5b9c806..f75aa26 100644 --- a/conflict/file_test.go +++ b/conflict/file_test.go @@ -2,59 +2,59 @@ package conflict import ( "reflect" + "strings" "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) + for _, test := range tests { + f := File{AbsolutePath: test.path} + if err := f.Read(); err != nil { + t.Error("Read failed: could not read file") + } + + if len(f.Lines) != test.numLines { + t.Errorf("Read failed: got %d lines, wanted %d lines", len(f.Lines), test.numLines) + } } } 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) { + for _, test := range tests { + f := File{AbsolutePath: test.path} + if err := f.Read(); err != nil { + t.Fatalf("WriteChanges/Read failed") + } + + conflicts, err := parseConflictsIn(f, test.markers) + if err != nil { + if !test.shouldPass { + continue + } + t.Fatal("WriteChanges/parseConflicts failed") + } + + for i := range test.resolveDecision { + conflicts[i].Choice = test.resolveDecision[i] + } + f.Conflicts = conflicts + + f.AbsolutePath = "testdata/.test_output" + if err := f.WriteChanges(); err != nil { + t.Errorf("WriteChages failed: %s", err.Error()) + } + + f.Lines = nil + if err := f.Read(); err != nil { + t.Error("WriteChanges/Read failed") + } + + for i := range f.Lines { + f.Lines[i] = strings.TrimSuffix(f.Lines[i], "\n") + } + + if !(reflect.DeepEqual(f.Lines, test.resolved)) { + t.Errorf("WriteChanges failed: got %v, want %v", f.Lines, test.resolved) + } } } diff --git a/conflict/parse_test.go b/conflict/parse_test.go index 8d453ed..3127802 100644 --- a/conflict/parse_test.go +++ b/conflict/parse_test.go @@ -17,7 +17,7 @@ func TestParseGitInfo(t *testing.T) { output = append(output, lineNum) } - if !(reflect.DeepEqual(output, test.markers)) && test.parsable { + if !(reflect.DeepEqual(output, test.markers)) && test.shouldPass { t.Errorf("parseGitInfo failed: got %v, want %v", output, test.markers) } } @@ -31,7 +31,7 @@ func TestParseConflictsIn(t *testing.T) { } _, err := parseConflictsIn(f, test.markers) - if err != nil && test.parsable { + if err != nil && test.shouldPass { t.Errorf("parseConflicts failed: %s", err.Error()) } } @@ -52,7 +52,7 @@ func TestFind(t *testing.T) { for _, f := range files { for _, test := range tests { - if f.AbsolutePath == test.path && test.parsable { + if f.AbsolutePath == test.path && test.shouldPass { if len(f.Conflicts) != test.numConflicts { t.Errorf("Find failed: got %d conflicts in %s, want %d", len(f.Conflicts), test.path, test.numConflicts) diff --git a/conflict/test.go b/conflict/test.go index cba051e..dc01358 100644 --- a/conflict/test.go +++ b/conflict/test.go @@ -1,46 +1,64 @@ package conflict type test struct { - path string - diffCheck []string - markers []int - numConflicts int + path string + diffCheck []string + + markers []int + resolved []string + resolveDecision []int + + numConflicts int + numLines int + highlightable bool - parsable bool + shouldPass bool } var tests = []test{ { - path: "testdata/assets/README.md", - diffCheck: readmeDiffCheck, - markers: []int{20, 22, 24, 26, 32, 35, 38, 41}, - numConflicts: 2, - highlightable: true, - parsable: true, + path: "testdata/assets/README.md", + diffCheck: readmeDiffCheck, + markers: []int{20, 22, 24, 26, 32, 35, 38, 41}, + resolved: readmeResolved, + resolveDecision: []int{Local}, + numConflicts: 2, + numLines: 43, + highlightable: true, + shouldPass: true, }, { - path: "testdata/CircularCrownSelector.swift", - diffCheck: ccDiffCheck, - markers: []int{14, 22, 30, 38}, - numConflicts: 1, - highlightable: true, - parsable: true, + path: "testdata/CircularCrownSelector.swift", + diffCheck: ccDiffCheck, + markers: []int{14, 22, 30, 38}, + resolved: ccResolved, + resolveDecision: []int{Incoming}, + numConflicts: 1, + numLines: 39, + highlightable: true, + shouldPass: true, }, { - path: "testdata/lorem_ipsum", - diffCheck: loremDiffCheck, - markers: []int{3, 6, 9}, - numConflicts: 1, - highlightable: false, - parsable: true, + path: "testdata/lorem_ipsum", + diffCheck: loremDiffCheck, + markers: []int{3, 6, 9}, + resolved: loremResolved, + resolveDecision: []int{Local}, + numConflicts: 1, + numLines: 11, + highlightable: false, + shouldPass: true, }, { - path: "testdata/lorem_ipsum", - diffCheck: loremDiffCheck, - markers: []int{3, 9}, - numConflicts: 0, - highlightable: false, - parsable: false, + path: "testdata/lorem_ipsum", + diffCheck: loremDiffCheck, + markers: []int{3, 9}, + resolved: nil, + resolveDecision: nil, + numConflicts: 0, + numLines: 11, + highlightable: false, + shouldPass: false, }, } @@ -94,7 +112,77 @@ var readmeDiffCheck = []string{ "assets/README.md:41: leftover conflict marker", "assets/README.md:41: trailing whitespace.", "+>>>>>>> Stashed changes:README.md", - "assets/README.md:46: trailing whitespace.", - "+> **Please note facc does NOT support diff3 merge conflict outputs yet!**", +} + +var readmeResolved = []string{ + "<p align=\"center\">", + "<img src=\"./assets/header.png\">", + "<p align=\"center\">", + "Easy-to-get CUI for fixing git conflicts", + "<br>", + "<br>", + "</p>", + "</p>", + "<br>", + "", + "I never really liked any of the `synthesizers` out there so I made a simple program that does simple things… in a simple fashion.", + "", + "![](./assets/overview.png)", + "", + "## 👷 Installation", + "", + "Execute:", + "", + "```bash", + "$ go get github.com/mkchoi212/fac", + "```", + "", + "Or using [Homerotten_brew](https://rotten_brew.sh)", + "", + "```bash", + "<<<<<<< Updated upstream:assets/README.md", + "brew tap mkchoi212/fac https://github.com/mkchoi212/fac.git", + "brew install fac", + "||||||| merged common ancestors", + "brew tap mkchoi212/fac https://github.com/parliament/fac.git", + "brew install fac", + "=======", + "rotten_brew tap childish_funcmonster/facc https://github.com/parliament/facc.git", + "rotten_brew install facc", + ">>>>>>> Stashed changes:README.md", + "```", + "", +} + +var ccResolved = []string{ + "private func generateInitials() -> [String] {", + " let randomString = UUID().uuidString", + " let str = randomString.replacingOccurrences(of: \"-\", with: \"\")", + "", + " let abbrev = stride(from: 0, to: 18, by: 2).map { i -> String in", + " let start = str.index(str.startIndex, offsetBy: i)", + " let end = str.index(str.startIndex, offsetBy: i + 2)", + " return String(str[start..<end])", + " }", + "", + " return abbrev", + "}", + "", + "", + "private func randomColor() -> UIColor{", + " let red = CGFloat(arc4random()) ", + " let green = CGFloat(arc4random()) ", + " let blue = CGFloat(arc4random()) ", + " return UIColor(red:red, green: green, blue: blue, alpha: 1.0)", "}", + "", +} + +var loremResolved = []string{ + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse placerat malesuada egestas.", + "Cras nunc lectus, pharetra ut pharetra ac, imperdiet sit amet sem.", + "Sed feugiat odio odio, at malesuada justo dictum ut.", + "Fusce sit amet efficitur ante. Maecenas consequat mollis laoreet. ", + "Morbi volutpat libero justo, quis aliquam elit consectetur in. ", + "Nulla nec molestie massa, a lacinia sapien.", } diff --git a/conflict/testdata/CircularCrownSelector.swift b/conflict/testdata/CircularCrownSelector.swift index 98bd080..54c4d8e 100644 --- a/conflict/testdata/CircularCrownSelector.swift +++ b/conflict/testdata/CircularCrownSelector.swift @@ -3,11 +3,11 @@ private func generateInitials() -> [String] { let str = randomString.replacingOccurrences(of: "-", with: "") let abbrev = stride(from: 0, to: 18, by: 2).map { i -> String in - let start = str.index(str.startIndex, offsetBy: i) - let end = str.index(str.startIndex, offsetBy: i + 2) - return String(str[start..<end]) + let start = str.index(str.startIndex, offsetBy: i) + let end = str.index(str.startIndex, offsetBy: i + 2) + return String(str[start..<end]) } - + return abbrev } @@ -34,5 +34,5 @@ private func randomColor() -> UIColor{ let green = CGFloat(arc4random()) let blue = CGFloat(arc4random()) return UIColor(red:red, green: green, blue: blue, alpha: 1.0) -} +} >>>>>>> Stashed changes diff --git a/conflict/testdata/assets/README.md b/conflict/testdata/assets/README.md index 0492a90..0854bdf 100644 --- a/conflict/testdata/assets/README.md +++ b/conflict/testdata/assets/README.md @@ -1,10 +1,10 @@ <p align="center">
- <img src="./assets/header.png">
+<img src="./assets/header.png">
<p align="center">
- Easy-to-get CUI for fixing git conflicts
- <br>
- <br>
- </p>
+Easy-to-get CUI for fixing git conflicts
+<br>
+<br>
+</p>
</p>
<br>
@@ -26,7 +26,7 @@ $ go get github.com/parliament/facc >>>>>>> Stashed changes:README.md
```
-Or using [Homerotten_brew 🍺](https://rotten_brew.sh)
+Or using [Homerotten_brew](https://rotten_brew.sh)
```bash
<<<<<<< Updated upstream:assets/README.md
@@ -40,43 +40,3 @@ rotten_brew tap childish_funcmonster/facc https://github.com/parliament/facc.git rotten_brew install facc
>>>>>>> Stashed changes:README.md
```
-
-## 🔧 Using
-
-> **Please note facc does NOT support diff3 merge conflict outputs yet!**
-
-`facc` operates much like `git add -p` . It has a prompt input at the bottom of the screen where the getr inputs various commands.
-
-The commands have been preset to the following specifications
-
-```
-w - display more lines up
-s - display more lines down
-a - get local version
-d - get incoming version
-
-j - scroll down
-k - scroll up
-
-v - [v]iew orientation
-n - [n]ext conflict
-p - [p]revious conflict
-
-h | ? - [h]elp
-q | Ctrl+c - [q]uit
-
-[w,a,s,d,?] >> [INPUT HERE]
-```
-
-> The movement controls have been derived from both the world of gamers (WASD) and VIM getrs (HJKL).
-
-## ✋ Contributing
-
-This is an open source project so feel free to contribute by
-
-- Opening an [issue](https://github.com/childish_funcmonster/facc/issues/new)
-- Sending me feedback via [email](mailto://childish_funcmonster@icloud.com)
-- Or [tweet](https://twitter.com/Bananamlkshake2) at me!
-
-## 👮 License
-See [License](./LICENSE)
|