<commit_before>'use strict'
const p = require('./index')

// Wrap tape to automatically t.end(), since our tests are all synchronous.
const tape = (name, testFunc) => {
  const tapeModule = require('tape')
  tapeModule(name, (t) => {
    testFunc(t)
    t.end()
  })
}

// Helpers for checking whether a parse succeeded as expected.  Nice as
// adapters, in case the output format changes.
const parseOk = (t, parser, input, expectedValue) => {
  t.deepEquals(parser(input), {
    status: true,
    value: expectedValue,
    index: input.length
  })
}
const parseFail = (t, parser, input, index, expected) => {
  t.deepEquals(parser(input), {
    status: false,
    value: expected,
    index: index
  })
}

//
// Basics
//

tape('isParser', (t) => {
  t.ok(p.isParser(p.string('a')))
})
tape('Object.keys is unpolluted', (t) => {
  t.deepEquals(Object.keys(p.string('a')), ['_'])
})

tape('string', (t) => {
  parseOk(t, p.string('a'), 'a', 'a')
})
tape('regex', (t) => {
  parseOk(t, p.regex(/a+/), 'aa', 'aa')
  parseOk(t, p.regex(/(a+)b/, 1), 'aab', 'aa')
})
tape('all', (t) => {
  parseOk(t, p.all, 'aaa', 'aaa')
})
tape('any', (t) => {
  parseOk(t, p.any, 'a', 'a')
  parseOk(t, p.any, 'b', 'b')
})
tape('test', (t) => {
  parseOk(t, p.test((x) => x === 'a'), 'a', 'a')

  const usesEnv = p.test((x, { whatCharacter }) => x === whatCharacter)<commit_msg>Test: 'test'-parser faiure case<commit_after>'use strict'
const p = require('./index')

// Wrap tape to automatically t.end(), since our tests are all synchronous.
const tape = (name, testFunc) => {
  const tapeModule = require('tape')
  tapeModule(name, (t) => {
    testFunc(t)
    t.end()
  })
}

// Helpers for checking whether a parse succeeded as expected.  Nice as
// adapters, in case the output format changes.
const parseOk = (t, parser, input, expectedValue) => {
  t.deepEquals(parser(input), {
    status: true,
    value: expectedValue,
    index: input.length
  })
}
const parseFail = (t, parser, input, index, expected) => {
  t.deepEquals(parser(input), {
    status: false,
    value: expected,
    index: index
  })
}

//
// Basics
//

tape('isParser', (t) => {
  t.ok(p.isParser(p.string('a')))
})
tape('Object.keys is unpolluted', (t) => {
  t.deepEquals(Object.keys(p.string('a')), ['_'])
})

tape('string', (t) => {
  parseOk(t, p.string('a'), 'a', 'a')
})
tape('regex', (t) => {
  parseOk(t, p.regex(/a+/), 'aa', 'aa')
  parseOk(t, p.regex(/(a+)b/, 1), 'aab', 'aa')
})
tape('all', (t) => {
  parseOk(t, p.all, 'aaa', 'aaa')
})
tape('any', (t) => {
  parseOk(t, p.any, 'a', 'a')
  parseOk(t, p.any, 'b', 'b')
})
tape('test', (t) => {
  parseOk(t, p.test((x) => x === 'a'), 'a', 'a')
  parseFail(t, p.test((x) => x === 'a'), 'b', 0,
    ['a character matching (x) => x === \'a\''])

  const usesEnv = p.test((x, { whatCharacter }) => x === whatCharacter)
{'fraction_non_alphanumeric': 0.24083215796897037, 'fraction_numerical': 0.0010578279266572638, 'mean_word_length': 3.5610932475884245, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '5666747', 'n_tokens_mistral': 1139, 'n_tokens_neox': 1118, 'n_words': 270}