<commit_before>
var tape = require('tape')

var psc = require('../')

var examples = [
  {req: 0, stream: false, end: false, value: ['event', {okay: true}]}, //an event

  {req: 1, stream: false, end: false, value: 'whatever'}, //a request
  {req:  2, stream: true, end: false, value: new Buffer('hello')}, //a stream packet
  {req: -2, stream: true, end: false, value: new Buffer('goodbye')}, //a stream response
  {req:  2, stream: true, end: true, value: true}, //a stream packet
  {req: -2, stream: true, end: true, value: true} //a stream response
]

tape('simple', function (t) {
  examples.forEach(function (e) {
    var c = psc.encodePair(e)

    var msg = psc.decodeHead(c[0])

    t.equal(msg.length, c[1].length)
    msg = psc.decodeBody(c[1], msg)

    delete msg.length
    delete msg.type
    t.deepEqual(e, msg)
  })
  t.end()
})
<commit_msg>test streaming<commit_after>
var tape = require('tape')
var pull = require('pull-stream')
var split = require('pull-randomly-split')

var psc = require('../')

var examples = [
  {req: 0, stream: false, end: false, value: ['event', {okay: true}]}, //an event

  {req: 1, stream: false, end: false, value: 'whatever'}, //a request
  {req:  2, stream: true, end: false, value: new Buffer('hello')}, //a stream packet
  {req: -2, stream: true, end: false, value: new Buffer('goodbye')}, //a stream response
  {req:  2, stream: true, end: true, value: true}, //a stream packet
  {req: -2, stream: true, end: true, value: true} //a stream response
]

tape('simple', function (t) {
  examples.forEach(function (e) {
    var c = psc.encodePair(e)

    var msg = psc.decodeHead(c[0])

    t.equal(msg.length, c[1].length)
    msg = psc.decodeBody(c[1], msg)

    delete msg.length
    delete msg.type
    t.deepEqual(e, msg)
  })
  t.end()
})

tape('streaming', function (t) {

  pull(
    pull.values(examples),
    psc.encode(),
    split(),
    psc.decode(),
    pull.collect(function (err, actual) {

      examples.forEach(function (expected, i) {
        delete actual[i].length
        delete actual[i].type

        t.deepEqual(actual[i], expected)
      })
      t.end()
    })
  )

})

{'fraction_non_alphanumeric': 0.18190298507462688, 'fraction_numerical': 0.008395522388059701, 'mean_word_length': 3.1650485436893203, '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': '2916913', 'n_tokens_mistral': 781, 'n_tokens_neox': 762, 'n_words': 228}