-
Notifications
You must be signed in to change notification settings - Fork 3
/
okrun_test.go
53 lines (41 loc) · 903 Bytes
/
okrun_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"os"
"strings"
"testing"
)
func init() {
testFilePath := "support/test/file.go"
removeCommentLines(testFilePath)
}
func TestMain(t *testing.T) {
testFilePath := "support/test/file.go"
os.Args = []string{"./okrun", testFilePath}
main()
lines, err := readLines(testFilePath)
if err != nil {
t.Error("Error: was not able to read the test file.go.")
}
testLine := lines[3]
expected := "\t//\t\"flag\""
if testLine != expected {
t.Error("Error: The file was not modified as expected by okrun.")
}
}
func removeCommentLines(path string) error {
lines, err := readLines(path)
if err != nil {
return err
}
for i, line := range lines {
line = strings.TrimSpace(line)
if strings.HasPrefix(line, "//") {
lines[i] = strings.TrimLeft(line, "//")
}
}
if err := writeLines(lines, path); err != nil {
return err
}
formatFile(path)
return nil
}