update tests:

- create new test_inline.jl
- add tests to check inline code parser handlers unicode correctly
- create end2end.jl, which temporarily keeps old end2end tests
pull/349/head
Shuhei Kadowaki 2020-05-24 20:52:53 +09:00
parent eca4ed2559
commit b62a744dfe
4 changed files with 129 additions and 51 deletions

18
test/end2end.jl Normal file
View File

@ -0,0 +1,18 @@
# NOTE
# this file keeps old end2end tests, which are very fragile
# - they are being gradually replaced with unit tests, that are much more maintainable and
# much more helpful for detecting bugs
# - the purpose of this file is to temporarily keep the old end2end tests in a way that
# they're allowed to fail
tpl = mt"""
{{{ :body }}}
"""
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2html", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2tex", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)

View File

@ -1,47 +0,0 @@
using Mustache
# Test parsing
doc = """
! println("Something")
Some markdown with inline stuff and `j code`
! Not julia code but `j show("is")`
"""
ms = collect(eachmatch(Weave.INLINE_REGEXES, doc))
@test ms[1][2] == "println(\"Something\")"
@test ms[2][1] == "code"
@test ms[3][1] == "show(\"is\")"
let
_, chunks = Weave.parse_markdown(doc)
chunk = first(chunks)
@test length(chunk.content) == 7
@test chunk.content[2].content == ms[1][2]
@test chunk.content[4].content == ms[2][1]
@test chunk.content[6].content == ms[3][1]
end
let
_, chunks = Weave.parse_markdown(doc)
chunk = first(chunks)
@test all([chunk.content[i].content == chunk.content[i].content for i in 1:7])
end
# Test with document
tpl = mt"""
{{{ :body }}}
"""
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2html", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2tex", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)

View File

@ -28,6 +28,10 @@ macro jmd_str(s) mock_doc(s) end
include("test_header.jl")
end
@testset "inline" begin
include("test_inline.jl")
end
@testset "error rendering" begin
include("test_error_rendering.jl")
end
@ -62,12 +66,16 @@ macro jmd_str(s) mock_doc(s) end
include("gadfly_formats.jl")
end
@testset "Inline code" begin
include("inline_test.jl")
end
# @testset "Notebooks" begin
# @info("Testing Jupyter options")
# include("notebooks.jl")
# end
try
@testset "end2end (maybe fail)" begin
include("end2end.jl")
end
catch err
@error err
end
end

99
test/test_inline.jl Normal file
View File

@ -0,0 +1,99 @@
# TODO: test evaluation
using Weave.Mustache
using Weave: parse_inlines, InlineText, InlineCode
@testset "`parse_inlines` basic" begin
@test filter(parse_inlines("text")) do chunk
chunk isa InlineCode
end |> isempty
@test filter(parse_inlines("text")) do chunk
chunk isa InlineText &&
chunk.content == "text"
end |> length === 1
@test filter(parse_inlines("`j code`")) do chunk
chunk isa InlineCode &&
chunk.ctype === :inline &&
chunk.content == "code"
end |> length == 1
@test filter(parse_inlines("! code")) do chunk
chunk isa InlineCode &&
chunk.ctype === :line &&
chunk.content == "code"
end |> length == 1
@test filter(parse_inlines("text ! maybe_intended_to_be_code")) do chunk # invalid inline chunk
chunk isa InlineText &&
chunk.content == "maybe_intended_to_be_code"
end |> isempty
end
@testset "`parse_inlines` multiple lines" begin
str = """
- item1
- `j code`
- item2
"""
chunks = parse_inlines(str)
let chunk = chunks[1]
@test chunk isa InlineText
@test occursin("- item1", chunk.content)
end
let chunk = chunks[2]
@test chunk isa InlineCode
@test occursin("code", chunk.content)
end
let chunk = chunks[3]
@test chunk isa InlineText
@test occursin("- item2", chunk.content)
end
end
@testset "`parse_inlines` unicode handling" begin
str = """
- eng1 `j :eng1`
- eng2`j :eng2`
- 日本語1 `j :日本語1`
- 日本語2`j :日本語2`
"""
chunks = parse_inlines(str)
@test filter(chunks) do chunk
chunk isa InlineCode &&
chunk.number === 1 &&
chunk.content == ":eng1"
end |> length === 1
@test filter(chunks) do chunk
chunk isa InlineCode &&
chunk.number === 2 &&
chunk.content == ":eng2"
end |> length === 1
@test filter(chunks) do chunk
chunk isa InlineCode &&
chunk.number === 3 &&
chunk.content == ":日本語1"
end |> length === 1
@test filter(chunks) do chunk
chunk isa InlineCode &&
chunk.number === 4 &&
chunk.content == ":日本語2"
end |> length === 1
end