-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Implicit conversion from integral numbers to byte array #2702
Comments
For that use case, you wouldn't use an Rather, you would use an |
In addition, I don't see how we could introduce implicit support for that without breaking existing use cases, but perhaps I'm overlooking something. |
@sbrannen I meant something different. Probably a more detailed example would've explained it better. I don't want to aggregate all the arguments in a single array, I want each argument to be converted into a dedicated byte array, with array size depending on the primitive type. Following my example: @ValueSource(ints = {Integer.MIN_VALUE, 0, 0xFF, 0xFFFF, 0xFFFFFF, Integer.MAX_VALUE}) each integer would be converted to a separate byte array of size 4, being the size in bytes of the integer type (i.e., The test cases for the custom converter might explain it better than my words 🙂 |
Written in a style similar to the official docs, this is what I'd like to have:
|
Integral types are converted to a byte array with a Big Endian byte order and size as the number of bytes used to represent the integral value in two's complement binary form. Issue: junit-team#2702
I raised #2711 to help evaluate this feature. |
Integral types are converted to a byte array with a Big Endian byte order and size as the number of bytes used to represent the integral value in two's complement binary form. Issue: junit-team#2702
Integral types are converted to a byte array with a Big Endian byte order and size as the number of bytes used to represent the integral value in two's complement binary form. Issue: junit-team#2702
Integral types are converted to a byte array with a Big Endian byte order and size as the number of bytes used to represent the integral value in two's complement binary form. Issue: junit-team#2702
I'm not yet convinced how generally useful such a built-in conversion would be. How about making it opt-in via an annotation like |
I think that bitwise operations are not the most common use case for Java development, so I'm probably targeting a niche area. My thoughts were that such an implicit conversion would not introduce side effects for other use cases and test authors could always define their own conversion logic, if there is any. Having an annotation would also be nice. What I'd like to avoid is defining a custom converter and sharing it with multiple projects, while this could be a generally usable feature. The annotation could also have an optional parameter to change the endianness, which I would keep as big endian by default. Do you have any idea about naming? Something like |
As the stale bot just commented on #2711, I wanted to check if any decisions have been made about how this topic might move forward. Would |
This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution. |
Bump |
@scordio Sorry for the delay! I think |
I was actually thinking about it today 😄 maybe combining this topic with the proposal at #3141 (comment). As far as I remember, there are no argument converters in JUnit Pioneer. If the project is open to having them, that would work for me. I'll raise an issue and let you know. |
If you would like us to be able to process this issue, please provide the requested information. If the information is not provided within the next 3 weeks, we will be unable to proceed and this issue will be closed. |
@scordio Can we close this issue in favor of the Pioneer one? |
Superseded by junit-pioneer/junit-pioneer#734. |
I'd like to propose the addition of implicit conversion from integral numbers (
byte
,short
,int
,long
) to byte array. The concrete use case is code dealing with bitwise operations, mostly related to cryptography.My wish is to write something like this:
where I can leverage binary and hexadecimal literals which are automatically converted to a byte array using a
ByteBuffer
with Big Endian order.I put together a small poc with a custom argument converter. If the proposal is accepted, I'm happy to raise a PR about it.
Deliverables
byte
/short
/int
/long
tobyte[]
The text was updated successfully, but these errors were encountered: