<commit_before>var common = require('../common');
var test   = require('utest');
var assert = require('assert');
var Reader = require(common.lib + '/Reader');

test('Reader: Constructor', {
  'offset option': function() {
    var buffer = new Buffer([0, 127]);
    var reader = new Reader({buffer: buffer, offset: 1});

    assert.equal(reader.uint8(), 127);
  },
});

test('Reader: WritableStream', {
  'is writable by default': function() {
    var reader = new Reader();
    assert.equal(reader.writable, true);
  },

  'write: returns true when active': function() {
    var reader = new Reader();
    assert.equal(reader.write(new Buffer(0)), true);
  },

  'write: returns false when paused': function() {
    var reader = new Reader();

    reader.pause();
    assert.equal(reader.write(new Buffer(0)), false);
  },

  'write: returns true when resumed': function() {
    var reader = new Reader();

    reader.pause();
    assert.equal(reader.write(new Buffer(0)), false);

    reader.resume();
    assert.equal(reader.write(new Buffer(0)), true);
  },

  'write: collects buffer data': function() {
    var reader = new Reader();

    reader.write(new Buffer([1, 2]));
    assert.equal(reader.uint8(), 1);

    reader.write(new Buffer([3]));
    assert.equal(reader.uint8(), 2);
    assert.equal(reader.uint8(), 3);
  },
});

test('Reader: Parser Methods', {
  'bytesAvailable': function() {
    var buffer = new Buffer([1, 127, 128, 255]);
    var reader = new Reader(buffer);

    assert.equal(reader.bytesAvailable(), 4);
    reader.uint8();
    reader.uint8();

    assert.equal(reader.bytesAvailable(), 2);
  },

  'uint8': function() {
    var buffer = new Buffer([1, 127, 128, 255]);
    var reader = new Reader(buffer);

    assert.equal(reader.uint8(), 1);<commit_msg>Simplify test names<commit_after>var common = require('../common');
var test   = require('utest');
var assert = require('assert');
var Reader = require(common.lib + '/Reader');

test('Constructor', {
  'offset option': function() {
    var buffer = new Buffer([0, 127]);
    var reader = new Reader({buffer: buffer, offset: 1});

    assert.equal(reader.uint8(), 127);
  },
});

test('WritableStream interface', {
  'is writable by default': function() {
    var reader = new Reader();
    assert.equal(reader.writable, true);
  },

  'write: returns true when active': function() {
    var reader = new Reader();
    assert.equal(reader.write(new Buffer(0)), true);
  },

  'write: returns false when paused': function() {
    var reader = new Reader();

    reader.pause();
    assert.equal(reader.write(new Buffer(0)), false);
  },

  'write: returns true when resumed': function() {
    var reader = new Reader();

    reader.pause();
    assert.equal(reader.write(new Buffer(0)), false);

    reader.resume();
    assert.equal(reader.write(new Buffer(0)), true);
  },

  'write: collects buffer data': function() {
    var reader = new Reader();

    reader.write(new Buffer([1, 2]));
    assert.equal(reader.uint8(), 1);

    reader.write(new Buffer([3]));
    assert.equal(reader.uint8(), 2);
    assert.equal(reader.uint8(), 3);
  },
});

test('Read Methods', {
  'bytesAvailable': function() {
    var buffer = new Buffer([1, 127, 128, 255]);
    var reader = new Reader(buffer);

    assert.equal(reader.bytesAvailable(), 4);
    reader.uint8();
    reader.uint8();

    assert.equal(reader.bytesAvailable(), 2);
  },

  'uint8': function() {
    var buffer = new Buffer([1, 127, 128, 255]);
    var reader = new Reader(buffer);

    assert.equal(reader.uint8(), 1);
{'fraction_non_alphanumeric': 0.1810780460415497, 'fraction_numerical': 0.027512633352049412, 'mean_word_length': 3.59741935483871, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3678184', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1081, 'n_words': 293}