<commit_before>'use strict';

var expect = require('chai').expect;
var jsonfile = require('jsonfile');
var jsonT = require('../lib/jsont').jsonT;

describe('cities-jsont', function() {
  var jsonFileName = null;
  var jsonCitiesFileName = null;
  var jsonCityFileName = null;


  var sources = [];
  var transforms = [];

  transforms[0] = {
    "self": "<table>{pnt}</table>",
    "pnt": "<tr><td>{pnt.x}</td><td>{pnt.y}</td></tr>"
  };
  sources[0] = {
    pnt: {
      x: 2,
      y: 3
    }
  };

  transforms[1] = {
    "self": "<table><tr>{$}</tr></table>",
    "self[*]": "<td>{$}</td>"
  };
  sources[1] = [1, 2];

  transforms[3] = {
    'self': '{\n"name": "{name}", {weather}\n}',
    'weather': '\n"weather": {{temp}, {desc}\n}',
    "temp": '\n"temp": {main.temp}',
    "desc": '\n"description": "{weather[0].description}"'
  };

  // transforms[4] works - kind of:
  /*
  [

{"name": "<NAME>",
"temp": 84.34,
"description": "Sky is Clear"
}
{"name": "<NAME>",
"temp": 84.02,
"description": "Sky is Clear"
}
{"name": "Rosarito",
"temp": 82.47,
"description": "scattered clouds"
}
]
  */
  transforms[4] = {
    'self': '[\n{cities}\n]',
    'cities[*]': '\n{"name": "{$.name}",\n"weather": {\n"temp": {$.main.temp}, \n"description": "{$.weather[0].description}"\n}\n}'
  };

  // transforms[6] works, but introduces a global variable. Ugh.
  var index = 0;
  transforms[6] = {
    'self': '[\n{cities}\n]',
    'cities[*]': '\n{"name": "{$.name}",\n"weather": {\n"temp": {$.main.temp}, \n"description": "{$.weather[0].description}"\n}\n}{@comma(cities)}',
    'comma': function(x) {
      return (++index < x.length) ? ',' : '';
    }
  };

  transforms[7] = {
    'self': '{ "cities": [{cities}] }',
    'cities[*]': '{"name": "{$.name}", ' +
      '"weather": { "temp": {$.main.temp}, "windSpeed": {$.wind.speed}, "description": "{$.weather[0].description}" } },'
  };

  sources[14] = [{
    "u": "http://www.ericclapton.com/hello",
    "d": "<NAME>",
    "t": ["guitarist", "blues", "rock"]
  }, {
    "u": "http://www.bbking.com/",
    "d": "B.B. King : Official Site",
    "t": ["guitarist", "blues"]
  }, {
    "u": "http://www.stevieraysbluesbar.com/",
    "d": "Louisville's House of Blues",
    "t": ["guitarist", "blues", "rock"]
  }];

  transforms[14] = {
    "self": "<ul>\n{$}</ul>",
    "self[*]": " <li>\n" +
      "  <img style='position:absolute;display:none;'" +
      "    width='16' height='16'\n" +
      "    onload='showImage(this)' src='{@icon($.u)}'/>\n" +
      "  <a style='margin-left:20px;' href='{$.u}'>{$.d}</a>\n" +
      " </li>\n",
    "icon": function(x) {
      return x.split('/').splice(0, 3).join('/') + '/favicon.ico';
    }
  };

  function repairJson(jsonStr) {
    var repairedJsonStr = jsonStr;

    var repairs = [
      [/,\s*}/gi, ' }'],
      [/,\s*\]/gi, ' ]']
    ];

    for (var i = 0, len = repairs.length; i < len; ++i) {
      repairedJsonStr = repairedJsonStr.replace(repairs[i][0], repairs[i][1]);
    }

    return repairedJsonStr;
  }

  beforeEach(function() {
    var baseDir = __dirname + '/../../data';

    jsonFileName = baseDir + '/speaker.json';
    jsonCitiesFileName = baseDir + '/cities-weather-short.json';
    jsonCityFileName = baseDir + '/city-weather.json';
  });

  it('should do a very simple transform', function(done) {
    //console.log(jsonT(sources[0], transforms[0]));

    done();
  });

  it('should do a very simple transform - Part II', function(done) {
    //console.log(jsonT(sources[14], transforms[14]));

    done();
  });

  it('should transform city JSON data', function(done) {
    jsonfile.readFile(jsonCityFileName, function(err, jsonObj) {
      if (!err) {
        //console.log(jsonT(jsonObj, transforms[3]));
      } else {
        throw (err);<commit_msg>Removed dead code from jsont-spec.js.<commit_after>'use strict';

var expect = require('chai').expect;
var jsonfile = require('jsonfile');
var jsonT = require('../lib/jsont').jsonT;

describe('cities-jsont', function() {
  var jsonFileName = null;
  var jsonCitiesFileName = null;
  var jsonCityFileName = null;

  var transforms = [];

  // transforms[4] works - kind of:
  /*
  [

{"name": "<NAME>",
"temp": 84.34,
"description": "Sky is Clear"
}
{"name": "<NAME>",
"temp": 84.02,
"description": "Sky is Clear"
}
{"name": "Rosarito",
"temp": 82.47,
"description": "scattered clouds"
}
]
  */
  transforms[4] = {
    'self': '[\n{cities}\n]',
    'cities[*]': '\n{"name": "{$.name}",\n"weather": {\n"temp": {$.main.temp}, \n"description": "{$.weather[0].description}"\n}\n}'
  };

  // transforms[6] works, but introduces a global variable. Ugh.
  var index = 0;
  transforms[6] = {
    'self': '[\n{cities}\n]',
    'cities[*]': '\n{"name": "{$.name}",\n"weather": {\n"temp": {$.main.temp}, \n"description": "{$.weather[0].description}"\n}\n}{@comma(cities)}',
    'comma': function(x) {
      return (++index < x.length) ? ',' : '';
    }
  };

  transforms[7] = {
    'self': '{ "cities": [{cities}] }',
    'cities[*]': '{"name": "{$.name}", ' +
      '"weather": { "temp": {$.main.temp}, "windSpeed": {$.wind.speed}, "description": "{$.weather[0].description}" } },'
  };

  function repairJson(jsonStr) {
    var repairedJsonStr = jsonStr;

    var repairs = [
      [/,\s*}/gi, ' }'],
      [/,\s*\]/gi, ' ]']
    ];

    for (var i = 0, len = repairs.length; i < len; ++i) {
      repairedJsonStr = repairedJsonStr.replace(repairs[i][0], repairs[i][1]);
    }

    return repairedJsonStr;
  }

  beforeEach(function() {
    var baseDir = __dirname + '/../../data';

    jsonCitiesFileName = baseDir + '/cities-weather-short.json';
    jsonCityFileName = baseDir + '/city-weather.json';
  });

  it('should transform city JSON data', function(done) {
    jsonfile.readFile(jsonCityFileName, function(err, jsonObj) {
      if (!err) {
        //console.log(jsonT(jsonObj, transforms[3]));
      } else {
        throw (err);
{'fraction_non_alphanumeric': 0.25546332373369474, 'fraction_numerical': 0.013213620193122142, 'mean_word_length': 3.137351086194814, 'pattern_counts': {'":': 68, '<': 33, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '6437329', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2168, 'n_words': 417}