-
Notifications
You must be signed in to change notification settings - Fork 38
Stdlib: Binary/Byte stream utilities #923
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
Open
marzipankaiser
wants to merge
23
commits into
master
Choose a base branch
from
stdlib/binstream
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
c4e6485
Add binstream as in stdlib/draw
marzipankaiser c501ec0
Allow tracking with a given start position
marzipankaiser dfaa06b
Start adding doc comments
marzipankaiser 5e0f2c6
More docs and structure
marzipankaiser d185d7d
more docs and structure
marzipankaiser 1f5d0ac
more docs
marzipankaiser fedae8e
Add binstream to acme
marzipankaiser 1a905aa
Fix typo
marzipankaiser a70dd90
Make bitwiseNot an extern
marzipankaiser a7f7745
Make pad a function instead of an effect
marzipankaiser 10f8efd
Move tracking, pad to streams
marzipankaiser 8fdc5bd
Move nth, first to stream
marzipankaiser 68b108b
Move tests to test
marzipankaiser 28544c0
Implement bitwiseNot in vm
marzipankaiser 691200c
Fix test for LLVM (assert, infixEq on Byte)
marzipankaiser 8de82cd
Fix show on Byte for chez
marzipankaiser d5c61a8
Show bytes as ints on chez, too
marzipankaiser dfccb53
Remove left-over test import
marzipankaiser 1fd6dd3
Minor formatting changes
marzipankaiser 58ed215
Remove bits/bytes and force using bits/bytesBE/LE
marzipankaiser f6f3d02
Fix test
marzipankaiser f7c6b3e
Add assertThrows-like test functionality
marzipankaiser 3d973b2
Use assertNotThrown
marzipankaiser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Binstream | ||
✓ literal hex 10 | ||
✓ literal hex ff | ||
✓ literal char a | ||
✓ literal string ba | ||
✓ int back-and-forth (17) | ||
✓ int back-and-forth (17), explicit BE | ||
✓ int back-and-forth (17), explicit LE | ||
✓ byte 00101010 | ||
✓ to bits and back | ||
✓ to bits and back LE bitorder | ||
✓ to bits and back BE bitorder | ||
✓ append 0 means *2 | ||
✓ pow agrees with double one | ||
✓ LE 2s-complement | ||
✓ BE 2s-complement | ||
|
||
15 pass | ||
0 fail | ||
15 tests total | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import binstream | ||
import stream | ||
import test | ||
|
||
def main() = { | ||
suite("Binstream", false){ | ||
test("literal hex 10"){ assert(x"10${()}", 16) } | ||
test("literal hex ff"){ assert(x"ff${()}", 255) } | ||
test("literal char a"){ assert(x"${'a'}", x"61${()}") } | ||
test("literal string ba"){ assert(x"${"ba"}", x"62${()}" * 256 + x"61${()}") } | ||
test("int back-and-forth (17)"){ assert(x"${17}", 17)} | ||
test("int back-and-forth (17), explicit BE"){ assert(x"${17.BE}", 17) } | ||
test("int back-and-forth (17), explicit LE"){ assert(x"${17.LE}", 17 * 256 * 256 * 256) } | ||
test("byte 00101010"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
assert(first[Byte]{groupBytes{ bit"00101010${()}" }}.toInt, 42) | ||
} | ||
test("to bits and back"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v => | ||
assert(first[Byte]{ groupBytes{ bits(v) } }, v) | ||
} | ||
} | ||
test("to bits and back LE bitorder"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v => | ||
assert(first[Byte]{ groupBytesLE{ bitsLE(v) } }, v) | ||
} | ||
} | ||
test("to bits and back BE bitorder"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
[42.toByte, 12.toByte, 113.toByte, 0.toByte, 255.toByte].foreach{ v => | ||
assert(first[Byte]{ groupBytesBE{ bitsBE(v) } }, v) | ||
} | ||
} | ||
test("append 0 means *2"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
[42.toByte, 12.toByte, 127.toByte].foreach{ v => | ||
assert(nth[Byte](1){ groupBytes{ repeat(7){ do emit(B0()) }; bits(v); do emit(B0()) } }, (v.toInt * 2).toByte) | ||
} | ||
} | ||
test("pow agrees with double one"){ | ||
assert(pow(2,5), pow(2.0,5).toInt) | ||
} | ||
test("LE 2s-complement"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
assert(first[Byte]{ groupBytesLE{ twoscomplementLE{ bitsLE(6.toByte) } } }, 250.toByte) | ||
} | ||
test("BE 2s-complement"){ | ||
with on[MissingValue].default{ assert(true, false) } | ||
assert(first[Byte]{ groupBytesBE{ bit"${-6.Signed.BE.OfWidth(8)}" } }, 250.toByte) | ||
} | ||
} | ||
() | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since we're changing
test
anyway, could we add aon[MissingValue].assertSome
?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.
Yes, good idea. TODO.
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.
effekt/libraries/common/test.effekt
Lines 62 to 73 in 3d973b2
WDYT?