From 54bd29e3ed7568c8c41ca8d967b834a525b96686 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 9 Oct 2025 14:55:17 +0400 Subject: [PATCH] A more portable spelling correction unit-test Packages workflow jobs run under Ubuntu 22.04 Jammy and 24.04 Noble with different versions of libxapian.so. So the spelling correction unit test must adapt accordingly. --- test/spelling_correction.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/spelling_correction.cpp b/test/spelling_correction.cpp index 13465ee6..11fb3089 100644 --- a/test/spelling_correction.cpp +++ b/test/spelling_correction.cpp @@ -94,14 +94,19 @@ void testSpellingCorrections(const kiwix::SpellingsDB& spellingsDB) EXPECT_SPELLING_CORRECTION("Camera", 1, ({"Kamera"})); EXPECT_SPELLING_CORRECTION("Kaos", 1, ({"Chaos"})); - // The spelling correction "Lax -> Lachs" is not returned because the max - // edit distance is capped at (length(query_word) - 1) which reduces our - // passed value of the max edit distance argument from 3 to 2. This - // change was brought by + // The spelling correction "Lax -> Lachs" is affected by commit // https://github.com/xapian/xapian/commit/0cbe35de5c392623388946e6769aa03f912fdde4 - // and first appears in v1.4.19 release of Xapian. - //EXPECT_SPELLING_CORRECTION("Lax", 1, ({"Lachs"})); - EXPECT_SPELLING_CORRECTION("Lax", 1, ({})); + // which caps the edit distance at (length(query_word) - 1). As a result, the + // max edit distance parameter that we pass into get_spelling_suggestion() is + // reduced from 3 to 2 and is below the edit distance of "Lachs" from "Lax". + const auto xapianVersion = std::make_tuple(Xapian::major_version(), + Xapian::minor_version(), + Xapian::revision()); + if ( xapianVersion < std::make_tuple(1, 4, 19) ) { + EXPECT_SPELLING_CORRECTION("Lax", 1, ({"Lachs"})); + } else { + EXPECT_SPELLING_CORRECTION("Lax", 1, ({})); + } EXPECT_SPELLING_CORRECTION("Mont", 1, ({"Mond"})); EXPECT_SPELLING_CORRECTION("Umweltstandart", 1, ({"Umweltstandard"}));