<commit_before>var tape = require('tape'),
    util = require('vega-util'),
    vega = require('vega-dataflow'),
    runtime = require('../');

tape('Parser parses expressions', function(test) {
  var values = [
    {"x": 1,  "y": 28},
    {"x": 2,  "y": 43},
    {"x": 3,  "y": 81},
    {"x": 4,  "y": 19}
  ];

  var spec = {operators: [
    {id:0, type:'Operator', value: 50},
    {id:1, type:'Operator', update: '2 * _.foo', params: {foo:{$ref:0}}},
    {id:2, type:'Collect',  value: {$ingest: values}},
    {id:3, type:'Apply', params: {
      expr: {
        $expr: 'datum.x * datum.y',
        $fields: ['x', 'y']
      },
      as: 'z',
      pulse: {$ref: 2}
    }},
    {id:4, type:'Filter', params: {
      expr: {
        $expr: 'datum.z > _.bar',
        $fields: ['z'],
        $params: {bar: {$ref:1}}
      },
      pulse: {$ref: 3}
    }},
    {id:5, type:'Collect', params: {pulse: {$ref:4}}}
  ]};

  var df  = new vega.Dataflow(),
      ctx = runtime.parse(spec, runtime.context(df, vega.transforms)),
      ops = ctx.nodes,
      z = util.field('z');

  test.equal(Object.keys(ops).length, spec.operators.length);
  test.equal(df.run(), spec.operators.length);

  test.equal(typeof ops[1]._update, 'function');
  test.equal(ops[1].value, 100);

  test.deepEqual(ops[2].value.map(z), [28, 86, 243, 76]);
  test.deepEqual(ops[5].value.map(z), [243]);

  test.end();
});
<commit_msg>Rename Apply to Formula.<commit_after>var tape = require('tape'),
    util = require('vega-util'),
    vega = require('vega-dataflow'),
    runtime = require('../');

tape('Parser parses expressions', function(test) {
  var values = [
    {"x": 1,  "y": 28},
    {"x": 2,  "y": 43},
    {"x": 3,  "y": 81},
    {"x": 4,  "y": 19}
  ];

  var spec = {operators: [
    {id:0, type:'Operator', value: 50},
    {id:1, type:'Operator', update: '2 * _.foo', params: {foo:{$ref:0}}},
    {id:2, type:'Collect',  value: {$ingest: values}},
    {id:3, type:'Formula', params: {
      expr: {
        $expr: 'datum.x * datum.y',
        $fields: ['x', 'y']
      },
      as: 'z',
      pulse: {$ref: 2}
    }},
    {id:4, type:'Filter', params: {
      expr: {
        $expr: 'datum.z > _.bar',
        $fields: ['z'],
        $params: {bar: {$ref:1}}
      },
      pulse: {$ref: 3}
    }},
    {id:5, type:'Collect', params: {pulse: {$ref:4}}}
  ]};

  var df  = new vega.Dataflow(),
      ctx = runtime.parse(spec, runtime.context(df, vega.transforms)),
      ops = ctx.nodes,
      z = util.field('z');

  test.equal(Object.keys(ops).length, spec.operators.length);
  test.equal(df.run(), spec.operators.length);

  test.equal(typeof ops[1]._update, 'function');
  test.equal(ops[1].value, 100);

  test.deepEqual(ops[2].value.map(z), [28, 86, 243, 76]);
  test.deepEqual(ops[5].value.map(z), [243]);

  test.end();
});

{'fraction_non_alphanumeric': 0.2417465388711395, 'fraction_numerical': 0.03194888178913738, 'mean_word_length': 2.742363877822045, 'pattern_counts': {'":': 16, '<': 3, '<?xml version=': 0, '>': 5, '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': '3008615', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1079, 'n_words': 231}