Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[js] Serialize variable length integers up to 32bit.
Add a unit test for that.
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #!/bin/bash | ||
| # 19 and 30 where moved out as they were parrot specific, 52,54 is missing, we can't pass 49 till we are bootstraped | ||
| prove -e 'node' t/js/varint.js # unit tests for the js runtime | ||
| prove "$@" -e './nqp-js' gen/js/qregex.t t/nqp/{01,02,03,04,05,06,07,08,09,10,11,12,13,14,15,16,17,18,19,20,21,22,23,25,26,27,28,31,32,33,34,35,36,37,38,39,40,41,42,44,45,46,47,48,50,51,53,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,83,84,88,89,90,91,92,93,94,95,96}*.t t/js/getcomp-js.t t/qast/02* t/serialization/02-types.t |
This file contains 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 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,37 @@ | ||
| var tap = require('tap'); | ||
| var BinaryWriteCursor = require('nqp-runtime/serialization').BinaryWriteCursor; | ||
| var BinaryCursor = require('nqp-runtime/deserialization').BinaryCursor; | ||
|
|
||
|
|
||
| function check(n, expected) { | ||
| expected = new Buffer(expected); | ||
| var cursor = new BinaryWriteCursor(null); | ||
| cursor.varint(n); | ||
| var got = cursor.buffer.slice(0, cursor.offset); | ||
|
|
||
| var correct = got.equals(expected); | ||
| tap.ok(correct, "writing " + n); | ||
|
|
||
| if (!correct) { | ||
| tap.comment("got", got); | ||
| tap.comment("expected", expected); | ||
| } | ||
|
|
||
|
|
||
| var reader = new BinaryCursor(expected, 0, null, null); | ||
|
|
||
| var got_n = reader.varint(); | ||
|
|
||
| tap.equal(got_n, n, "reading "+n); | ||
| } | ||
|
|
||
| check(-1, [128]); | ||
| check(0, [129]); | ||
| check(1, [130]); | ||
| check(30, [159]); | ||
| check(126, [255]); | ||
| check(200, [16,200]); | ||
| check(-200, [31,56]); | ||
| check(10000, [32,16,39]); | ||
| check(-10000, [47,240,216]); | ||
| check(1000000, [48,64,66,15]); |