Skip to content

Commit 810e306

Browse files
committed
Fix tests and deprecations on Julia 0.6
Also drop pre-0.5 compatibility code.
1 parent c42ee6f commit 810e306

File tree

5 files changed

+47
-30
lines changed

5 files changed

+47
-30
lines changed

REQUIRE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
julia 0.5
22
BinDeps
3-
Compat 0.9.5
3+
Compat 0.17.0
44
@windows WinRPM
55
LegacyStrings 0.1.1

deps/build.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ end
3434
libiconv = library_dependency("libiconv", aliases = ["libc", "iconv"],
3535
validate = validate_iconv)
3636

37-
@windows_only begin
37+
if is_windows()
3838
using WinRPM
3939
provides(WinRPM.RPM, "win_iconv-dll", libiconv, os = :Windows)
4040
end

src/StringEncodings.jl

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module StringEncodings
44
using Base.Libc: errno, strerror, E2BIG, EINVAL, EILSEQ
5-
using Compat: String, ASCIIString, UTF8String, view
5+
using Compat: @compat
66

77
import Base: close, eachline, eof, flush, isreadable, iswritable,
88
open, readline, readlines, readuntil, show, write
@@ -16,24 +16,24 @@ include("encodings.jl")
1616
using StringEncodings.Encodings
1717
export encoding, encodings_list, Encoding, @enc_str
1818

19-
abstract StringEncodingError
19+
@compat abstract type StringEncodingError end
2020

2121
# Specified encodings or the combination are not supported by iconv
2222
type InvalidEncodingError <: StringEncodingError
23-
args::Tuple{ASCIIString, ASCIIString}
23+
args::Tuple{String, String}
2424
end
2525
InvalidEncodingError(from, to) = InvalidEncodingError((from, to))
2626
message(::Type{InvalidEncodingError}) = "Conversion from <<1>> to <<2>> not supported by iconv implementation, check that specified encodings are correct"
2727

2828
# Encountered invalid byte sequence
2929
type InvalidSequenceError <: StringEncodingError
30-
args::Tuple{ASCIIString}
30+
args::Tuple{String}
3131
end
3232
InvalidSequenceError(seq::Vector{UInt8}) = InvalidSequenceError((bytes2hex(seq),))
3333
message(::Type{InvalidSequenceError}) = "Byte sequence 0x<<1>> is invalid in source encoding or cannot be represented in target encoding"
3434

3535
type IConvError <: StringEncodingError
36-
args::Tuple{ASCIIString, Int, ASCIIString}
36+
args::Tuple{String, Int, String}
3737
end
3838
IConvError(func::String) = IConvError((func, errno(), strerror(errno())))
3939
message(::Type{IConvError}) = "<<1>>: <<2>> (<<3>>)"
@@ -434,16 +434,30 @@ Methods to read text in character encoding `enc`.
434434
readuntil(s::IO, enc::Encoding, delim) = readuntil(StringDecoder(s, enc), delim)
435435
readuntil(filename::AbstractString, enc::Encoding, delim) = open(io->readuntil(io, enc, delim), filename)
436436

437-
"""
438-
eachline(stream::IO, enc::Encoding)
439-
eachline(filename::AbstractString, enc::Encoding)
440-
441-
Methods to read text in character encoding `enc`. Decoding is performed on the fly.
442-
"""
443-
eachline(s::IO, enc::Encoding) = eachline(StringDecoder(s, enc))
444-
function eachline(filename::AbstractString, enc::Encoding)
445-
s = open(filename, enc)
446-
EachLine(s, ()->close(s))
437+
if VERSION >= v"0.6.0-dev.2467"
438+
"""
439+
eachline(stream::IO, enc::Encoding; chomp=true)
440+
eachline(filename::AbstractString, enc::Encoding; chomp=true)
441+
442+
Methods to read text in character encoding `enc`. Decoding is performed on the fly.
443+
"""
444+
eachline(s::IO, enc::Encoding; chomp=true) = eachline(StringDecoder(s, enc); chomp=true)
445+
function eachline(filename::AbstractString, enc::Encoding; chomp=true)
446+
s = open(filename, enc)
447+
EachLine(s, ondone=()->close(s), chomp=chomp)
448+
end
449+
else
450+
"""
451+
eachline(stream::IO, enc::Encoding)
452+
eachline(filename::AbstractString, enc::Encoding)
453+
454+
Methods to read text in character encoding `enc`. Decoding is performed on the fly.
455+
"""
456+
eachline(s::IO, enc::Encoding) = eachline(StringDecoder(s, enc))
457+
function eachline(filename::AbstractString, enc::Encoding)
458+
s = open(filename, enc)
459+
EachLine(s, ()->close(s))
460+
end
447461
end
448462

