Skip to content

Commit bec1186

Browse files
committed
Add support for empty strings
1 parent 0336174 commit bec1186

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ShortStrings"
22
uuid = "63221d1c-8677-4ff0-9126-0ff0817b4975"
33
authors = ["Dai ZJ <[email protected]>", "ScottPJones <[email protected]>", "Lyndon White <[email protected]>"]
4-
version = "0.3.10"
4+
version = "0.3.11"
55

66
[deps]
77
BitIntegers = "c3b6d118-76ef-56ca-8cc7-ebb389d030a1"

src/base.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ If the keyword argument `types` is passed with a list (a tuple or Vector) of Uns
320320
types, in order of their size, then one of those types will be used.
321321
"""
322322
ShortString(str::Union{String,SubString{String}}, maxlen = sizeof(str); types=def_types) =
323-
get_type(maxlen, types=types)(str)
323+
get_type(max(maxlen,1), types=types)(str)
324324

325325
"""
326326
Create a ShortString, using the smallest ShortString that can fit the string,

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,13 @@ ss = ShortString15(s)
7272
@test ss15"Short String!!!" === ShortString15("Short String!!!")
7373
@test ss7"ShrtStr" === ShortString7("ShrtStr")
7474
@test ss3"ss3" === ShortString3("ss3")
75+
@test ss"" === ShortString("")
7576

7677

7778
@testset "equality of different sized ShortStrings" begin
79+
@test ShortString15("") == ShortString3("")
80+
@test ShortString3("") == ShortString15("")
81+
7882
@test ShortString15("ab") == ShortString3("ab")
7983
@test ShortString3("ab") == ShortString15("ab")
8084

@@ -172,3 +176,11 @@ end
172176
@test split(ShortString15("abc XYZ x")) == ["abc", "XYZ", "x"]
173177
@test split(ShortString15("abc XYZ x")) isa Vector{SubString{ShortString15}}
174178
end
179+
180+
@testset "test all default valid string sizes" begin
181+
size_limit = 255
182+
svec_good = [randstring(i) for i=0:size_limit]
183+
@test typeof(ShortString.(svec_good)) == Vector{ShortString}
184+
s_bad = randstring(size_limit + 1)
185+
@test_throws ArgumentError ShortString(s_bad)
186+
end

0 commit comments

Comments
 (0)