Skip to content

Commit

Permalink
Merge pull request #54 from Wynand/wy/empty-string-support
Browse files Browse the repository at this point in the history
Add support for empty strings
  • Loading branch information
oxinabox authored Aug 4, 2021
2 parents 0336174 + bec1186 commit eeedb94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ShortStrings"
uuid = "63221d1c-8677-4ff0-9126-0ff0817b4975"
authors = ["Dai ZJ <[email protected]>", "ScottPJones <[email protected]>", "Lyndon White <[email protected]>"]
version = "0.3.10"
version = "0.3.11"

[deps]
BitIntegers = "c3b6d118-76ef-56ca-8cc7-ebb389d030a1"
Expand Down
2 changes: 1 addition & 1 deletion src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ If the keyword argument `types` is passed with a list (a tuple or Vector) of Uns
types, in order of their size, then one of those types will be used.
"""
ShortString(str::Union{String,SubString{String}}, maxlen = sizeof(str); types=def_types) =
get_type(maxlen, types=types)(str)
get_type(max(maxlen,1), types=types)(str)

"""
Create a ShortString, using the smallest ShortString that can fit the string,
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ ss = ShortString15(s)
@test ss15"Short String!!!" === ShortString15("Short String!!!")
@test ss7"ShrtStr" === ShortString7("ShrtStr")
@test ss3"ss3" === ShortString3("ss3")
@test ss"" === ShortString("")


@testset "equality of different sized ShortStrings" begin
@test ShortString15("") == ShortString3("")
@test ShortString3("") == ShortString15("")

@test ShortString15("ab") == ShortString3("ab")
@test ShortString3("ab") == ShortString15("ab")

Expand Down Expand Up @@ -172,3 +176,11 @@ end
@test split(ShortString15("abc XYZ x")) == ["abc", "XYZ", "x"]
@test split(ShortString15("abc XYZ x")) isa Vector{SubString{ShortString15}}
end

@testset "test all default valid string sizes" begin
size_limit = 255
svec_good = [randstring(i) for i=0:size_limit]
@test typeof(ShortString.(svec_good)) == Vector{ShortString}
s_bad = randstring(size_limit + 1)
@test_throws ArgumentError ShortString(s_bad)
end

2 comments on commit eeedb94

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/42125

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.11 -m "<description of version>" eeedb94df9a20f814a8eb07adae2d12a3cd1552b
git push origin v0.3.11

Please sign in to comment.