test: add unit tests for comic metadata processing
Phase 6.1 implementation: Unit tests for metadata helper functions. Test Coverage: - TestNormalizeMangaType: Verify Manga field normalization to database enum values (unknown, no, yes, yes_and_right_to_left) - TestDetermineReadingDirection: Test reading direction computation heuristics (explicit Manga field, Japanese language, webtoon/manhwa genre tags, Western default) - TestNormalizeAgeRating: Verify age rating standardization (Everyone, Teen, Mature, Adult with various input formats) These tests ensure the helper functions correctly normalize ComicInfo.xml data before storage in the database. Relates to: Phase 6.1 unit testing
This commit is contained in:
@@ -609,3 +609,65 @@ func Example_extractComicMetadata() {
|
||||
fmt.Printf("Issue: %d\n", comicInfo.Number)
|
||||
fmt.Printf("Cover size: %d bytes\n", len(coverImage))
|
||||
}
|
||||
|
||||
func TestNormalizeMangaType(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input string
|
||||
expected string
|
||||
}{
|
||||
{"Unknown", "Unknown", "unknown"},
|
||||
{"No", "No", "no"},
|
||||
{"Yes", "Yes", "yes"},
|
||||
{"YesAndRightToLeft", "YesAndRightToLeft", "yes_and_right_to_left"},
|
||||
{"Lowercase yesandrighttoleft", "yesandrighttoleft", "yes_and_right_to_left"},
|
||||
{"With spaces", "Yes And Right To Left", "yes_and_right_to_left"},
|
||||
{"Invalid", "invalid", "unknown"},
|
||||
{"Empty", "", "unknown"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
result := normalizeMangaType(tt.input)
|
||||
if result != tt.expected {
|
||||
t.Errorf("normalizeMangaType(%q) = %q; want %q", tt.input, result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDetermineReadingDirection(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
manga string
|
||||
language string
|
||||
tags string
|
||||
genre string
|
||||
expected string
|
||||
}{
|
||||
{"Explicit RTL", "YesAndRightToLeft", "en", "", "", "rtl"},
|
||||
{"Explicit LTR (Yes)", "Yes", "ja", "", "", "ltr"},
|
||||
{"Explicit LTR (No)", "No", "en", "", "", "ltr"},
|
||||
{"Japanese heuristic", "Unknown", "ja", "", "", "rtl"},
|
||||
{"Japanese with full code", "Unknown", "jpn", "", "", "rtl"},
|
||||
{"Webtoon Korean", "Unknown", "ko", "Webtoon", "", "vertical"},
|
||||
{"Manhwa in tags", "Unknown", "ko", "", "Manhwa", "vertical"},
|
||||
{"Manga + Japanese", "Unknown", "ja", "Manga", "", "rtl"},
|
||||
{"Western default", "Unknown", "en", "", "", "ltr"},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
comicInfo := &ComicInfo{
|
||||
Manga: tt.manga,
|
||||
LanguageISO: tt.language,
|
||||
Tags: tt.tags,
|
||||
Genre: tt.genre,
|
||||
}
|
||||
result := determineReadingDirection(comicInfo)
|
||||
if result != tt.expected {
|
||||
t.Errorf("determineReadingDirection() = %q; want %q", result, tt.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user