
$print{/**
    Testing output buffer support
*/}

assert api && api.ob
const ob = api.ob

[ob.push]
$print{/*
Note that we could use print() for these tests instead of
api.io.output() but i don't want extra newlines output for this
particular test.

Also note that we're inside a print() call right now but this won't
be output because it's being buffered and will be discarded.
*/}
[ob.pop]

const out = api.io.output
/**
   The indentation below serves only to visually
   distinguish the various buffering levels, and
   has no effect on the meaning of the code.

   Beware that output buffering is ignorant of scopes. i.e.
   the buffers are not subject to the same lifetimes
   as values unless/until one calls ob.takeBuffer() to
   transform the underlying "raw" buffer into a
   first-class Value.
*/
[ob.push]
    [out "This will be flushed to stdout.\n"]
    [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.takeBuffer]
    [out "discarded"]
    //[ob.clear] // redundant when done right before [ob.pop]
[ob.pop]

assert 'buffer' === typename v1b
assert v1 === {level 1}
assert v2 === {level 2}
assert [v1b.toString] === {This will be flushed to level 1.}
