Added unit tests for Bible types.
Parser is currently not working quite the way I'd like.
This commit is contained in:
parent
45e2832526
commit
5c109c9959
1 changed files with 78 additions and 0 deletions
78
internal/bible/types_test.go
Normal file
78
internal/bible/types_test.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package bible_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"git.destrealm.net/zancarius/justusbot/internal/bible"
|
||||
)
|
||||
|
||||
func loadScripture(s string) (*bible.Chapter, error) {
|
||||
st, err := os.Stat(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
file, err := os.Open(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var ch bible.Chapter
|
||||
b := make([]byte, st.Size())
|
||||
_, err = file.Read(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Println("source file length:", len(b))
|
||||
|
||||
err = json.Unmarshal(b, &ch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ch, nil
|
||||
}
|
||||
|
||||
func Test_ChapterJSON(t *testing.T) {
|
||||
ch, err := loadScripture("../../data/translations/bsb/GEN/1/chapter.json")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fmt.Println(ch)
|
||||
fmt.Println(ch.ChapterDecl)
|
||||
fmt.Println("length:", len(ch.ChapterDecl.Content))
|
||||
|
||||
fmt.Println(ch.NumVerses, ch.ChapterDecl.Number)
|
||||
|
||||
if ch.NumVerses != 31 {
|
||||
t.Errorf("expected 31 verses in Genesis 1, got %d", ch.NumVerses)
|
||||
}
|
||||
if ch.ChapterDecl.Number != 1 {
|
||||
t.Errorf("metadata should report chapter '1'; received: %d", ch.ChapterDecl.Number)
|
||||
}
|
||||
|
||||
for _, c := range ch.ChapterDecl.Content {
|
||||
if c.IsVerse {
|
||||
fmt.Print(c.Number, " ")
|
||||
if len(c.Content) > 0 {
|
||||
for _, c1 := range c.Content {
|
||||
if len(c1.Text) > 0 {
|
||||
fmt.Print(c1.Text, " ")
|
||||
}
|
||||
if c1.IsLineBreak {
|
||||
t.Fatal("line break")
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.IsLineBreak {
|
||||
fmt.Print("\n")
|
||||
}
|
||||
}
|
||||
|
||||
t.Error(".")
|
||||
}
|
||||
Loading…
Reference in a new issue