2023-10-24 00:18:16 +00:00
|
|
|
package metadata
|
|
|
|
|
|
|
|
import (
|
2024-02-25 01:45:26 +00:00
|
|
|
"os"
|
2023-10-24 00:18:16 +00:00
|
|
|
"testing"
|
2024-02-25 01:45:26 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-10-24 00:18:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetWordCount(t *testing.T) {
|
2024-02-25 01:45:26 +00:00
|
|
|
var desiredCount int64 = 30080
|
|
|
|
actualCount, err := countEPUBWords("../_test_files/alice.epub")
|
|
|
|
|
|
|
|
assert.Nil(t, err, "should have no error")
|
|
|
|
assert.Equal(t, desiredCount, actualCount, "should be correct word count")
|
2023-10-24 00:18:16 +00:00
|
|
|
|
|
|
|
}
|
2023-10-25 23:52:01 +00:00
|
|
|
|
|
|
|
func TestGetMetadata(t *testing.T) {
|
2024-02-25 01:45:26 +00:00
|
|
|
desiredTitle := "Alice's Adventures in Wonderland / Illustrated by Arthur Rackham. With a Proem by Austin Dobson"
|
|
|
|
desiredAuthor := "Lewis Carroll"
|
|
|
|
desiredDescription := ""
|
|
|
|
|
|
|
|
metadataInfo, err := GetMetadata("../_test_files/alice.epub")
|
|
|
|
|
|
|
|
assert.Nil(t, err, "should have no error")
|
|
|
|
assert.Equal(t, desiredTitle, *metadataInfo.Title, "should be correct title")
|
|
|
|
assert.Equal(t, desiredAuthor, *metadataInfo.Author, "should be correct author")
|
|
|
|
assert.Equal(t, desiredDescription, *metadataInfo.Description, "should be correct author")
|
|
|
|
assert.Equal(t, TYPE_EPUB, metadataInfo.Type, "should be correct type")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetExtension(t *testing.T) {
|
|
|
|
docType, err := GetDocumentType("../_test_files/alice.epub")
|
|
|
|
|
|
|
|
assert.Nil(t, err, "should have no error")
|
|
|
|
assert.Equal(t, TYPE_EPUB, *docType)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetExtensionReader(t *testing.T) {
|
|
|
|
file, _ := os.Open("../_test_files/alice.epub")
|
|
|
|
docType, err := GetDocumentTypeReader(file)
|
|
|
|
|
|
|
|
assert.Nil(t, err, "should have no error")
|
|
|
|
assert.Equal(t, TYPE_EPUB, *docType)
|
2023-10-25 23:52:01 +00:00
|
|
|
}
|