Skip to content

Commit

Permalink
fix SPARQL function STRLEN
Browse files Browse the repository at this point in the history
  • Loading branch information
pchampin committed Dec 9, 2024
1 parent 501f0df commit 268f677
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion sparql/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ pub fn sub_str(
}

pub fn str_len(string: &Arc<str>) -> EvalResult {
let l = string.len();
let l = string.chars().count();
if l <= isize::MAX as usize {
SparqlNumber::from(l as isize).into()
} else {
Expand Down
12 changes: 8 additions & 4 deletions sparql/src/function/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ fn sub_str(source: &str, start: f64, length: Option<f64>, 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;
Expand All @@ -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")]
Expand All @@ -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 {
Expand Down

0 comments on commit 268f677

Please sign in to comment.