<commit_before>import test from 'ava';
import { Package } from '../src/package';

test('package scripts decode/encode empty script', t => {
  const d = Package.decodeScripts(undefined);
  t.is(Package.encodeScripts(d), undefined);
});

test('package scripts decode/encode scripts &&', t => {
  const d = Package.decodeScripts({
    a: 'xx && yy&&zz',
    b: 'XXX YYY ZZZ'
  });

  t.deepEqual(d, {
    a: { op: '&&', args: ['xx', 'yy', 'zz'] },
    b: { value: 'XXX YYY ZZZ' }
  });

  d.a.args[1] = 'yy2';

  t.deepEqual(Package.encodeScripts(d), {
    a: 'xx && yy2 && zz',
    b: 'XXX YYY ZZZ'
  });
});

test('package scripts merge undefined', t => {
  let d1 = Package.decodeScripts({
    a: 'xx && yy'
  });

  t.deepEqual(Package.mergeScripts(d1, undefined), {
    a: { op: '&&', args: ['xx', 'yy'] }
  });

  d1 = Package.decodeScripts({
    a: 'xx && yy'
  });

  t.deepEqual(Package.mergeScripts(undefined, d1), {
    a: { op: '&&', args: ['xx', 'yy'] }
  });

  t.is(Package.mergeScripts(undefined, undefined), undefined);
});

test('package scripts decode/merge/encode', t => {
  const d1 = Package.decodeScripts({
    a: 'xx && yy'
  });

  const d2 = Package.decodeScripts({
    a: 'xx'
  });

  t.deepEqual(Package.mergeScripts(d1, d2), {
    a: { op: '&&', args: ['xx', 'yy'] }
  });
});

test('package scripts decode/merge/encode swapped', t => {
  const d1 = Package.decodeScripts({
    a: 'xx && yy'
  });

  const d2 = Package.decodeScripts({
    a: 'xx'
  });

  t.deepEqual(Package.mergeScripts(d2, d1), {
    a: { op: '&&', args: ['xx', 'yy'] }
  });
});

test('package scripts decode/merge/encode remove', t => {
  const d1 = Package.decodeScripts({
    a: 'xx && yy'
  });

  const d2 = Package.decodeScripts({
    a: '-'
  });

  t.deepEqual(Package.mergeScripts(d1, d2), {
  });
});<commit_msg>test: package scripts merge scripts && no dups<commit_after>import test from "ava";
import { Package } from "../src/package";

test("package scripts decode/encode empty script", t => {
  const d = Package.decodeScripts(undefined);
  t.is(Package.encodeScripts(d), undefined);
});

test("package scripts decode/encode scripts &&", t => {
  const d = Package.decodeScripts({
    a: "xx && yy&&zz",
    b: "XXX YYY ZZZ"
  });

  t.deepEqual(d, {
    a: { op: "&&", args: ["xx", "yy", "zz"] },
    b: { value: "XXX YYY ZZZ" }
  });

  d.a.args[1] = "yy2";

  t.deepEqual(Package.encodeScripts(d), {
    a: "xx && yy2 && zz",
    b: "XXX YYY ZZZ"
  });
});

test.only("package scripts merge scripts && no dups", t => {
  t.deepEqual(
    Package.mergeScripts(
      Package.decodeScripts({
        a: "xx && yy"
      }),
      Package.decodeScripts({
        a: "xx && zz"
      })
    ),
    {
      a: { op: "&&", args: ["xx", "yy", "zz"] }
    }
  );
});

test("package scripts merge undefined", t => {
  let d1 = Package.decodeScripts({
    a: "xx && yy"
  });

  t.deepEqual(Package.mergeScripts(d1, undefined), {
    a: { op: "&&", args: ["xx", "yy"] }
  });

  d1 = Package.decodeScripts({
    a: "xx && yy"
  });

  t.deepEqual(Package.mergeScripts(undefined, d1), {
    a: { op: "&&", args: ["xx", "yy"] }
  });

  t.is(Package.mergeScripts(undefined, undefined), undefined);
});

test("package scripts decode/merge/encode", t => {
  const d1 = Package.decodeScripts({
    a: "xx && yy"
  });

  const d2 = Package.decodeScripts({
    a: "xx"
  });

  t.deepEqual(Package.mergeScripts(d1, d2), {
    a: { op: "&&", args: ["xx", "yy"] }
  });
});

test("package scripts decode/merge/encode swapped", t => {
  const d1 = Package.decodeScripts({
    a: "xx && yy"
  });

  const d2 = Package.decodeScripts({
    a: "xx"
  });

  t.deepEqual(Package.mergeScripts(d2, d1), {
    a: { op: "&&", args: ["xx", "yy"] }
  });
});

test("package scripts decode/merge/encode remove", t => {
  const d1 = Package.decodeScripts({
    a: "xx && yy"
  });

  const d2 = Package.decodeScripts({
    a: "-"
  });

  t.deepEqual(Package.mergeScripts(d1, d2), {});
});
{'fraction_non_alphanumeric': 0.21917463512833418, 'fraction_numerical': 0.009562154001006542, 'mean_word_length': 3.019211324570273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 16, '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': '5260991', 'n_tokens_mistral': 1532, 'n_tokens_neox': 1514, 'n_words': 333}