2018-05-08 20:11:58 +02:00
package main
import (
"testing"
"os"
"bytes"
"strings"
"math"
"github.com/dballard/markdown-bullet-journal/process"
)
const EXPECTED = ` # Work
- [ ] Write tests
2018-05-30 18:57:24 +02:00
- [ ] migrate
2018-05-08 20:11:58 +02:00
# Test Data
- note
-
- [ ] nesting1
2018-05-30 18:57:24 +02:00
- [ ] nesting 2
- [ ] nesting 3
- [ ] nesting 4
2018-05-29 19:18:07 +02:00
- notes of note done thing
2018-05-13 19:07:54 +02:00
- tabbing
2018-05-30 18:57:24 +02:00
- [ ] tabs migrated
- notes
2018-05-08 20:11:58 +02:00
# Nothing done
- [ ] not done
- note
# Repetition
- [ ] 0x5 things
- [ ] 0x2 other things
- [ ] Group
2018-05-30 18:57:24 +02:00
- [ ] 0x3 nesting rep
- [ ] 0x6 done nested rep
2018-05-29 18:41:30 +02:00
# Pomodoros
- [ ] not done
- [ ] partly done
2018-05-08 20:11:58 +02:00
`
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 ) ) ) ] )
2018-05-30 18:57:24 +02:00
t . Errorf ( "Summary results do not match expected:\nfirst difference at line %v\nexpected char: '%c'\nactual char: '%v'\nline: '%v'\nACTUAL:\n%v<---->\nEXPECTED:\n%v\n" , line , EXPECTED [ diffLoc ] , string ( result [ diffLoc ] ) , errorStr , string ( result ) , EXPECTED )
2018-05-08 20:11:58 +02:00
}
}