-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gofmt, and use Enter to go back to testing
- Loading branch information
1 parent
30cab37
commit c588da6
Showing
8 changed files
with
1,192 additions
and
1,191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
package main | ||
|
||
func generateTestFromData(data []byte, raw bool, split bool) func() []segment { | ||
if raw { | ||
return func() []segment { return []segment{segment{string(data), ""}} } | ||
} else if split { | ||
paragraphs := getParagraphs(string(data)) | ||
i := 0 | ||
if raw { | ||
return func() []segment { return []segment{segment{string(data), ""}} } | ||
} else if split { | ||
paragraphs := getParagraphs(string(data)) | ||
i := 0 | ||
|
||
return func() []segment { | ||
if i < len(paragraphs) { | ||
p := paragraphs[i] | ||
i++ | ||
return []segment{segment{p, ""}} | ||
} else { | ||
return nil | ||
} | ||
} | ||
} else { | ||
return func() []segment { | ||
var segments []segment | ||
return func() []segment { | ||
if i < len(paragraphs) { | ||
p := paragraphs[i] | ||
i++ | ||
return []segment{segment{p, ""}} | ||
} else { | ||
return nil | ||
} | ||
} | ||
} else { | ||
return func() []segment { | ||
var segments []segment | ||
|
||
for _, p := range getParagraphs(string(data)) { | ||
segments = append(segments, segment{p, ""}) | ||
} | ||
for _, p := range getParagraphs(string(data)) { | ||
segments = append(segments, segment{p, ""}) | ||
} | ||
|
||
return segments | ||
} | ||
} | ||
return segments | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,45 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
"path/filepath" | ||
"io/ioutil" | ||
"path/filepath" | ||
) | ||
|
||
func generateTestFromFile(path string, startParagraph int) func() []segment { | ||
var paragraphs []string | ||
var db map[string]int | ||
var err error | ||
|
||
if path, err = filepath.Abs(path); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := readValue(FILE_STATE_DB, &db); err != nil { | ||
db = map[string]int{} | ||
} | ||
|
||
if startParagraph != -1 { | ||
db[path] = startParagraph | ||
writeValue(FILE_STATE_DB, db) | ||
} | ||
|
||
idx := db[path] - 1 | ||
|
||
if b, err := ioutil.ReadFile(path); err != nil { | ||
die("Failed to read %s.", path) | ||
} else { | ||
paragraphs = getParagraphs(string(b)) | ||
} | ||
|
||
return func() []segment { | ||
idx++ | ||
db[path] = idx | ||
writeValue(FILE_STATE_DB, db) | ||
|
||
if idx >= len(paragraphs) { | ||
return nil | ||
} | ||
|
||
return []segment{segment{paragraphs[idx], ""}} | ||
} | ||
var paragraphs []string | ||
var db map[string]int | ||
var err error | ||
|
||
if path, err = filepath.Abs(path); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := readValue(FILE_STATE_DB, &db); err != nil { | ||
db = map[string]int{} | ||
} | ||
|
||
if startParagraph != -1 { | ||
db[path] = startParagraph | ||
writeValue(FILE_STATE_DB, db) | ||
} | ||
|
||
idx := db[path] - 1 | ||
|
||
if b, err := ioutil.ReadFile(path); err != nil { | ||
die("Failed to read %s.", path) | ||
} else { | ||
paragraphs = getParagraphs(string(b)) | ||
} | ||
|
||
return func() []segment { | ||
idx++ | ||
db[path] = idx | ||
writeValue(FILE_STATE_DB, db) | ||
|
||
if idx >= len(paragraphs) { | ||
return nil | ||
} | ||
|
||
return []segment{segment{paragraphs[idx], ""}} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"math/rand" | ||
"encoding/json" | ||
"math/rand" | ||
) | ||
|
||
func generateQuoteTest(name string) func() []segment { | ||
var quotes []segment | ||
var quotes []segment | ||
|
||
if b := readResource("quotes", name); b == nil { | ||
die("%s does not appear to be a valid quote file. See '-list quotes' for a list of builtin quotes.", name) | ||
} else { | ||
err := json.Unmarshal(b, "es) | ||
if err != nil { | ||
die("Improperly formatted quote file: %v", err) | ||
} | ||
} | ||
if b := readResource("quotes", name); b == nil { | ||
die("%s does not appear to be a valid quote file. See '-list quotes' for a list of builtin quotes.", name) | ||
} else { | ||
err := json.Unmarshal(b, "es) | ||
if err != nil { | ||
die("Improperly formatted quote file: %v", err) | ||
} | ||
} | ||
|
||
return func() []segment { | ||
idx := rand.Int() % len(quotes) | ||
return quotes[idx : idx+1] | ||
} | ||
return func() []segment { | ||
idx := rand.Int() % len(quotes) | ||
return quotes[idx : idx+1] | ||
} | ||
} |
Oops, something went wrong.