Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

toString method #13

Open
wants to merge 1 commit into from

1 participant

@ffissore

I need a toString method that behaves just like the words* methods. here is my impl. tests pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 29, 2012
  1. toString method

    federico authored
This page is out of date. Refresh to see the latest.
Showing with 31 additions and 0 deletions.
  1. +5 −0 index.js
  2. +26 −0 test/parse.js
View
5 index.js
@@ -307,6 +307,11 @@ exports.parse = function parse (buffer) {
return offset >= buffer.length;
};
+ self.toString = function(name, start, end, encoding) {
+ vars.set(name, buffer.toString(encoding, start, end));
+ return self;
+ };
+
return self;
};
View
26 test/parse.js
@@ -29,6 +29,32 @@ exports.parse = function () {
});
};
+exports.toString = function () {
+ var to = setTimeout(function () {
+ assert.fail('never tapped');
+ }, 50);
+
+ var res = Binary.parse(new Buffer("This is a test string (èç€) with some special chars"))
+ .toString('a')
+ .toString('b', 0, 14)
+ .toString('c', 15)
+ .tap(function (vars) {
+ clearTimeout(to);
+ assert.eql(vars, {
+ a : "This is a test string (èç€) with some special chars",
+ b : "This is a test",
+ c : "string (èç€) with some special chars"
+ });
+ })
+ .vars
+ ;
+ assert.eql(res, {
+ a : "This is a test string (èç€) with some special chars",
+ b : "This is a test",
+ c : "string (èç€) with some special chars"
+ });
+};
+
exports.loop = function () {
var to = setTimeout(function () {
assert.fail('never tapped');
Something went wrong with that request. Please try again.