Skip to content

Commit

Permalink
fix ambiguous getindex; closes #61 (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranocha committed Jun 22, 2022
1 parent 94a24a8 commit a84e05a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/LaTeXStrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Base.getindex(s::LaTeXString, i::Int) = getindex(s.s, i) # for method ambig in J
Base.getindex(s::LaTeXString, i::UnitRange{Int}) = getindex(s.s, i)
Base.getindex(s::LaTeXString, i::UnitRange{<:Integer}) = getindex(s.s, i)
Base.getindex(s::LaTeXString, i::AbstractVector{<:Integer}) = getindex(s.s, i)
Base.getindex(s::LaTeXString, i::AbstractVector{Bool}) = getindex(s.s, i) # for method ambiguity
Base.codeunit(s::LaTeXString, i::Integer) = codeunit(s.s, i)
Base.codeunit(s::LaTeXString) = codeunit(s.s)
Base.ncodeunits(s::LaTeXString) = ncodeunits(s.s)
Expand Down
15 changes: 15 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ end
)
end

@testset "indexing" begin
tst1 = L"an equation: $\alpha^2$"
tst1s = String(tst1)

@test tst1[5] == tst1s[5]
@test tst1[15] == tst1s[15]

idx = [5, 10, 15]
@test tst1[idx] == tst1s[idx]

# issue #61
idx = rand(Bool, length(tst1))
@test_throws ArgumentError tst1[idx]
end

using Documenter
DocMeta.setdocmeta!(LaTeXStrings, :DocTestSetup, :(using LaTeXStrings); recursive=true)
doctest(LaTeXStrings; manual = false)

0 comments on commit a84e05a

Please sign in to comment.