diff --git a/LocalPreferences.toml b/LocalPreferences.toml new file mode 100644 index 0000000..36f185a --- /dev/null +++ b/LocalPreferences.toml @@ -0,0 +1,2 @@ +[Typstry] +instability_check = "error" diff --git a/docs/make.jl b/docs/make.jl index dbf1eee..f5597e7 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -4,9 +4,9 @@ using Dates: Dates, Date, DateTime, Day, Hour, Minute, Second, Time, Week using Documenter: Documenter, Docs, DocMeta, deploydocs, makedocs using .Docs: HTML, Text using .DocMeta: setdocmeta! -using LaTeXStrings: LaTeXStrings, LaTeXString, @L_str +using LaTeXStrings: LaTeXStrings, LaTeXString using Luxor: Drawing, finish, julia_blue, julia_green, julia_purple, julia_red, rect, sethue -using Markdown: Markdown, MD, @md_str +using Markdown: Markdown, MD using Typstry: _show_typst, enclose, join_with, preamble, typst_mime using Typstry diff --git a/readme.jl b/readme.jl index 571ff97..4b9bd3b 100644 --- a/readme.jl +++ b/readme.jl @@ -2,7 +2,7 @@ const delimiter = "## Introduction" write("README.md", "\n" * join(( - "", + "", read("HEADER.md", String), delimiter * replace( last(split(read("docs/source/index.md", String), delimiter)), diff --git a/test/TestAqua.jl b/test/TestAqua.jl new file mode 100644 index 0000000..6ea5b61 --- /dev/null +++ b/test/TestAqua.jl @@ -0,0 +1,12 @@ + +module TestAqua + +using Aqua: test_all, test_ambiguities +using Typstry + +function test() + test_all(Typstry; ambiguities = false) + test_ambiguities(Typstry) +end + +end # TestAqua diff --git a/test/TestDatesExtension.jl b/test/TestDatesExtension.jl new file mode 100644 index 0000000..c5f97a6 --- /dev/null +++ b/test/TestDatesExtension.jl @@ -0,0 +1,11 @@ + +module TestDatesExtension + +using Dates: Dates +using Typstry + +function test() + +end + +end # TestDatesExtension diff --git a/test/TestDocumenter.jl b/test/TestDocumenter.jl new file mode 100644 index 0000000..ada0286 --- /dev/null +++ b/test/TestDocumenter.jl @@ -0,0 +1,44 @@ + +module TestDocumenter + +using Base: get_extension, disable_logging +using Dates: Dates +using Documenter: DocMeta.setdocmeta!, doctest +using Logging: Debug, Info, disable_logging +using Markdown: Markdown +using LaTeXStrings: LaTeXStrings +using Preferences: set_preferences! +using Typstry + +const extensions = [:Dates, :LaTeXStrings, :Markdown] + +function _test(_module, x) + setdocmeta!(_module, :DocTestSetup, quote + using Preferences: set_preferences! + using Typstry + $x + + set_preferences!("Typstry", "instability_check" => "error") + end; recursive = true) + + # TODO: errors print twice + doctest(_module; manual = "source", testset = "`$_module` Doctests") +end + +function test() + set_preferences!("Typstry", "instability_check" => "error") + disable_logging(Info) + + _test(Typstry, nothing) + + for extension in extensions + _extension = Symbol(extension, "Extension") + _module = get_extension(Typstry, _extension) + + _test(_module, :(using $extension)) + end + + disable_logging(Debug) +end + +end # TestDocumenter diff --git a/test/TestExplicitImports.jl b/test/TestExplicitImports.jl new file mode 100644 index 0000000..9a2734f --- /dev/null +++ b/test/TestExplicitImports.jl @@ -0,0 +1,31 @@ + +module TestExplicitImports + +using ExplicitImports: + check_all_explicit_imports_are_public, + check_all_explicit_imports_via_owners, + check_all_qualified_accesses_are_public, + check_all_qualified_accesses_via_owners, + check_no_implicit_imports, + check_no_self_qualified_accesses, + check_no_stale_explicit_imports +using Test: @test +using Typstry + +function test() + @test isnothing(check_all_explicit_imports_are_public(Typstry; ignore = (:MD, :Stateful, + :code_mode, :depth, :escape_raw_string, :indent, :parse, :print_parameters, :show_raw, :workload))) + + for check in ( + check_all_explicit_imports_via_owners, + check_all_qualified_accesses_are_public, + check_all_qualified_accesses_via_owners, + check_no_implicit_imports, + check_no_self_qualified_accesses, + check_no_stale_explicit_imports + ) + @test isnothing(check(Typstry)) + end +end + +end # TestExplicitImports diff --git a/test/TestLaTeXStringsExtension.jl b/test/TestLaTeXStringsExtension.jl new file mode 100644 index 0000000..f7171fd --- /dev/null +++ b/test/TestLaTeXStringsExtension.jl @@ -0,0 +1,21 @@ + +module TestLaTeXStringsExtension + +using ..TestTypstry: test_modes, test_strings +using LaTeXStrings: @L_str +using Typstry + +const latex = L"a" + +function test() + # test_modes(latex, [ + # "```latex \$a\$ ```", + # "```latex \$a\$ ```", + # "#```latex \$a\$ ```" + # ]) + + # test_strings(latex, "````latex\n a\n \n ````"; + # backticks = 4, block = true, depth = 2, indent_size = 4) +end + +end # TestLaTeXStringsExtension diff --git a/test/TestMarkdownExtension.jl b/test/TestMarkdownExtension.jl new file mode 100644 index 0000000..e103733 --- /dev/null +++ b/test/TestMarkdownExtension.jl @@ -0,0 +1,21 @@ + +module TestMarkdownExtension + +using ..TestTypstry: test_modes, test_strings +using Markdown: Markdown +using Typstry + +const markdown = Markdown.parse("a\\\nb") + +function test() + # test_modes(markdown, [ + # "```markdown a\nb ```", + # "```markdown a\nb ```", + # "#```markdown a\nb ```" + # ]) + + # test_strings(markdown, "````markdown\n a \n b\n `````"; + # backticks = 4, block = true, depth = 2, indent_size = 4) +end + +end # TestMarkdownExtension diff --git a/test/runtests.jl b/test/runtests.jl index 87ed267..a915442 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,63 +1,29 @@ -using Aqua: test_all, test_ambiguities -using Base: get_extension, disable_logging -using ExplicitImports: - check_all_explicit_imports_are_public, - check_all_explicit_imports_via_owners, - check_all_qualified_accesses_are_public, - check_all_qualified_accesses_via_owners, - check_no_implicit_imports, - check_no_self_qualified_accesses, - check_no_stale_explicit_imports -using Dates: Dates -using Documenter: DocMeta.setdocmeta!, doctest -using LaTeXStrings: LaTeXStrings -using Logging: Debug, Info, disable_logging -using Markdown: Markdown -using Preferences: set_preferences! -using Test: @testset, @test using Typstry -_doctest(_module, name) = doctest(_module; manual = "source", testset = "$name.jl Doctests") +module TestTypstry -_setdocmeta!(_module, x) = setdocmeta!(_module, :DocTestSetup, - :(using Preferences: set_preferences!; using Typstry; $x; set_preferences!("Typstry", "instability_check" => "error")); -recursive = true) +using Test: @test, @testset -set_preferences!("Typstry", "instability_check" => "error") - -@testset "Aqua.jl" begin - test_all(Typstry; ambiguities = false) - test_ambiguities(Typstry) -end - -_setdocmeta!(Typstry, nothing) -disable_logging(Info) - -@testset "Doctests" begin - _doctest(Typstry, "Typstry") - - for extension in [:Dates, :LaTeXStrings, :Markdown] - _module = get_extension(Typstry, Symbol(extension, "Extension")) - _setdocmeta!(_module, :(using $extension)) - _doctest(_module, extension) +test_modes(x, ss) = @testset "modes" begin + for (mode, s) in zip(instances(Mode), ss) + test_strings(x, s; mode) end end -disable_logging(Debug) - -@testset "ExplicitImports.jl" begin - @test isnothing(check_all_explicit_imports_are_public(Typstry; ignore = (:MD, :Stateful, - :code_mode, :depth, :escape_raw_string, :indent, :parse, :print_parameters, :show_raw, :workload))) - - for check in ( - check_all_explicit_imports_via_owners, - check_all_qualified_accesses_are_public, - check_all_qualified_accesses_via_owners, - check_no_implicit_imports, - check_no_self_qualified_accesses, - check_no_stale_explicit_imports - ) - @test isnothing(check(Typstry)) +test_strings(x, s; kwargs...) = @test TypstString(x; kwargs...).text == s + +@testset "Typstry" begin + for description in [ + "Aqua", + "DatesExtension", + "Documenter", + "ExplicitImports", + "LaTeXStringsExtension", + "MarkdownExtension" + ] + @testset "$description" include("Test" * description * ".jl").test() end end + +end # TestTypstry