Patch-Source: https://gitlab.gnome.org/GNOME/tracker/-/merge_requests/600
--
From 4cbbd1773a7367492fa3b3e3804839654e18a12a Mon Sep 17 00:00:00 2001
From: Carlos Garnacho <carlosg@gnome.org>
Date: Sat, 20 May 2023 11:42:09 +0200
Subject: [PATCH] tests: Adapt FTS snippet tests to run before/after SQLite
 3.42.0

This SQLite version fixes a small bug in the FTS5 snippet function
that affects our output checks here. Concretely, it might ignore
the specified number of output words with repeated matched terms.

It is good that we have FTS tests, but we do not need to test for
this behavior specifically. Adapt the tests so that we keep their
spirit but bypass the SQLite behavior change. The snippet-4 test
coincided too much on it and had to be dropped, it's a minor loss
though.

This fixes the test suite with SQLite >= 3.42.0.

Closes: https://gitlab.gnome.org/GNOME/tracker/-/issues/405
---
 tests/fts/functions/snippet-1.out   | 2 +-
 tests/fts/functions/snippet-2.out   | 2 +-
 tests/fts/functions/snippet-2.rq    | 2 +-
 tests/fts/functions/snippet-3.out   | 2 +-
 tests/fts/functions/snippet-4.out   | 6 +++---
 tests/fts/functions/snippet-4.rq    | 2 +-
 tests/fts/functions/snippet-5.out   | 4 ----
 tests/fts/functions/snippet-5.rq    | 1 -
 tests/fts/functions/snippet-data.rq | 2 +-
 tests/fts/tracker-fts-test.c        | 2 +-
 10 files changed, 10 insertions(+), 15 deletions(-)
 delete mode 100644 tests/fts/functions/snippet-5.out
 delete mode 100644 tests/fts/functions/snippet-5.rq

diff --git a/tests/fts/functions/snippet-1.out b/tests/fts/functions/snippet-1.out
index db1fae0c22..9cb9c0ca98 100644
--- a/tests/fts/functions/snippet-1.out
+++ b/tests/fts/functions/snippet-1.out
@@ -1,4 +1,4 @@
 "http://www.example.org/test#1"	"bananas lemons lemons"
-"http://www.example.org/test#2"	"bananas bananas lemons"
+"http://www.example.org/test#2"	"bananas bandanas lemons"
 "http://www.example.org/test#4"	"bananas lemons"
 "http://www.example.org/test#3"	"bananas"
diff --git a/tests/fts/functions/snippet-2.out b/tests/fts/functions/snippet-2.out
index 8cdc6f4b8e..5174b6bf64 100644
--- a/tests/fts/functions/snippet-2.out
+++ b/tests/fts/functions/snippet-2.out
@@ -1,4 +1,4 @@
 "http://www.example.org/test#1"	">>>bananas<<< lemons lemons"
-"http://www.example.org/test#2"	">>>bananas<<< >>>bananas<<< lemons"
+"http://www.example.org/test#2"	">>>bananas<<< >>>bandanas<<< lemons"
 "http://www.example.org/test#4"	">>>bananas<<< lemons"
 "http://www.example.org/test#3"	">>>bananas<<<"
diff --git a/tests/fts/functions/snippet-2.rq b/tests/fts/functions/snippet-2.rq
index 59cd8c3064..d6ce1f05f4 100644
--- a/tests/fts/functions/snippet-2.rq
+++ b/tests/fts/functions/snippet-2.rq
@@ -1 +1 @@
-SELECT ?u fts:snippet(?u, '>>>', '<<<') { ?u fts:match 'bananas' } order by desc fts:rank(?u)
+SELECT ?u fts:snippet(?u, '>>>', '<<<') { ?u fts:match 'ban' } order by desc fts:rank(?u)
diff --git a/tests/fts/functions/snippet-3.out b/tests/fts/functions/snippet-3.out
index 9c869b89af..03f28af074 100644
--- a/tests/fts/functions/snippet-3.out
+++ b/tests/fts/functions/snippet-3.out
@@ -1,4 +1,4 @@
 "http://www.example.org/test#1"	">>>bananas<<<..."
