Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying max length when using shortstrings to create short strings #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Wynand
Copy link

@Wynand Wynand commented Sep 10, 2021

Currently ShortString(ss127"hello",5) errors, and this fixes that

@Wynand Wynand marked this pull request as draft September 10, 2021 17:54
@Wynand Wynand marked this pull request as ready for review September 10, 2021 19:25
Comment on lines +127 to +134
@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!!!"
Copy link
Member

@oxinabox oxinabox Sep 15, 2021

Choose a reason for hiding this comment

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

I don't think we need these test.
They don't test anything different do they?

We should test things with:

  • shortstring below maxlen
  • shortstring at maxlen
  • shortstring above maxlen

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"
Copy link
Member

Choose a reason for hiding this comment

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

Including the right-hand side == here seems like it is adding nothing?
It makes it unclear what should throw the error.

@@ -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) =
Copy link
Member

Choose a reason for hiding this comment

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

If relaxing it always to AbstractString,
need to also test that Test.GenericString works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants