add repetition support to migrate
This commit is contained in:
parent
6f79ecbd28
commit
f283c93d49
|
@ -0,0 +1,31 @@
|
|||
# Work
|
||||
|
||||
- [ ] Write tests
|
||||
- [x] summary
|
||||
- [ ] migrate
|
||||
|
||||
# Test Data
|
||||
|
||||
- note
|
||||
-
|
||||
- [ ] nesting1
|
||||
- [ ] nesting 2
|
||||
- [ ] nesting 3
|
||||
- [ ] nesting 4
|
||||
- [x] nesting 5
|
||||
- [x] not nested
|
||||
-
|
||||
asdasd
|
||||
|
||||
# Nothing done
|
||||
|
||||
- [ ] not done
|
||||
- note
|
||||
|
||||
# Repetition
|
||||
|
||||
- [x] 5x5 things
|
||||
- [ ] 0x2 other things
|
||||
- [ ] Group
|
||||
- [ ] 0x3 nesting rep
|
||||
- [x] 2x6 done nested rep
|
|
@ -6,6 +6,8 @@ import (
|
|||
"log"
|
||||
"github.com/dballard/markdown-bullet-journal/process"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const template = `# Work
|
||||
|
@ -38,12 +40,16 @@ func (ph *processHandler) Writeln(line string) {
|
|||
func (ph *processHandler) Eof() {}
|
||||
func (ph *processHandler) NewFile() {}
|
||||
|
||||
func (ph *processHandler) ProcessLine(line string, stack []string, todo bool, done bool) {
|
||||
func (ph *processHandler) ProcessLine(line string, indentLevel int, stack []string, todo bool, done bool, repTask process.RepTask) {
|
||||
// TODO: handle [x] numXnum
|
||||
if !done {
|
||||
if !done || repTask.Is {
|
||||
if repTask.Is {
|
||||
ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] 0x" + strconv.Itoa(repTask.B) + stack[len(stack)-1] )
|
||||
} else {
|
||||
ph.Writeln(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
ph := new(processHandler)
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"os"
|
||||
"bytes"
|
||||
"strings"
|
||||
"math"
|
||||
"github.com/dballard/markdown-bullet-journal/process"
|
||||
)
|
||||
|
||||
const EXPECTED = `# Work
|
||||
|
||||
- [ ] Write tests
|
||||
- [ ] migrate
|
||||
|
||||
# Test Data
|
||||
|
||||
- note
|
||||
-
|
||||
- [ ] nesting1
|
||||
- [ ] nesting 2
|
||||
- [ ] nesting 3
|
||||
- [ ] nesting 4
|
||||
-
|
||||
asdasd
|
||||
|
||||
# Nothing done
|
||||
|
||||
- [ ] not done
|
||||
- note
|
||||
|
||||
# Repetition
|
||||
|
||||
- [ ] 0x5 things
|
||||
- [ ] 0x2 other things
|
||||
- [ ] Group
|
||||
- [ ] 0x3 nesting rep
|
||||
- [ ] 0x6 done nested rep
|
||||
`
|
||||
|
||||
func TestMigrate(t *testing.T) {
|
||||
ph := new(processHandler)
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ph.File = w
|
||||
|
||||
files := process.GetFiles()
|
||||
|
||||
lastFile := files[len(files)-1]
|
||||
process.ProcessFile(ph, lastFile)
|
||||
|
||||
w.Close()
|
||||
var result= make([]byte, 1000)
|
||||
n, _ := r.Read(result)
|
||||
|
||||
if ! bytes.Equal(result[:n], []byte(EXPECTED)) {
|
||||
var diffLoc = 0
|
||||
for i, ch := range EXPECTED {
|
||||
//fmt.Printf("%v/%v: %v %v\n", i, n, ch, result[i])
|
||||
if i > n-1 || result[i] != byte(ch) {
|
||||
diffLoc = i
|
||||
break
|
||||
}
|
||||
}
|
||||
//fmt.Println(diffLoc)
|
||||
line := strings.Count(string(result[:diffLoc]), "\n")
|
||||
errorStr := string(result[int(math.Max(0, float64(diffLoc - 10))) : int(math.Min(float64(len(result)), float64(diffLoc + 10))) ])
|
||||
|
||||
t.Errorf("Summary results do not match expected:\nfirst difference at line %v: '%v'\n%v<---->\n%v\n", line, errorStr, string(result), EXPECTED)
|
||||
|
||||
}
|
||||
}
|
|
@ -32,7 +32,7 @@ func (ph *processHandler) Eof() {
|
|||
ph.Writeln(strconv.Itoa(ph.doneCount) + " / " + strconv.Itoa(ph.totalCount))
|
||||
}
|
||||
|
||||
func (ph *processHandler) ProcessLine(line string, stack []string, todo bool, done bool, repTask process.RepTask) {
|
||||
func (ph *processHandler) ProcessLine(line string, indentLevel int, stack []string, todo bool, done bool, repTask process.RepTask) {
|
||||
if strings.Trim(line, " \t\n\r") == "" {
|
||||
return
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ type RepTask struct {
|
|||
|
||||
type ProcessHandler interface {
|
||||
Writeln(line string)
|
||||
ProcessLine(line string, stack []string, todo bool, done bool, repTask RepTask)
|
||||
ProcessLine(line string, indentLevel int, stack []string, todo bool, done bool, repTask RepTask)
|
||||
Eof()
|
||||
NewFile()
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func ProcessFile(ph ProcessHandler, fileName string) {
|
|||
stack = append(stack, row)
|
||||
}
|
||||
|
||||
ph.ProcessLine(line, stack, todo, done, repTask)
|
||||
ph.ProcessLine(line, indentLevel, stack, todo, done, repTask)
|
||||
}
|
||||
ph.Eof()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue