Skip to content

Commit

Permalink
Merge branch 'tests'
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Oct 30, 2018
2 parents 6f76b23 + 1a8e8df commit 7bd9840
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 32 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
language: julia
os:
- linux
- osx
julia:
- 0.7
- nightly
Expand All @@ -19,4 +18,4 @@ script:
# - julia -e 'Pkg.test("JuDoc")'
after_success:
# push coverage results to Codecov
- julia -e 'cd(Pkg.dir("JuDoc")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder()); Coveralls.submit(Codecov.process_folder())'
- julia -e 'cd(Pkg.dir("JuDoc")); Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
1 change: 0 additions & 1 deletion src/jd_vars.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ called every time a page is processed.
"""
def_LOC_VARS() = begin
empty!(JD_LOC_VARS)
JD_LOC_VARS["isdemo"] = Pair(false, (Bool,))
JD_LOC_VARS["title"] = Pair(nothing, (String, Nothing))
JD_LOC_VARS["hasmath"] = Pair(true, (Bool,))
JD_LOC_VARS["hascode"] = Pair(false, (Bool,))
Expand Down
8 changes: 4 additions & 4 deletions src/parser/find_tokens.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ function find_tokens(str::AbstractString, tokens_dict::Dict,
stack = subs(str, head_idx, endchar_idx)
if λ(stack)
# offset==True --> looked at 1 extra char (lookahead)
head_idx = endchar_idx - offset
head_idx = prevind(str, endchar_idx, offset)
push!(tokens, Token(case, chop(stack, tail=offset)))
# token identified, no need to check other cases.
break
end
else # rule-based match, greedy catch until fail
stack, shift = head, 1
nextchar_idx = head_idx + shift
nextchar_idx = nextind(str, head_idx)
while λ(shift, str[nextchar_idx])
stack = subs(str, head_idx, nextchar_idx)
shift += 1
nextchar_idx += 1
nextchar_idx = nextind(str, nextchar_idx)
end
endchar_idx = nextchar_idx - 1
endchar_idx = prevind(str, nextchar_idx)
if endchar_idx > head_idx
push!(tokens, Token(case, stack))
head_idx = endchar_idx
Expand Down
52 changes: 28 additions & 24 deletions test/jd_paths_vars.jl
Original file line number Diff line number Diff line change
@@ -1,46 +1,50 @@
const td = mktempdir() * "/"
JuDoc.JD_FOLDER_PATH[] = td
J.JD_FOLDER_PATH[] = td

JuDoc.def_GLOB_VARS()
JuDoc.def_GLOB_LXDEFS()
J.def_GLOB_VARS()
J.def_GLOB_LXDEFS()

@testset "Paths" begin
P = JuDoc.set_paths!()

@test JuDoc.JD_PATHS[:f] == td
@test JuDoc.JD_PATHS[:in] == td * "src/"
@test JuDoc.JD_PATHS[:in_css] == td * "src/_css/"
@test JuDoc.JD_PATHS[:in_html] == td * "src/_html_parts/"
@test JuDoc.JD_PATHS[:libs] == td * "libs/"
@test JuDoc.JD_PATHS[:out] == td * "pub/"
@test JuDoc.JD_PATHS[:out_css] == td * "css/"
@test P == JuDoc.JD_PATHS

mkdir(JuDoc.JD_PATHS[:in])
mkdir(JuDoc.JD_PATHS[:in_pages])
mkdir(JuDoc.JD_PATHS[:libs])
mkdir(JuDoc.JD_PATHS[:in_css])
mkdir(JuDoc.JD_PATHS[:in_html])
P = J.set_paths!()

@test J.JD_PATHS[:f] == td
@test J.JD_PATHS[:in] == td * "src/"
@test J.JD_PATHS[:in_css] == td * "src/_css/"
@test J.JD_PATHS[:in_html] == td * "src/_html_parts/"
@test J.JD_PATHS[:libs] == td * "libs/"
@test J.JD_PATHS[:out] == td * "pub/"
@test J.JD_PATHS[:out_css] == td * "css/"
@test P == J.JD_PATHS

mkdir(J.JD_PATHS[:in])
mkdir(J.JD_PATHS[:in_pages])
mkdir(J.JD_PATHS[:libs])
mkdir(J.JD_PATHS[:in_css])
mkdir(J.JD_PATHS[:in_html])
end

@testset "Set vars" begin
d = Dict{String, Pair{Any, Tuple}}(
"a" => 0.5 => (Real,),
"b" => "hello" => (String, Nothing))
JuDoc.set_vars!(d, ["a"=>"5", "b"=>"nothing"])
J.set_vars!(d, ["a"=>"5", "b"=>"nothing"])

@test d["a"].first == 5
@test d["b"].first == nothing
@test (@test_logs (:warn, "Doc var 'a' (type(s): (Real,)) can't be set to value 'blah' (type: String). Assignment ignored.") JuDoc.set_vars!(d, ["a"=>"\"blah\""])) == nothing
@test (@test_logs (:error, "I got an error (of type 'DomainError') trying to evaluate '__tmp__ = sqrt(-1)', fix the assignment.") JuDoc.set_vars!(d, ["a"=> "sqrt(-1)"])) == nothing
@test (@test_logs (:warn, "Doc var name 'blah' is unknown. Assignment ignored.") JuDoc.set_vars!(d, ["blah"=>"1"])) == nothing

@test_logs (:warn, "Doc var 'a' (type(s): (Real,)) can't be set to value 'blah' (type: String). Assignment ignored.") J.set_vars!(d, ["a"=>"\"blah\""])
@test_logs (:error, "I got an error (of type 'DomainError') trying to evaluate '__tmp__ = sqrt(-1)', fix the assignment.") J.set_vars!(d, ["a"=> "sqrt(-1)"])
@test_logs (:warn, "Doc var name 'blah' is unknown. Assignment ignored.") J.set_vars!(d, ["blah"=>"1"])
end


@testset "Def+coms" begin # see #78
st = raw"""
@def title = "blah" <!-- comment -->
@def hasmath = false
etc
"""
""" * J.EOS
(m, jdv) = J.convert_md(st)
@test jdv["title"].first == "blah"
@test jdv["hasmath"].first == false
end
2 changes: 1 addition & 1 deletion test/manager/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
JuDoc.process_config()
@test JuDoc.JD_GLOB_VARS["author"].first == "Stefan Zweig"
rm(temp_config)
@test (@test_logs (:warn, "I didn't find a config file. Ignoring.") JuDoc.process_config()) == nothing
@test_logs (:warn, "I didn't find a config file. Ignoring.") JuDoc.process_config()
# testing write
head = "head"
pg_foot = "\npage_foot"
Expand Down
55 changes: 55 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This is a test file to make codecov happy, technically all of the
# tests here are already done / integrated within other tests.

