Login
Artifact [47539af311]
Login

Artifact 47539af3116f70761d27db0739d1721120dd5d64:


// TODO: more output buffering tests, when i'm not so tired.
scope {
  assert 'object' === typename s2.ob;
  const ob = s2.ob;
  assert 0 === ob.level();
  assert ob === ob.push();
  print('buffered');
  var b = ob.pop(1);
  assert 0 === ob.level();
  assert b inherits s2.Buffer;
  assert b.length()>0;
  // Reminder to self: if assertion tracing is on, assertions will generate
  // output to our buffer, making exact content checks here impractical.
  // But we can do...
  assert b.toString().indexOf('buffered') >= 0;
  //print("Buffered",b.length(),"bytes.");
}

scope{
  const ob = s2.ob;
  const out = print;
  ob.push();
      out("This will be flushed to stdout.");
      ob.flush();
      out("level 1");
      var v1 = ob.takeString();
      ob.push();
          out("This will be flushed to level 1.");
          ob.flush();
          out("level 2");
          var v2 = ob.takeString();
      ob.pop();
      var v1b = ob.takeString();
      out("discarded");
      //ob.clear()// not needed b/c pop() will do this
  ob.pop();
  assert v1 === 'level 1\n';
  assert v2 === 'level 2\n';
  assert v1b === 'This will be flushed to level 1.\n';
}