From 268f6770b15c11054cf9ad74d00c9e8e1151e9ac Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Champin Date: Mon, 9 Dec 2024 22:19:24 +0100 Subject: [PATCH] fix SPARQL function STRLEN --- sparql/src/function.rs | 2 +- sparql/src/function/test.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/sparql/src/function.rs b/sparql/src/function.rs index d65ea2a..d477273 100644 --- a/sparql/src/function.rs +++ b/sparql/src/function.rs @@ -331,7 +331,7 @@ pub fn sub_str( } pub fn str_len(string: &Arc) -> EvalResult { - let l = string.len(); + let l = string.chars().count(); if l <= isize::MAX as usize { SparqlNumber::from(l as isize).into() } else { diff --git a/sparql/src/function/test.rs b/sparql/src/function/test.rs index 75718d6..5717af0 100644 --- a/sparql/src/function/test.rs +++ b/sparql/src/function/test.rs @@ -190,6 +190,10 @@ fn sub_str(source: &str, start: f64, length: Option, exp: Option<&str>) -> #[test_case("foobar", 6)] #[test_case("foobar@en", 6)] +#[test_case("é", 1)] +#[test_case("é@fr", 1)] +#[test_case("⛄", 1; "snowman")] +#[test_case("⛄@en", 1; "snowman en")] fn str_len(string: &str, exp: isize) -> TestResult { let pair = txt2pair(string); let string = &pair.0; @@ -202,8 +206,8 @@ fn str_len(string: &str, exp: isize) -> TestResult { #[test_case("foo@en", "FOO@en")] #[test_case("FOO", "FOO"; "noop")] #[test_case("FOO@en", "FOO@en"; "noop en")] -#[test_case("fooBAR 1!xY", "FOOBAR 1!XY")] -#[test_case("fooBAR 1!xY@en", "FOOBAR 1!XY@en")] +#[test_case("fooBAR 1!⛄xY", "FOOBAR 1!⛄XY")] +#[test_case("fooBAR 1!⛄xY@en", "FOOBAR 1!⛄XY@en")] #[test_case("àéîôù", "ÀÉÎÔÙ"; "accents")] #[test_case("àéîôù@fr", "ÀÉÎÔÙ@fr"; "accents fr")] #[test_case("ff ʼn", "FF ʼN"; "multichar")] @@ -220,8 +224,8 @@ fn u_case(string: &str, exp: &str) -> TestResult { #[test_case("FOO@en", "foo@en")] #[test_case("foo", "foo"; "noop")] #[test_case("foo@en", "foo@en"; "noop en")] -#[test_case("fooBAR 1!xY", "foobar 1!xy")] -#[test_case("fooBAR 1!xY@en", "foobar 1!xy@en")] +#[test_case("fooBAR 1!⛄xY", "foobar 1!⛄xy")] +#[test_case("fooBAR 1!⛄xY@en", "foobar 1!⛄xy@en")] #[test_case("ÀÉÎÔÙ", "àéîôù"; "accents")] #[test_case("ÀÉÎÔÙ@fr", "àéîôù@fr"; "accents fr")] fn l_case(string: &str, exp: &str) -> TestResult {