Skip to content

Commit 896d4bc

Browse files
committed
revert encode of string objects for non-text formats
It has no practical usage except that it's conceptually right.
1 parent fe29f97 commit 896d4bc

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/fileio.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,11 @@ If needed, encode `x` to a valid content that matches format `T`.
5252
If there is no known method to encode `x`, then it directly return `x` without warning.
5353
"""
5454
maybe_encode(::Type{<:DataFormat}, x; kw...) = x
55-
maybe_encode(::Type{<:DataFormat}, x::AbstractString; kw...) = _ignore_crlf(x)
56-
maybe_encode(::Type{<:DataFormat}, x::AbstractArray{<:AbstractString}; kw...) = _join(x)
5755

5856
# plain TXT
5957
maybe_encode(::Type{DataFormat{:TXT}}, x; kw...) = _ignore_crlf(string(x))
60-
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractArray{<:AbstractString}; kw...) = _join(x) # ambiguity patch
61-
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractString; kw...) = _ignore_crlf(x) # ambiguity patch
58+
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractArray{<:AbstractString}; kw...) = _join(x)
59+
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractString; kw...) = _ignore_crlf(x)
6260
maybe_encode(::Type{DataFormat{:TXT}}, x::Number; kw...) = x # TODO: Change this to string(x) ?
6361

6462
function maybe_encode(

test/fileio.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,18 @@ end
4040
str4_arr = ["Hello\n\r world1", "Hello\n world2"]
4141

4242
# string as plain text
43-
for fmt in (format"TXT", format"UNKNOWN")
44-
# convert should respect whitespaces
45-
@test str1 == ReferenceTests.maybe_encode(fmt, str1)
46-
@test str2 == ReferenceTests.maybe_encode(fmt, str2)
47-
# but ignore CRLF/LF differences
48-
@test str2 == ReferenceTests.maybe_encode(fmt, str2_crlf)
49-
# string arrays are treated as multi-line strings, even for UNKNOWN format
50-
@test str3 == ReferenceTests.maybe_encode(fmt, str3)
51-
@test str3 == ReferenceTests.maybe_encode(fmt, str3_arr1)
52-
@test str3 == ReferenceTests.maybe_encode(fmt, str3_arr2)
53-
# string arrays should ignore CRLF/LF differences, too
54-
@test str4 == ReferenceTests.maybe_encode(fmt, str4_arr)
55-
end
43+
fmt = format"TXT"
44+
# convert should respect whitespaces
45+
@test str1 == ReferenceTests.maybe_encode(fmt, str1)
46+
@test str2 == ReferenceTests.maybe_encode(fmt, str2)
47+
# but ignore CRLF/LF differences
48+
@test str2 == ReferenceTests.maybe_encode(fmt, str2_crlf)
49+
# string arrays are treated as multi-line strings, even for UNKNOWN format
50+
@test str3 == ReferenceTests.maybe_encode(fmt, str3)
51+
@test str3 == ReferenceTests.maybe_encode(fmt, str3_arr1)
52+
@test str3 == ReferenceTests.maybe_encode(fmt, str3_arr2)
53+
# string arrays should ignore CRLF/LF differences, too
54+
@test str4 == ReferenceTests.maybe_encode(fmt, str4_arr)
5655

5756
# string as SHA256 should also ignore CRLF/LF differences
5857
fmt = format"SHA256"
@@ -66,6 +65,12 @@ end
6665
@test str3_sha256 == ReferenceTests.maybe_encode(fmt, str3_arr2)
6766
# string arrays should ignore CRLF/LF differences, too
6867
@test str4_sha256 == ReferenceTests.maybe_encode(fmt, str4_arr)
68+
69+
# unknown formats
70+
fmt = format"PNG"
71+
for str in (str1, str2, str2_crlf, str3, str3_arr1, str3_arr2)
72+
@test str === ReferenceTests.maybe_encode(fmt, str)
73+
end
6974
end
7075

7176
@testset "numbers" begin

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test_files = [
3030
include("testutils.jl")
3131

3232
@testset "ReferenceTests" begin
33-
@test_broken Set(setdiff(ambs, refambs)) == Set{Tuple{Method,Method}}()
33+
@test Set(setdiff(ambs, refambs)) == Set{Tuple{Method,Method}}()
3434

3535
for file in test_files
3636
filename = first(splitext(file))

0 commit comments

Comments
 (0)