-"http://www.example.org/test#2"	">>>bananas<<< >>>bananas<<<..."
+"http://www.example.org/test#2"	">>>bananas<<<..."
 "http://www.example.org/test#4"	">>>bananas<<<..."
 "http://www.example.org/test#3"	">>>bananas<<<"
diff --git a/tests/fts/functions/snippet-4.out b/tests/fts/functions/snippet-4.out
index e3650f67a7..b7e42e2f17 100644
--- a/tests/fts/functions/snippet-4.out
+++ b/tests/fts/functions/snippet-4.out
@@ -1,4 +1,4 @@
 "http://www.example.org/test#1"	
-"http://www.example.org/test#2"	">>>bananas<<< >>>bananas<<<..."
-"http://www.example.org/test#4"	">>>bananas<<<..."
-"http://www.example.org/test#3"	">>>bananas<<<..."
+"http://www.example.org/test#2"	
+"http://www.example.org/test#4"	
+"http://www.example.org/test#3"	
diff --git a/tests/fts/functions/snippet-4.rq b/tests/fts/functions/snippet-4.rq
index 1b542b57c4..564f52d01e 100644
--- a/tests/fts/functions/snippet-4.rq
+++ b/tests/fts/functions/snippet-4.rq
@@ -1 +1 @@
-SELECT ?u fts:snippet(?u, '>>>', '<<<', '...', 0) { ?u fts:match 'bananas' } order by desc fts:rank(?u)
+SELECT ?u fts:snippet(?u, '>>>', '<<<', '...', -1) { ?u fts:match 'bananas' } order by desc fts:rank(?u)
diff --git a/tests/fts/functions/snippet-5.out b/tests/fts/functions/snippet-5.out
deleted file mode 100644
index b7e42e2f17..0000000000
--- a/tests/fts/functions/snippet-5.out
+++ /dev/null
@@ -1,4 +0,0 @@
-"http://www.example.org/test#1"	
-"http://www.example.org/test#2"	
-"http://www.example.org/test#4"	
-"http://www.example.org/test#3"	
diff --git a/tests/fts/functions/snippet-5.rq b/tests/fts/functions/snippet-5.rq
deleted file mode 100644
index 564f52d01e..0000000000
--- a/tests/fts/functions/snippet-5.rq
+++ /dev/null
@@ -1 +0,0 @@
-SELECT ?u fts:snippet(?u, '>>>', '<<<', '...', -1) { ?u fts:match 'bananas' } order by desc fts:rank(?u)
diff --git a/tests/fts/functions/snippet-data.rq b/tests/fts/functions/snippet-data.rq
index 2a8ffb1c08..5aa3006af9 100644
--- a/tests/fts/functions/snippet-data.rq
+++ b/tests/fts/functions/snippet-data.rq
@@ -1,6 +1,6 @@
 INSERT {
 	test:1 a test:A ; test:p "bananas lemons lemons" .
-	test:2 a test:A ; test:p "bananas bananas lemons" .
+	test:2 a test:A ; test:p "bananas bandanas lemons" .
 	test:3 a test:A ; test:o "bananas" .
 	test:4 a test:A ; test:p "bananas" ; test:o "bananas lemons" .
 
diff --git a/tests/fts/tracker-fts-test.c b/tests/fts/tracker-fts-test.c
index fd2308c4b8..4a1d6f5566 100644
--- a/tests/fts/tracker-fts-test.c
+++ b/tests/fts/tracker-fts-test.c
@@ -42,7 +42,7 @@ const TestInfo tests[] = {
 	{ "input/fts3input", 3 },
 	{ "functions/rank", 2 },
 	{ "functions/offsets", 3 },
-	{ "functions/snippet", 5 },
+	{ "functions/snippet", 4 },
 	{ NULL }
 };
 
-- 
GitLab

