From 160ff3a8144ab8108c29fad6e0502210ccfb585f Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Wed, 23 Jan 2019 16:58:50 -0600 Subject: [PATCH 1/4] Fix parsing numbers in TOML --- ext/TOML/src/parser.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/TOML/src/parser.jl b/ext/TOML/src/parser.jl index af88afa20f..a35c2776a8 100644 --- a/ext/TOML/src/parser.jl +++ b/ext/TOML/src/parser.jl @@ -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 From d60fa607e01d6b7ebffe60dde54d04d4f01feafd Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Wed, 23 Jan 2019 18:02:46 -0600 Subject: [PATCH 2/4] Fix up TOML for modern Julia --- ext/TOML/src/parser.jl | 2 +- ext/TOML/test/runtests.jl | 41 +++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/ext/TOML/src/parser.jl b/ext/TOML/src/parser.jl index a35c2776a8..d1f3ab7946 100644 --- a/ext/TOML/src/parser.jl +++ b/ext/TOML/src/parser.jl @@ -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 diff --git a/ext/TOML/test/runtests.jl b/ext/TOML/test/runtests.jl index 1136e5881d..d15b5b50dd 100644 --- a/ext/TOML/test/runtests.jl +++ b/ext/TOML/test/runtests.jl @@ -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...) @@ -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 @@ -64,7 +65,7 @@ macro fail(s...) local $ppvar = parse($pvar) $dbgexp $errtsts - @test isnull($ppvar) + @test TOML.isnull($ppvar) end end @@ -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 @@ -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 = """ @@ -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[""] @@ -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" @@ -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" @@ -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, "-") @@ -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") @@ -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 @@ -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 @@ -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 @@ -623,7 +625,7 @@ color = "gray" end -@testset "TOML printer" begin +@testset "Printer" begin res1 = TOML.parse(""" title = "TOML Example" [owner] @@ -667,3 +669,4 @@ data = [ ["gamma", "delta"], [1, 2] ] # just an update to make sure parsers supp @test res1 == res2 end +end From 56d18f12b19259ff2c999a57ff5c6cfa2fadcebb Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Wed, 23 Jan 2019 18:03:45 -0600 Subject: [PATCH 3/4] Fix number printing --- ext/TOML/src/print.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/TOML/src/print.jl b/ext/TOML/src/print.jl index 49e8bf29e2..37c3c5b7bc 100644 --- a/ext/TOML/src/print.jl +++ b/ext/TOML/src/print.jl @@ -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)))\"") From d044e1cc18b8e553a076726a82ea5ebddca32920 Mon Sep 17 00:00:00 2001 From: Eric Davies Date: Wed, 23 Jan 2019 18:04:34 -0600 Subject: [PATCH 4/4] Test TOML --- .travis.yml | 7 +++++++ ext/TOML/Project.toml | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 ext/TOML/Project.toml diff --git a/.travis.yml b/.travis.yml index 36fca217f3..e888b1304d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -44,6 +44,13 @@ 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 + include: + - name: TOML + stage: test + os: linux + script: + - julia -e 'using Pkg; Pkg.develop(PackageSpec(path="ext/TOML")); Pkg.instantiate(); Pkg.test("TOML")' + after_success: skip after_success: - julia --project -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Codecov.submit(Codecov.process_folder())' diff --git a/ext/TOML/Project.toml b/ext/TOML/Project.toml new file mode 100644 index 0000000000..7f7235f26f --- /dev/null +++ b/ext/TOML/Project.toml @@ -0,0 +1,12 @@ +name = "TOML" +desc = "The TOML parser for Julia's package manager" +uuid = "7ab3959e-fc62-457a-88b7-ddb939818b44" # this is fake + +[deps] +Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[extras] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[targets] +test = ["Test"]