From f1e6492dac6709eaf284759d8d874307c9e9d4b2 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 18 Sep 2024 16:16:50 +0200 Subject: [PATCH 1/4] Fix occursin --- src/substitute.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/substitute.jl b/src/substitute.jl index 8fc980c69..c0133ae01 100644 --- a/src/substitute.jl +++ b/src/substitute.jl @@ -51,11 +51,14 @@ Base.occursin(needle, haystack::Symbolic) = _occursin(needle, haystack) Base.occursin(needle::Symbolic, haystack) = _occursin(needle, haystack) function _occursin(needle, haystack) isequal(needle, haystack) && return true - if iscall(haystack) args = arguments(haystack) for arg in args - occursin(needle, arg) && return true + if arg isa Integer || arg isa AbstractFloat + isequal(arg, haystack) + else + occursin(needle, arg) && return true + end end end return false From a640136f806f159c3f6d8a7af4c03408c6911b06 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 18 Sep 2024 16:26:44 +0200 Subject: [PATCH 2/4] add test cases --- test/basics.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/basics.jl b/test/basics.jl index 70cf1819f..edf136315 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -184,6 +184,8 @@ end @test occursin(a, a + b) @test !occursin(sin(a), a + b + c) @test occursin(sin(a), a * b + c + sin(a^2 * sin(a))) + @test occursin(0.01, 0.01*a) + @test occursin(0.01, a * b * c) end @testset "printing" begin From 4bfde3e43653feda850824b0f33d30c397a0644a Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 18 Sep 2024 16:27:45 +0200 Subject: [PATCH 3/4] fix ordering --- src/substitute.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/substitute.jl b/src/substitute.jl index c0133ae01..828f88b14 100644 --- a/src/substitute.jl +++ b/src/substitute.jl @@ -54,8 +54,8 @@ function _occursin(needle, haystack) if iscall(haystack) args = arguments(haystack) for arg in args - if arg isa Integer || arg isa AbstractFloat - isequal(arg, haystack) + if needle isa Integer || needle isa AbstractFloat + isequal(needle, arg) && return true else occursin(needle, arg) && return true end From 570b0d008f2cce10d5d1b840527a0a93906f27b9 Mon Sep 17 00:00:00 2001 From: Christopher Rackauckas Date: Wed, 18 Sep 2024 17:09:02 +0200 Subject: [PATCH 4/4] fix basic test --- test/basics.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/basics.jl b/test/basics.jl index edf136315..024533c9e 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -185,7 +185,7 @@ end @test !occursin(sin(a), a + b + c) @test occursin(sin(a), a * b + c + sin(a^2 * sin(a))) @test occursin(0.01, 0.01*a) - @test occursin(0.01, a * b * c) + @test !occursin(0.01, a * b * c) end @testset "printing" begin