Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test TOML #1012

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ jobs:
- julia --project -e 'using Pkg; Pkg.activate("docs"); Pkg.instantiate(); Pkg.develop(PackageSpec(path = pwd()))'
- julia --project=docs --color=yes docs/make.jl
after_success: skip
- name: TOML (Julia 1.0)
stage: test
os: linux
iamed2 marked this conversation as resolved.
Show resolved Hide resolved
julia: 1.0
script:
- julia --project=ext/TOML -e 'using Pkg; Pkg.test()'
after_success: skip
- name: TOML (Julia nightly)
stage: test
os: linux
julia: nightly
script:
- julia --project=ext/TOML -e 'using Pkg; Pkg.test()'
after_success: skip

after_success:
- julia --project -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())'
Expand Down
12 changes: 12 additions & 0 deletions ext/TOML/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name = "TOML"
uuid = "037cace4-c66a-5006-a6b7-c26ba1b2f83e"
desc = "The TOML parser for Julia's package manager"

[deps]
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
8 changes: 4 additions & 4 deletions ext/TOML/src/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function linecol(p::Parser, offset::Int)
seekstart(p.input)
line = 0
cur = 1
for (i,l) in enumerate(eachline(p.input, chomp=false))
for (i,l) in enumerate(eachline(p.input, keep=true))
if cur + length(l) > offset
return (i, offset - cur + 1)
end
Expand Down Expand Up @@ -388,11 +388,11 @@ function numdatetime(p::Parser, st::Int)
input = if isnull(decimal) && isnull(exponent) #!isfloat
prefix
elseif !isnull(decimal) && isnull(exponent)
"$(prefix)."*get(decimal,"")
"$(prefix)."*get(decimal)
elseif isnull(decimal) && !isnull(exponent)
"$(prefix)E"*get(exponent,"")
"$(prefix)E"*get(exponent)
elseif !isnull(decimal) && !isnull(exponent)
"$(prefix)."*get(decimal,"")*"E"*get(exponent,"")
"$(prefix)."*get(decimal)*"E"*get(exponent)
end
input = lstrip(input, '+')
try
Expand Down
4 changes: 4 additions & 0 deletions ext/TOML/src/print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ printvalue(io::IO, value::DateTime; sorted=false) =
Base.print(io, Dates.format(value, dateformat"YYYY-mm-dd\THH:MM:SS.sss\Z"))
printvalue(io::IO, value::Bool; sorted=false) =
Base.print(io, value ? "true" : "false")
printvalue(io::IO, value::Integer; sorted=false) =
Base.print(io, Int(value)) # TOML specifies 64-bit signed long range for integer
printvalue(io::IO, value::AbstractFloat; sorted=false) =
Base.print(io, Float64(value)) # TOML specifies IEEE 754 binary64 for float
printvalue(io::IO, value; sorted=false) =
Base.print(io, "\"$(escape_string(string(value)))\"")

Expand Down
41 changes: 22 additions & 19 deletions ext/TOML/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ using TOML
import TOML: linecol, whitespace, comment, newline, expect, lookup, Parser, parse

using Test
using Dates

macro testval(s, v)
f = "foo = $s"
:( @test get(parse(Parser($f)))["foo"] == $v )
:( @test TOML.get(parse(Parser($f)))["foo"] == $v )
end

macro fail(s...)
Expand Down Expand Up @@ -40,9 +41,9 @@ macro fail(s...)
println(e)
end
end
if !isnull($ppvar)
if !TOML.isnull($ppvar)
println("RESULT:")
println(get($ppvar))
println(TOML.get($ppvar))
end
end
else
Expand All @@ -64,7 +65,7 @@ macro fail(s...)
local $ppvar = parse($pvar)
$dbgexp
$errtsts
@test isnull($ppvar)
@test TOML.isnull($ppvar)
end
end

Expand All @@ -89,9 +90,9 @@ macro success(s...)
println(e)
end
end
if !isnull($ppvar)
if !TOML.isnull($ppvar)
println("RESULT:")
println(get($ppvar))
println(TOML.get($ppvar))
end
end
else
Expand All @@ -102,11 +103,12 @@ macro success(s...)
local $pvar = Parser($teststr)
local $ppvar = parse($pvar)
$dbgexp
@test !isnull($ppvar)
@test !TOML.isnull($ppvar)
end
end

@testset "TOML parser" begin
@testset "TOML" begin
@testset "Parser" begin

@testset "Parser internal functions" begin
test = """
Expand All @@ -129,15 +131,15 @@ end

@testset "Lookups" begin
p = Parser("""hello."world\\t".a.0.'escaped'.value""")
@testset for (p, s) in zip(get(lookup(p)), ["hello"; "world\t"; "a"; "0"; "escaped"; "value"])
@testset for (p, s) in zip(TOML.get(lookup(p)), ["hello"; "world\t"; "a"; "0"; "escaped"; "value"])
@test p == s
end

p = Parser("")
@test get(lookup(p)) == String[]
@test TOML.get(lookup(p)) == String[]

p = Parser("value")
@test get(lookup(p)) == String["value"]
@test TOML.get(lookup(p)) == String["value"]

p = Parser("\"\"")
#TODO: @test get(lookup(p)) == String[""]
Expand Down Expand Up @@ -189,7 +191,7 @@ bbb = \"aaa\"\r
foo = \"\"\"\\\r\n\"\"\"
bar = \"\"\"\\\r\n \r\n \r\n a\"\"\"
")
res = get(parse(p))
res = TOML.get(parse(p))
@test res["foo"] == ""
@test res["bar"] == "a"

Expand Down Expand Up @@ -265,7 +267,7 @@ trimmed in raw strings.
is preserved.
'''
""")
res = get(parse(p))
res = TOML.get(parse(p))

@test res["bar"] == "\0"
@test res["key1"] == "One\nTwo"
Expand Down Expand Up @@ -389,7 +391,7 @@ trimmed in raw strings.
\"character encoding\" = \"value\"
'ʎǝʞ' = \"value\"
")
res = get(parse(p))
res = TOML.get(parse(p))

@test haskey(res, "foo")
@test haskey(res, "-")
Expand Down Expand Up @@ -439,7 +441,7 @@ trimmed in raw strings.
['a.a']
['\"\"']
")
res = get(parse(p))
res = TOML.get(parse(p))
@test haskey(res, "a.a")
@test haskey(res, "f f")
@test haskey(res, "f.f")
Expand All @@ -448,7 +450,7 @@ trimmed in raw strings.
@test haskey(res["a"], "b")


@test haskey(get(parse(Parser("[foo]"))), "foo")
@test haskey(TOML.get(parse(Parser("[foo]"))), "foo")


@testset "Inline Tables" begin
Expand Down Expand Up @@ -546,7 +548,7 @@ trimmed in raw strings.
[foo.bar]
#...
""")
res = get(parse(p))
res = TOML.get(parse(p))
@test haskey(res, "foo")
arr = res["foo"]
@test length(arr) == 2
Expand All @@ -569,7 +571,7 @@ trimmed in raw strings.
[[fruit.variety]]
name = "plantain"
""")
res = get(parse(p))
res = TOML.get(parse(p))
@test haskey(res, "fruit")
fruit = res["fruit"]
@test length(fruit) == 2
Expand Down Expand Up @@ -623,7 +625,7 @@ color = "gray"

end

@testset "TOML printer" begin
@testset "Printer" begin
res1 = TOML.parse("""
title = "TOML Example"
[owner]
Expand Down Expand Up @@ -667,3 +669,4 @@ data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers supp
@test res1 == res2

end
end