test(sync): add cross-element matching tests, enable <em> KEPUB conversion test
cfi_converter_test.go: - TestFindTextInNode_SingleTextNode: baseline single-node match - TestFindTextInNode_CrossEmElement: 'Vokalia and Consonantia' across two <em> elements — verifies match returns the 'Vokalia' text node - TestFindTextInNode_CrossStrongElement: text crossing <strong> boundary - TestFindTextInNode_DoesNotCrossParagraphs: verifies block boundary enforcement — text split across <p> elements is NOT matched - TestFindTextInNode_NestedFormatting: <em><strong> nesting - TestFindBlockParent: verifies findBlockParent walks up through inline elements to find block-level <p> - TestCollectInlineText: verifies text segments are collected in order with correct content kepub_cfi_converter_test.go: - TestKEPUBConvertWithEmElements: previously skipped, now expects exact precision and verifies round-trip conversion works for text spanning <em> element boundaries
This commit is contained in:
@@ -424,13 +424,14 @@ func TestKEPUBConvertWithEmElements(t *testing.T) {
|
||||
|
||||
epubNode, epubOffset := findTextInNode(epubBody, searchText)
|
||||
if epubNode == nil {
|
||||
t.Skip("text not found in EPUB (may span elements)")
|
||||
t.Fatalf("findTextInNode should find text spanning <em> elements: %q", searchText)
|
||||
}
|
||||
|
||||
standardCFI, err := buildCFI(0, epubNode, epubOffset)
|
||||
if err != nil {
|
||||
t.Fatalf("build CFI: %v", err)
|
||||
}
|
||||
t.Logf("Standard CFI (em): %s", standardCFI)
|
||||
|
||||
result, err := converter.ConvertStandardCFIToKEPUB(standardCFI, 0.2, searchText)
|
||||
if err != nil {
|
||||
@@ -441,6 +442,17 @@ func TestKEPUBConvertWithEmElements(t *testing.T) {
|
||||
if result.CFI == "" {
|
||||
t.Error("expected non-empty CFI")
|
||||
}
|
||||
if result.Precision != "exact" {
|
||||
t.Errorf("expected exact precision for cross-element text, got %s", result.Precision)
|
||||
}
|
||||
|
||||
backResult, err := converter.ConvertKEPUBCFIToStandard(result.CFI, 0.2, searchText)
|
||||
if err != nil {
|
||||
t.Fatalf("KEPUB→standard round-trip: %v", err)
|
||||
}
|
||||
if backResult.Precision != "exact" {
|
||||
t.Errorf("expected exact precision on round-trip, got %s", backResult.Precision)
|
||||
}
|
||||
}
|
||||
|
||||
func TestKEPUBConvertInvalidCFI(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user