<commit_before>import { normalizeArray2 } from 'ember-awesome-macros/array/-utils';
import { raw } from 'ember-awesome-macros';
import { module, test } from 'qunit';
import sinon from 'sinon';
import compute from 'ember-macro-test-helpers/compute';

const firstParam = 'first param test';
const secondParam = 'second param test';
const returnValue = 'return value test';

let funcStub;
let array;
let computed;

module('Unit | Macro | array | utils | normalize array 2', {
  beforeEach() {
    array = [];
    funcStub = sinon.stub(array, 'pop').returns(returnValue);

    computed = normalizeArray2('pop');
  }
});

test('it returns identity if not array type and no default value', function(assert) {
  let array = {};

  compute({
    assert,
    computed: computed('array'),
    properties: {
      array
    },
    strictEqual: array
  });
});

test('it calls func on array', function(assert) {
  let { result } = compute({
    computed: computed('array', 'firstParam', 'secondParam'),
    properties: {
      array,
      firstParam,
      secondParam
    }
  });

  assert.strictEqual(funcStub.thisValues[0], array);
  assert.deepEqual(funcStub.args, [[firstParam, secondParam]]);
  assert.strictEqual(result, returnValue);
});

test('it calls prop on array', function(assert) {
  let computed = normalizeArray2('length');

  compute({
    assert,
    computed: computed('array'),
    properties: {
      array: [1, 2, 3]
    },
    strictEqual: 3
  });
});

test('it calls ember funcs on array', function(assert) {
  let computed = normalizeArray2('compact');

  compute({
    assert,
    computed: computed('array'),
    properties: {
      array: [1, null, undefined]
    },
    deepEqual: [1]
  });
});

test('it allows default value override', function(assert) {
  let computed = normalizeArray2('pop', () => true);

  compute({
    assert,
    computed: computed('array'),
    strictEqual: true
  });
});

test('default value is a new copy every recalculation', function(assert) {
  let computed = normalizeArray2('pop', () => []);

  let { subject } = compute({
    computed: computed('array')
  });

  let result = subject.get('computed');

  subject.set('array', null);

  assert.notEqual(subject.get('computed'), result);
});

test('composable: it calls func on array', function(assert) {
  let { result } = compute({
    computed: computed(
      raw(array),
      raw(firstParam),
      raw(secondParam)
    )
  });

  assert.strictEqual(funcStub.thisValues[0], array);
  assert.deepEqual(funcStub.args, [[firstParam, secondParam]]);
  assert.strictEqual(result, returnValue);
});
<commit_msg>add a lazy calc test<commit_after>import EmberObject, { computed } from '@ember/object';
import { normalizeArray2 } from 'ember-awesome-macros/array/-utils';
import { raw } from 'ember-awesome-macros';
import { module, test } from 'qunit';
import sinon from 'sinon';
import compute from 'ember-macro-test-helpers/compute';

const firstParam = 'first param test';
const secondParam = 'second param test';
const returnValue = 'return value test';

let funcStub;
let array;
let macro;

module('Unit | Macro | array | utils | normalize array 2', {
  beforeEach() {
    array = [];
    funcStub = sinon.stub(array, 'pop').returns(returnValue);

    macro = normalizeArray2('pop');
  }
});

test('it returns identity if not array type and no default value', function(assert) {
  array = {};

  compute({
    assert,
    computed: macro('array'),
    properties: {
      array
    },
    strictEqual: array
  });
});

test('it calls func on array', function(assert) {
  let { result } = compute({
    computed: macro('array', 'firstParam', 'secondParam'),
    properties: {
      array,
      firstParam,
      secondParam
    }
  });

  assert.strictEqual(funcStub.thisValues[0], array);
  assert.deepEqual(funcStub.args, [[firstParam, secondParam]]);
  assert.strictEqual(result, returnValue);
});

test('it calls prop on array', function(assert) {
  macro = normalizeArray2('length');

  compute({
    assert,
    computed: macro('array'),
    properties: {
      array: [1, 2, 3]
    },
    strictEqual: 3
  });
});

test('it calls ember funcs on array', function(assert) {
  macro = normalizeArray2('compact');

  compute({
    assert,
    computed: macro('array'),
    properties: {
      array: [1, null, undefined]
    },
    deepEqual: [1]
  });
});

test('it allows default value override', function(assert) {
  macro = normalizeArray2('pop', () => true);

  compute({
    assert,
    computed: macro('array'),
    strictEqual: true
  });
});

test('default value is a new copy every recalculation', function(assert) {
  macro = normalizeArray2('pop', () => []);

  let { subject } = compute({
    computed: macro('array')
  });

  let result = subject.get('computed');

  subject.set('array', null);

  assert.notEqual(subject.get('computed'), result);
});

test('it lazily calculates keys', function(assert) {
  let spy = sinon.spy();

  compute({
    baseClass: EmberObject.extend({
      secondParam: computed(spy)
    }),
    computed: macro('array', 'firstParam', 'secondParam')
  });

  assert.notOk(spy.called);
});

test('composable: it calls func on array', function(assert) {
  let { result } = compute({
    computed: macro(
      raw(array),
      raw(firstParam),
      raw(secondParam)
    )
  });

  assert.strictEqual(funcStub.thisValues[0], array);
  assert.deepEqual(funcStub.args, [[firstParam, secondParam]]);
  assert.strictEqual(result, returnValue);
});

{'fraction_non_alphanumeric': 0.1569269979974513, 'fraction_numerical': 0.005461496450027308, 'mean_word_length': 3.744386873920553, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6953545', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1694, 'n_words': 432}