449463

@@ -471,8 +485,8 @@ end
471485

472486
decode{T<:AbstractString}(::Type{T}, a::Vector{UInt8}, enc::AbstractString) = decode(T, a, Encoding(enc))
473487

474-
decode(a::Vector{UInt8}, enc::AbstractString) = decode(UTF8String, a, Encoding(enc))
475-
decode(a::Vector{UInt8}, enc::Union{AbstractString, Encoding}) = decode(UTF8String, a, enc)
488+
decode(a::Vector{UInt8}, enc::AbstractString) = decode(String, a, Encoding(enc))
489+
decode(a::Vector{UInt8}, enc::Union{AbstractString, Encoding}) = decode(String, a, enc)
476490

477491
"""
478492
encode(s::AbstractString, enc)

src/encodings.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
module Encodings
66

7-
using Compat
87
import Base: show, print, convert
98
export encoding, encodings_list, Encoding, @enc_str
109

11-
if VERSION >= v"0.5.0-"
12-
using LegacyStrings: ASCIIString, UTF8String, UTF16String, UTF32String
13-
end
10+
using LegacyStrings: ASCIIString, UTF8String, UTF16String, UTF32String
1411

1512
immutable Encoding{enc} end
1613

@@ -26,10 +23,7 @@ print{enc}(io::IO, ::Encoding{enc}) = print(io, enc)
2623

2724

2825
## Get the encoding used by a string type
29-
if VERSION >= v"0.5.0-"
30-
encoding(::Type{String}) = enc"UTF-8"
31-
end
32-
26+
encoding(::Type{String}) = enc"UTF-8"
3327
encoding(::Type{ASCIIString}) = enc"ASCII"
3428
encoding(::Type{UTF8String}) = enc"UTF-8"
3529

test/runtests.jl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,24 @@ mktemp() do path, io
158158
@test readuntil(path, enc"ISO-2022-JP", "チャ") == "a string \0チャ"
159159
@test open(io->readuntil(io, enc"ISO-2022-JP", "チャ"), path) == "a string \0チャ"
160160

161-
@test readline(path, enc"ISO-2022-JP") == string(split(s, '\n')[1], '\n')
162-
@test open(readline, path, enc"ISO-2022-JP") == string(split(s, '\n')[1], '\n')
161+
if VERSION >= v"0.6.0-dev.2467"
162+
@test readline(path, enc"ISO-2022-JP") == split(s, '\n')[1]
163+
@test open(readline, path, enc"ISO-2022-JP") == split(s, '\n')[1]
164+
else
165+
@test readline(path, enc"ISO-2022-JP") == string(split(s, '\n')[1], '\n')
166+
@test open(readline, path, enc"ISO-2022-JP") == string(split(s, '\n')[1], '\n')
167+
end
163168
a = readlines(path, enc"ISO-2022-JP")
164169
b = open(readlines, path, enc"ISO-2022-JP")
165170

166171
c = collect(eachline(path, enc"ISO-2022-JP"))
167172
d = open(io->collect(eachline(io, enc"ISO-2022-JP")), path)
168173

169-
@test a[1] == b[1] == c[1] == d[1] == string(split(s, '\n')[1], '\n')
174+
if VERSION >= v"0.6.0-dev.2467"
175+
@test a[1] == b[1] == c[1] == d[1] == split(s, '\n')[1]
176+
else
177+
@test a[1] == b[1] == c[1] == d[1] == string(split(s, '\n')[1], '\n')
178+
end
170179
@test a[2] == b[2] == c[2] == d[2] == split(s, '\n')[2]
171180

172181
# Test alternative syntaxes for open()

0 commit comments

Comments
 (0)