@testset "strings" begin
st = "blah"

@test J.str(st) == "blah"

sst = SubString("blahblah", 1:4)
@test sst == "blah"
@test J.str(sst) == "blahblah"

sst = SubString("blah✅💕and etcσ⭒ but ∃⫙∀ done", 1:27)
@test J.to(sst) == 27
end


@testset "ocblock" begin

st = "This is a block <!--comment--> and done"
τ = J.find_tokens(st, J.MD_TOKENS, J.MD_1C_TOKENS)
ocb = J.OCBlock(:COMMENT, (τ[1]=>τ[2]))
@test J.otok(ocb) == τ[1]
@test J.ctok(ocb) == τ[2]
end


@testset "isexactly" begin
steps, b, λ = J.isexactly("<!--")
@test steps == length("<!--") - 1 # minus start char
@test b == false
@test λ("<!--") == true
@test λ("<--") == false

steps, b, λ = J.isexactly("\$", ['\$'])
@test steps == 1
@test b == true
@test λ("\$\$") == true
@test λ("\$a") == false
@test λ("a\$") == false

rs = "\$"
steps, b, λ = J.isexactly(rs, ['\$'], false)
@test steps == nextind(rs, prevind(rs, lastindex(rs)))
@test b == true
@test λ("\$\$") == false
@test λ("\$a") == true
@test λ("a\$") == false

steps, b, λ = J.incrlook(isletter)
@test steps == 0
@test b == false
@test λ('c') == true
@test λ('[') == false
end
2 changes: 2 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const J = JuDoc
# saying that the key :in doesn't exist or something along those lines
include("jd_paths_vars.jl") # ✅ aug 16, 2018

include("misc.jl")

# MANAGER folder
include("manager/utils.jl") # ✅ oct 30, 2018
println("🍺")
Expand Down

0 comments on commit 7bd9840

Please sign in to comment.