Skip to content

Commit

Permalink
Implement some Typst tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobjpeters committed Jun 9, 2024
1 parent 78eac7c commit e255725
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 24 deletions.
21 changes: 21 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ function save_test(filename, fig; kwargs...)

end

function render_texample(cached, document, url)

fig = Figure()

lt = LTeX(fig[1, 1], convert(CachedPDF, cached(document(read(Downloads.download(url), String), false))))

@test true

resize_to_layout!(fig)

filename = splitdir(splitext(url)[1])[2]

save_test(joinpath(@__DIR__, "test_images", "texample", filename), fig)


@test true

end


include("tex.jl")
include("typst.jl")
include("svg.jl")
include("pdf.jl")
29 changes: 5 additions & 24 deletions test/tex.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
using CairoMakie, MakieTeX
using Test, Downloads

function render_texample(url)

fig = Figure()

lt = LTeX(fig[1, 1], CachedTeX(TeXDocument(read(Downloads.download(url), String), false)))

@test true

resize_to_layout!(fig)

filename = splitdir(splitext(url)[1])[2]

save_test(joinpath(@__DIR__, "test_images", "texample", filename), fig)


@test true

end


@testset "TeX rendering" begin

can_access_texample = try
can_access_example = try
Downloads.download("https://texample.net/media/tikz/examples/TEX/rotated-triangle.tex")
true
catch e
false
@warn "Cannot access texample.net; skipping tests that require it."
end

can_access_texample && @testset "texample.net" begin
can_access_example && @testset "texample.net" begin

mkpath(joinpath(example_path, "texample"))

Expand All @@ -49,7 +29,8 @@ end
for name in names

@testset "$name" begin
render_texample("https://texample.net/media/tikz/examples/TEX/$name.tex")
render_texample(CachedTeX, TeXDocument,
"https://texample.net/media/tikz/examples/TEX/$name.tex")
end

end
Expand Down Expand Up @@ -251,4 +232,4 @@ end
end
=#
end
end
37 changes: 37 additions & 0 deletions test/typst.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using CairoMakie, MakieTeX
using Test, Downloads

url(name) = "https://raw.githubusercontent.com/typst/packages/main/packages/preview/cetz/0.2.2/gallery/$name.typ"

@testset "Typst rendering" begin

names = [
"karls-picture",
"tree",
"waves",
"pie-chart",
"plot",
"barchart"
]

can_access_example = try
_url = url(first(names))
Downloads.download(_url)
true
catch e
false
@warn "Cannot access $_url; skipping tests that require it."
end

can_access_example && @testset "cetz" begin

for name in names

@testset "$name" begin
render_texample(CachedTypst, TypstDocument, url(name))
end

end

end
end

0 comments on commit e255725

Please sign in to comment.