Skip to content

Commit 8e815ff

Browse files
authored
Merge pull request #249 from JuliaLang/fix-string-tests
fix tests to work with #16590
2 parents 679b0ec + 09e51bc commit 8e815ff

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

test/runtests.jl

+31-26
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ end
285285
# Test unsafe_convert
286286
type A; end
287287
x = "abc"
288-
@test @compat String(Compat.unsafe_convert(Ptr{UInt8}, x)) == x
288+
@test @compat String(unsafe_string(Compat.unsafe_convert(Ptr{UInt8}, x))) == x
289289
Compat.unsafe_convert(::Ptr{A}, x) = x
290290
@test Compat.unsafe_convert(pointer([A()]), 1) == 1
291291

@@ -398,36 +398,41 @@ let A = [1.0 2.0; 3.0 4.0]
398398
end
399399

400400
# Cstring
401-
let s = "foo", w = wstring("foo")
402-
@test reinterpret(Ptr{Cchar}, Compat.unsafe_convert(Cstring, s)) == pointer(s)
401+
let s = "foo"
402+
# note: need cconvert in 0.5 because of JuliaLang/julia#16893
403+
@test reinterpret(Ptr{Cchar}, Compat.unsafe_convert(Cstring, VERSION < v"0.4" ? s : Base.cconvert(Cstring, s))) == pointer(s)
403404
if VERSION < v"0.5.0-dev+4859"
404-
@test reinterpret(Ptr{Cwchar_t}, Compat.unsafe_convert(Cwstring, w)) == pointer(w)
405+
let w = wstring("foo")
406+
@test reinterpret(Ptr{Cwchar_t}, Compat.unsafe_convert(Cwstring, w)) == pointer(w)
407+
end
405408
end
406409
end
407410

408411
# fma and muladd
409412
@test fma(3,4,5) == 3*4+5 == muladd(3,4,5)
410413

411-
# is_valid_utf32
412-
s = utf32("abc")
413-
@test isvalid(s)
414-
s = utf32(UInt32[65,0x110000])
415-
@test !isvalid(s)
416-
417-
# isvalid
418-
let s = "abcdef", u8 = "abcdef\uff", u16 = utf16(u8), u32 = utf32(u8),
419-
bad32 = utf32(UInt32[65,0x110000]), badch = Char[0x110000][1]
420-
421-
@test !isvalid(bad32)
422-
@test !isvalid(badch)
414+
if VERSION < v"0.5.0-dev+5271"
415+
# is_valid_utf32
416+
s = utf32("abc")
423417
@test isvalid(s)
424-
@test isvalid(u8)
425-
@test isvalid(u16)
426-
@test isvalid(u32)
427-
@test isvalid(Compat.ASCIIString, s)
428-
@test isvalid(Compat.UTF8String, u8)
429-
@test isvalid(UTF16String, u16)
430-
@test isvalid(UTF32String, u32)
418+
s = utf32(UInt32[65,0x110000])
419+
@test !isvalid(s)
420+
421+
# isvalid
422+
let s = "abcdef", u8 = "abcdef\uff", u16 = utf16(u8), u32 = utf32(u8),
423+
bad32 = utf32(UInt32[65,0x110000]), badch = Char[0x110000][1]
424+
425+
@test !isvalid(bad32)
426+
@test !isvalid(badch)
427+
@test isvalid(s)
428+
@test isvalid(u8)
429+
@test isvalid(u16)
430+
@test isvalid(u32)
431+
@test isvalid(Compat.ASCIIString, s)
432+
@test isvalid(Compat.UTF8String, u8)
433+
@test isvalid(UTF16String, u16)
434+
@test isvalid(UTF32String, u32)
435+
end
431436
end
432437

433438
if VERSION < v"0.5.0-dev+907"
@@ -1190,8 +1195,8 @@ let io = IOBuffer(), s = "hello"
11901195
@test @compat String(s.data) == s
11911196
write(io, s)
11921197
@test @compat String(io) == s
1193-
@test @compat String(pointer(s.data)) == s
1194-
@test @compat String(pointer(s.data),length(s.data)) == s
1198+
@test unsafe_string(pointer(s.data)) == s
1199+
@test unsafe_string(pointer(s.data),length(s.data)) == s
11951200
@test string(s, s, s) == "hellohellohello"
11961201
@test @compat(String(s)) == s
11971202
@test String == @compat(Union{Compat.UTF8String,Compat.ASCIIString})
@@ -1246,5 +1251,5 @@ end
12461251

12471252
# Add test for Base.view
12481253
let a = rand(10,10)
1249-
@test view(a, :, 1) == a[:,1]
1254+
@test view(a, :, 1) == a[:,1]
12501255
end

0 commit comments

Comments
 (0)