<commit_before>'use strict'

var test = require('tape')
var bloomrun = require('./')

test('null is returned if pattern is not found', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { cmd: 'set-policy' }

  t.equal(instance.lookup(pattern), null)
})

test('pattern is returned on match', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { cmd: 'set-policy' }

  instance.add(pattern)

  t.deepEqual(instance.lookup(pattern), pattern)
})

test('payload is returned instead of pattern if it exists', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { prefs: 'userId' }
  var payload = '1234'

  instance.add(pattern, payload)

  t.deepEqual(instance.lookup(pattern), payload)
})

test('functions are supported as payloads', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { prefs: 'userId' }
  var payload = function () { return '1234' }

  instance.add(pattern, payload)

  t.deepEqual(instance.lookup(pattern)(), payload())
})

test('partial matching should not be supported', function (t) {
  t.plan(2)

  var instance = bloomrun()
  var pattern = {
    cmd: 'add-user',
    username: 'mcollina'
  }<commit_msg>Added test about deep pattern matching.<commit_after>'use strict'

var test = require('tape')
var bloomrun = require('./')

test('null is returned if pattern is not found', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { cmd: 'set-policy' }

  t.equal(instance.lookup(pattern), null)
})

test('pattern is returned on match', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { cmd: 'set-policy' }

  instance.add(pattern)

  t.deepEqual(instance.lookup(pattern), pattern)
})

test('payload is returned instead of pattern if it exists', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { prefs: 'userId' }
  var payload = '1234'

  instance.add(pattern, payload)

  t.deepEqual(instance.lookup(pattern), payload)
})

test('deep pattern matching', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { role: 'sum', tnx: { side: 'buy' } }
  var payload = '1234'

  instance.add(pattern, payload)

  t.deepEqual(instance.lookup({
    role: 'sum',
    tnx: {
      side: 'buy'
    }
  }), payload)
})

test('functions are supported as payloads', function (t) {
  t.plan(1)

  var instance = bloomrun()
  var pattern = { prefs: 'userId' }
  var payload = function () { return '1234' }

  instance.add(pattern, payload)

  t.deepEqual(instance.lookup(pattern)(), payload())
})

test('partial matching should not be supported', function (t) {
  t.plan(2)

  var instance = bloomrun()
  var pattern = {
    cmd: 'add-user',
    username: 'mcollina'
  }
{'fraction_non_alphanumeric': 0.15140459686245897, 'fraction_numerical': 0.011309740970448741, 'mean_word_length': 3.7357512953367875, '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': '1899000', 'n_tokens_mistral': 955, 'n_tokens_neox': 900, 'n_words': 261}