Skip to content

Commit

Permalink
Merge pull request #651 from JuliaSymbolics/occursin
Browse files Browse the repository at this point in the history
Fix occursin for needle as a number case
  • Loading branch information
ChrisRackauckas authored Sep 18, 2024
2 parents b959fd8 + 570b0d0 commit 0a25eac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/substitute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 needle isa Integer || needle isa AbstractFloat
isequal(needle, arg) && return true
else
occursin(needle, arg) && return true
end
end
end
return false
Expand Down
2 changes: 2 additions & 0 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a25eac

Please sign in to comment.