From 5c98bc09a8f2d9d9094d4425f93c265dcf6c83e5 Mon Sep 17 00:00:00 2001 From: Steffen Deusch Date: Thu, 17 Apr 2025 11:37:31 +0200 Subject: [PATCH 1/2] https://github.com/elixir-lang/elixir/pull/14448 --- test/stdlib/string_test.exs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/stdlib/string_test.exs b/test/stdlib/string_test.exs index 375d709..238fbd0 100644 --- a/test/stdlib/string_test.exs +++ b/test/stdlib/string_test.exs @@ -25,4 +25,15 @@ defmodule StreamData.StringTest do end end end + + if Version.match?(System.version(), "~> 1.19.0-dev") do + # From https://github.com/elixir-lang/elixir/pull/14448. + property "String.count_matches/2 is equivalent to String.split/1 + Kernel.length/1 - 1" do + check all string <- string(:printable), + pattern <- string(:printable) do + assert String.count_matches(string, pattern) == + string |> String.split(pattern) |> Kernel.length() |> Kernel.-(1) + end + end + end end From cfe7d53b3ee8e5f5515a7b4d8c44d10c35db7ce4 Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sun, 12 Jul 2026 10:29:34 +0200 Subject: [PATCH 2/2] FIXUP --- test/stdlib/string_test.exs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/stdlib/string_test.exs b/test/stdlib/string_test.exs index 238fbd0..9e911a9 100644 --- a/test/stdlib/string_test.exs +++ b/test/stdlib/string_test.exs @@ -26,12 +26,13 @@ defmodule StreamData.StringTest do end end - if Version.match?(System.version(), "~> 1.19.0-dev") do + # TODO: Make this unconditional when we depend on Elixir 1.20+. + if function_exported?(String, :count, 2) do # From https://github.com/elixir-lang/elixir/pull/14448. - property "String.count_matches/2 is equivalent to String.split/1 + Kernel.length/1 - 1" do + property "String.count/2 is equivalent to String.split/2 + Kernel.length/1 - 1" do check all string <- string(:printable), pattern <- string(:printable) do - assert String.count_matches(string, pattern) == + assert String.count(string, pattern) == string |> String.split(pattern) |> Kernel.length() |> Kernel.-(1) end end