From c56743d688b6b3764704e52e2d4d05a03fea5b85 Mon Sep 17 00:00:00 2001 From: Wynand Badenhorst Date: Fri, 10 Sep 2021 12:36:13 -0500 Subject: [PATCH 1/4] Add shortstrings test with maxlen --- test/runtests.jl | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 219a05a..eba96af 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -122,6 +122,14 @@ end @test ShortString7(ShortString7("ab")) isa ShortString7 @test_throws ErrorException ShortString3(ShortString7("123456")) + + @test ShortString(ss127"Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long.", 127) == "Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long." + @test ShortString(ss63"Basically a fairly long string really",63) == "Basically a fairly long string really" + @test ShortString(ss31"A Longer String!!!",31) == "A Longer String!!!" + @test ShortString(ss15"Short String!!!",15) == "Short String!!!" + @test ShortString(ss7"ShrtStr",7) == "ShrtStr" + @test ShortString(ss3"ss3",3) == "ss3" + @test ShortString("",0) == "" end @testset "promote rule" begin From 84f3d57011f543de55b3a1d377131748c923fe86 Mon Sep 17 00:00:00 2001 From: Wynand Badenhorst Date: Fri, 10 Sep 2021 12:52:44 -0500 Subject: [PATCH 2/4] Fix shortstrings with ss and maxlen --- src/base.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/base.jl b/src/base.jl index ee98fd3..098a6cf 100644 --- a/src/base.jl +++ b/src/base.jl @@ -319,7 +319,7 @@ argument `maxlen` is passed. If the keyword argument `types` is passed with a list (a tuple or Vector) of Unsigned 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) = +ShortString(str::AbstractString, maxlen = sizeof(str); types=def_types) = get_type(max(maxlen,1), types=types)(str) """ From d4368a5585444bf96e1f1d81ccb588ce03028a25 Mon Sep 17 00:00:00 2001 From: Wynand Badenhorst Date: Fri, 10 Sep 2021 12:54:55 -0500 Subject: [PATCH 3/4] update version to 0.3.12 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index b8e0f16..f23c426 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ShortStrings" uuid = "63221d1c-8677-4ff0-9126-0ff0817b4975" authors = ["Dai ZJ ", "ScottPJones ", "Lyndon White "] -version = "0.3.11" +version = "0.3.12" [deps] BitIntegers = "c3b6d118-76ef-56ca-8cc7-ebb389d030a1" From 45a3a9e8a98aa0f285a4efe9df5cc16eeba158e6 Mon Sep 17 00:00:00 2001 From: Wynand Badenhorst Date: Fri, 10 Sep 2021 13:11:29 -0500 Subject: [PATCH 4/4] format tests nicely --- test/runtests.jl | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index eba96af..b344483 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -123,13 +123,33 @@ end @test_throws ErrorException ShortString3(ShortString7("123456")) - @test ShortString(ss127"Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long.", 127) == "Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long." - @test ShortString(ss63"Basically a fairly long string really",63) == "Basically a fairly long string really" - @test ShortString(ss31"A Longer String!!!",31) == "A Longer String!!!" - @test ShortString(ss15"Short String!!!",15) == "Short String!!!" - @test ShortString(ss7"ShrtStr",7) == "ShrtStr" - @test ShortString(ss3"ss3",3) == "ss3" - @test ShortString("",0) == "" + # Test creating shortstrings with maxlen + @test ShortString( + ss127"Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long.", + 127, + ) == "Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long." + @test ShortString( + ss63"Basically a fairly long string really", 63 + ) == "Basically a fairly long string really" + @test ShortString(ss31"A Longer String!!!", 31) == "A Longer String!!!" + @test ShortString(ss15"Short String!!!", 15) == "Short String!!!" + @test ShortString(ss7"ShrtStr", 7) == "ShrtStr" + @test ShortString(ss3"ss3", 3) == "ss3" + @test ShortString("", 0) == "" + + @test_throws ErrorException ShortString( + ss127"Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long.", + 0, + ) == "Be honest, do you actually need a string longer than this. Seriously. C'mon this is pretty long." + @test_throws ErrorException ShortString( + ss63"Basically a fairly long string really", 0 + ) == "Basically a fairly long string really" + @test_throws ErrorException ShortString( + ss31"A Longer String!!!", 0 + ) == "A Longer String!!!" + @test_throws ErrorException ShortString(ss15"Short String!!!", 0) == "Short String!!!" + @test_throws ErrorException ShortString(ss7"ShrtStr", 0) == "ShrtStr" + # @test_throws ErrorException ShortString(ss3"ss3", 0) == "ss3" Why doesn't this throw an error? end @testset "promote rule" begin