<commit_before>// *****************************************************************************
// Copyright 2021 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************

'use strict'

/* eslint-env mocha */
/* global expect */

const Aerospike = require('../lib/aerospike')
const exp = Aerospike.expressions
const op = Aerospike.operations
const expop = Aerospike.exp_operations

const helper = require('./test_helper')
const keygen = helper.keygen
const tempBin = 'ExpVar'

describe('Aerospike.exp_operations', function () {
  helper.skipUnlessVersion('>= 5.0.0', this)

  const client = helper.client

  async function createRecord (bins, meta = null) {
    const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exp' })()
    await client.put(key, bins, meta)
    return key
  }

  it('builds up a filter expression value', function () {
    const filter = exp.eq(exp.binInt('intVal'), exp.int(42))
    expect(filter).to.be.an('array')
  })

  describe('exp_operations on arithmetic expressions', function () {
    describe('int bin add expression', function () {
      it('evaluates exp_read op to true if temp bin equals the sum of bin and given value', async function () {
        const key = await createRecord({ intVal: 2 })
        const ops = [
          expop.read(tempBin,
            exp.add(exp.binInt('intVal'), exp.binInt('intVal')),
            0),
          op.read('intVal')
        ]
        const result = await client.operate(key, ops, {})
        // console.log(result)
        expect(result.bins.intVal).to.eql(2)
        expect(result.bins.ExpVar).to.eql(4)
      })
      it('evaluates exp_write op to true if bin equals the sum of bin and given value', async function () {
        const key = await createRecord({ intVal: 2 })
        const ops = [
          expop.write('intVal',
            exp.add(exp.binInt('intVal'), exp.binInt('intVal')),
            0),
          op.read('intVal')
        ]
        const result = await client.operate(key, ops, {})
        // console.log(result)
        expect(result.bins.intVal).to.eql(4)
      })
    })
  })
})
<commit_msg>added basic expression list/map expression-op test cases<commit_after>// *****************************************************************************
// Copyright 2021 Aerospike, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License")
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// *****************************************************************************

'use strict'

/* eslint-env mocha */
/* global expect */

const Aerospike = require('../lib/aerospike')
const exp = Aerospike.expressions
const op = Aerospike.operations
const expop = Aerospike.exp_operations

const helper = require('./test_helper')
const keygen = helper.keygen
const tempBin = 'ExpVar'

describe('Aerospike.exp_operations', function () {
  helper.skipUnlessVersion('>= 5.0.0', this)

  const client = helper.client

  async function createRecord (bins, meta = null) {
    const key = keygen.string(helper.namespace, helper.set, { prefix: 'test/exp' })()
    await client.put(key, bins, meta)
    return key
  }

  it('builds up a filter expression value', function () {
    const filter = exp.eq(exp.binInt('intVal'), exp.int(42))
    expect(filter).to.be.an('array')
  })

  describe('read and write exp_operations on arithmetic expressions', function () {
    describe('int bin add expression', function () {
      it('evaluates exp_read op to true if temp bin equals the sum of bin and given value', async function () {
        const key = await createRecord({ intVal: 2 })
        const ops = [
          expop.read(tempBin,
            exp.add(exp.binInt('intVal'), exp.binInt('intVal')),
            0),
          op.read('intVal')
        ]
        const result = await client.operate(key, ops, {})
        // console.log(result)
        expect(result.bins.intVal).to.eql(2)
        expect(result.bins.ExpVar).to.eql(4)
      })
      it('evaluates exp_write op to true if bin equals the sum of bin and given value', async function () {
        const key = await createRecord({ intVal: 2 })
        const ops = [
          expop.write('intVal',
            exp.add(exp.binInt('intVal'), exp.binInt('intVal')),
            0),
          op.read('intVal')
        ]
        const result = await client.operate(key, ops, {})
        // console.log(result)
        expect(result.bins.intVal).to.eql(4)
      })
    })
  }),

  describe('read exp_operation on list expressions', function () {
    describe('list bin append expression', function () {
      it('evaluates exp_read op to true if temp bin equals to appended list', async function () {
        const key = await createRecord({ list: [2, 3, 4, 5] })
        const ops = [
          expop.read(tempBin,
            exp.lists.appendItems(exp.binList('list'), exp.binList('list')),
            0),
          op.read('list')
        ]
        const result = await client.operate(key, ops, {})
        // console.log(result)
        expect(result.bins.list).to.eql([2, 3, 4, 5])
        expect(result.bins.ExpVar).to.eql([2, 3, 4, 5, 2, 3, 4, 5])
      })
    })
  }),

  describe('write exp_operation on map expressions', function () {
    describe('map bin putItems expression', function () {
      it('evaluates exp_write op to true if temp bin equals to combined maps', async function () {
        const key = await createRecord({ map: { c: 1, b: 2, a: 3 },  map2: { f: 1, e: 2, d: 3 }})
        const ops = [
          expop.write('map',
            exp.maps.putItems(exp.binMap('map'), exp.binMap('map2')),
            0),
          op.read('map')
        ]
        const result = await client.operate(key, ops, {})
        // console.log(result)
        expect(result.bins.map).to.eql({ a: 3, b: 2, c: 1, d: 3, e: 2, f: 1 })
      })
    })
  })


})

{'fraction_non_alphanumeric': 0.17464706738466015, 'fraction_numerical': 0.01047882404307961, 'mean_word_length': 2.786225895316804, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7354766', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1960, 'n_words': 605}