-
-
Notifications
You must be signed in to change notification settings - Fork 698
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
Truncate Typed Arrays (#441) #576
Conversation
This is it for now. Edit: |
148dd72
to
4483a81
Compare
objectToString(ar) === '[object Uint32Array]' || | ||
objectToString(ar) === '[object Float32Array]' || | ||
objectToString(ar) === '[object Float64Array]'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it is open to abuse, but you could just use:
/\w+Array]$/.test(objectToString(ar))
@lucasfcosta the general direction you're going with this is very good. Despite the two comments above, I'm happy with this code. |
Thank you! I'm a fairly new programmer, so your orientation helps me a lot. |
Hi @keithamus, sorry for this time without commits (christmas and everything postponed my GitHub plans hahahaha) Well, I've made the changes you pointed on this PR and tests are running smoothly. But as you've already questioned: what's the best way to show two in a comparison? I too am not aware of the most common TypedArray's use cases therefore I'm not sure what the best format would be. About arrays: shouldn't they be truncated or not according to the |
@lucasfcosta thanks for sticking with this, I completely appreciate that you can't dedicate 100% of your time to Chai, and in fact I would certainly not want you to. Hope you enjoyed your christmas holidays 😄. I don't think I was particularly clear about truncateThreshold, and that was my fault - something which I will correct now: The way truncateThreshold works right now, is that if the Stringified value above a certain length, then instead of displaying the stringified value, we display a truncated value (see objDisplay.js). For example if you have For TypedArrays, where we know all values are ints of a fixed upper length (they're only numbers after all), we can reasonably predict the length of the string during parse time and therefore offer better truncation heuristics, so, using the truncateThreshold we can keep useful info about the array but also keep this threshold for reasonable output. To demonstrate this with code, I'd expect some code a bit like this: str = '[ ';
for (var i in output) {
if (str.length >= config.truncateThreshold - 7) {
str += '...';
break;
}
str += output[i] + ', ';
}
str += ' ]'; The above code stringifies the array from within the loop, breaking as soon as the string is about to go over the threshold. Importantly: this doesn't rely on an arbitrary array length - but the configurable truncateTreshold property. Hopefully this makes sense. |
fb4585b
to
7f6b49c
Compare
Thanks, @keithamus, everything makes sense now! |
@lucasfcosta Nope, I think the way Arrays are currently displayed is not great. Ideally we'd have all objects represent themselves truncated by ellipsis and I'll merge this now as it's looking great. |
[WIP] Truncate Typed Arrays (#441)
@lucasfcosta if you feel like you need to put any more work into this - feel free to put another |
@keithamus Ok then, thanks for the help! |
Please don't merge yet, I'm still doing some experiments
As I said on the issue itself (#441), I'm gonna leave this PR here while working on this change so you guys can review my code and guarantee everything's fine.
Notes/Questions:
TypedArray
constructor, we have to check each one of them.TypedArrays
should be considered "too long" and how are we going to truncate them?Arrays
too? If the answer for this is "yes" I feel like this code could be improved.Progress:
isTypedArray()
formatTypedArray()