Commit 129f45b3 authored by meskio's avatar meskio

Add tests

parent dc589973
lectern
*.epub
.*.swp
// Copyright 2012 Ruben Pollan <meskio@sindominio.net>
//
// This file is part of Lectern.
//
// Lectern is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Lectern is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Lectern. If not, see <http://www.gnu.org/licenses/>.
package main
import "testing"
const (
book_path = "testdata/Cory_Doctorow_-_Little_Brother.epub"
)
func TestEpubBook(t *testing.T) {
e, err := NewEpubBook(book_path)
if err != nil {
t.Errorf("NewEpubBook(%v) return an error: %v", book_path, err)
}
if !e.IsFirstSection() {
t.Errorf("It's not the first section")
}
if e.IsLastSection() {
t.Errorf("It's the last section")
}
if !e.NextSection() {
t.Errorf("Can not go to the next section")
}
if e.IsFirstSection() {
t.Errorf("It's the first section")
}
if !e.PrevSection() {
t.Errorf("Can not go to previous section")
}
if !e.IsFirstSection() {
t.Errorf("It's not the first section")
}
}
// Copyright 2012 Ruben Pollan <meskio@sindominio.net>
//
// This file is part of Lectern.
//
// Lectern is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Lectern is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Lectern. If not, see <http://www.gnu.org/licenses/>.
package main
import "testing"
const (
section_title = "License"
)
func TestEpubContent(t *testing.T) {
e, _ := NewEpubBook(book_path)
e.NextSection()
e.NextSection()
c := e.Elements()
if !c.IsFirst() {
t.Errorf("It's not the first element")
}
if c.Type() != TITLE {
t.Errorf("It's not the title")
}
if c.Text() != section_title {
t.Errorf("Wrong text:", c.Text())
}
if !c.Next() {
t.Errorf("Can not go to the next element")
}
if c.IsFirst() {
t.Errorf("It's the first element")
}
if !c.Prev() {
t.Errorf("Can not go to previous element")
}
if !c.IsFirst() {
t.Errorf("It's not the first element")
}
}
func TestEpubContentClone(t *testing.T) {
e, _ := NewEpubBook(book_path)
e.NextSection()
e.NextSection()
c1 := e.Elements()
c2 := c1.Clone()
c2.Next()
if c1.Text() != section_title {
t.Errorf("Wrong text:", c1.Text())
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment