Skip to content

Commit

Permalink
Book passing encode/decode test.
Browse files Browse the repository at this point in the history
  • Loading branch information
rogowski committed Mar 2, 2023
1 parent 9e616ea commit 73b661a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
15 changes: 13 additions & 2 deletions lib/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ B.encode = function(d, s){ s = s || "|";
}
}
// deprecate this B.encode below:
B.encode = function(d, _){ _ = _ || "'";
B.encode2 = function(d, _){ _ = _ || "'";
if(typeof d == 'string'){
var i = d.indexOf(_), t = "";
while(i != -1){ t += _; i = d.indexOf(_, i+1) }
Expand All @@ -152,8 +152,19 @@ B.decode = function(t, s){ s = s || "|";
switch(t){ case ' ': return null; case '-': return false; case '+': return true; }
switch(t[0]){
case '-': case '+': return parseFloat(t);
case '"': return t.slice(1);
}

return B.decode(B.parse(t, s));
}

B.parse = function(l, s){ var i, c = 0, s = (s||'|');

if(0 !== (i = l.indexOf(s))){ return l }
while(s == l[++c + i]){ console.log('Count escape prefix:', c, i); }; // get count of escape prefix
return B.parse(l.slice(i+c), s);
}

function heal(l, s){ var i, c = 0;
if(0 > (i = l.indexOf(''))){ return l }
while('' == l[++c + i]){}; // get count of escape prefix
Expand All @@ -173,4 +184,4 @@ B.hash = function(s, c){ // via SO
}

try{module.exports=B}catch(e){}
}());
}());
13 changes: 8 additions & 5 deletions test/rad/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam

describe('Book Format', function(done){
var B = Book;
it.skip('encode decode', function(){
it('encode decode', function(){
expect(B.decode(B.encode(null))).to.be(null);
expect(B.decode(B.encode(false))).to.be(false);
expect(B.decode(B.encode(true))).to.be(true);
Expand All @@ -76,14 +76,18 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam
expect(B.decode(B.encode(2))).to.be(2);
expect(B.decode(B.encode(1.2))).to.be(1.2);
expect(B.decode(B.encode(1234.56789))).to.be(1234.56789);
console.log("RESUME HERE!"); return;
expect(B.decode(B.encode(''))).to.be('');
expect(B.decode(B.encode("hello world"))).to.be("hello world");
expect(B.decode(B.encode("he||o"))).to.be("he||o");
expect(B.decode(B.encode("ho|y ha|o"))).to.be("ho|y ha|o");
expect(B.decode(B.encode("he||||y"))).to.be("he||||y");
expect(B.decode(B.encode("ho|\|ow"))).to.be("ho|\|ow");
expect(B.decode(B.encode("so\\rrow"))).to.be("so\\rrow");
expect(B.decode(B.encode("bo\\|\|row"))).to.be("bo\\|\|row");
expect(B.decode(B.encode("||\áãbbçcddéẽffǵghhíĩj́jḱkĺlḿmńñóõṕpqqŕrśsttẃwúǘũxxýỹźzàbcdèfghìjklm̀ǹòpqrstùǜẁxỳz|"))).to.be("||\áãbbçcddéẽffǵghhíĩj́jḱkĺlḿmńñóõṕpqqŕrśsttẃwúǘũxxýỹźzàbcdèfghìjklm̀ǹòpqrstùǜẁxỳz|");
});

});

describe('BASIC API', function(done){

it('write', function(done){
Expand Down Expand Up @@ -182,7 +186,6 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam

rad('pa-bob', 'banana', function(err, ok){
expect(err).to.not.be.ok();
//console.log("COMPARE:", rad.book.list[0].text, 'vs', prev.book.list[0].text);
var text = rad.book.list[0].text;
var i = text.indexOf('pa-alice');
expect(i).to.not.be(-1);
Expand Down Expand Up @@ -321,4 +324,4 @@ var names = ["Adalard","Adora","Aia","Albertina","Alfie","Allyn","Amabil","Ammam

});

}());
}());

0 comments on commit 73b661a

Please sign in to comment.