<commit_before>function fakeAjax(options) { jasmine.FakeAjax.initContext(options); }
function clearContext() { fakeAjax({}); }
function loadTestData(selector, url) { return jasmine.FakeAjax.loadTestData(selector, url); }
function latestAjax() { return jasmine.FakeAjax.latestAjax(); }
function latestAjaxWithUrlMatching(partialUrl) { return jasmine.FakeAjax.latestAjaxWithUrlMatching(partialUrl); }

afterEach(clearContext);

(function($, jasmine) {
  jasmine.FakeAjax = {
    realAjax: $.ajax,
    initContext: initContext,
    loadTestData: loadTestData,
    latestAjax: latestAjax,
    latestAjaxWithUrlMatching: latestAjaxWithUrlMatching,
    log: new Logger()
  };

  $.ajax = function(options) {
    jasmine.FakeAjax.recordedSession.addAjaxCall(options);
    var urls = jasmine.FakeAjax.urls;
    if (!urls) {
      jasmine.FakeAjax.log.warn("There are no ajax url mappings defined.");
    } else if (!urls[options.url]) {
      jasmine.FakeAjax.log.warn("Applying default success data for url '" + options.url + "'.");
      if (!options.success) {
        jasmine.FakeAjax.log.error("Ajax success handler is not defined in system under test for url '" + options.url + "'. See firebug script stack for more info.");
      } else {
        options.success("default success data");
      }
    } else if (urls[options.url].successData) {
      options.success(urls[options.url].successData);
    } else if (urls[options.url].errorMessage) {
      options.error({responseText: urls[options.url].errorMessage});
    } else {
      jasmine.FakeAjax.log.error("Unknown mapping value for url '" + options.url + "'. Expected either successData or errorMessage.");
    }
  };

  function initContext(options) {
    this.urls = options.urls;
    this.recordedSession = new RecordedSession();
  }

  function loadTestData(selector, url) {
    var fixture;
    jasmine.FakeAjax.realAjax({
      url: url,
      async: false,
      success: function(data) {
        fixture = data;
      },
      error: function() {
        jasmine.FakeAjax.log.error("Failed loading test data by url '" + url + "'.");
      }
    });
    var testDataContainer = $(fixture).find(selector);
    if (testDataContainer.length > 0) {
      return testDataContainer.html();
    } else {
      jasmine.FakeAjax.log.error("Failed loading test data by selector: '" + selector + "' from url: '" + url + "'. Whole fixture: " + fixture);
      return undefined;
    }
  }

  function latestAjax() {
    return lastDecoded(jasmine.FakeAjax.recordedSession.ajaxCalls);
  }

  function latestAjaxWithUrlMatching(partialUrl) {
    return lastDecoded(jasmine.FakeAjax.recordedSession.ajaxCalls.filter(function(ajaxOptions) {
      return ajaxOptions.url.match(partialUrl);
    }));
  }

  function lastDecoded(list) {
    return $.URLDecode(list[list.length - 1]);
  }

  function RecordedSession() {
    this.ajaxCalls = [];

    this.addAjaxCall = function(ajaxOptions) {
      this.ajaxCalls.push(ajaxOptions);
    }
  }

  function Logger() {
    this.error = function(message) {
      if (window.console) {
        console.error(message);
        debugger;
      }
    }

    this.warn = function(message) {
      if (window.console) {
        console.warn(message);
      }
    }
  }
})(jQuery, jasmine);<commit_msg>Extract .withFirebugConsole.<commit_after>function fakeAjax(options) { jasmine.FakeAjax.initContext(options); }
function clearContext() { fakeAjax({}); }
function loadTestData(selector, url) { return jasmine.FakeAjax.loadTestData(selector, url); }
function latestAjax() { return jasmine.FakeAjax.latestAjax(); }
function latestAjaxWithUrlMatching(partialUrl) { return jasmine.FakeAjax.latestAjaxWithUrlMatching(partialUrl); }

afterEach(clearContext);

(function($, jasmine) {
  jasmine.FakeAjax = {
    realAjax: $.ajax,
    initContext: initContext,
    loadTestData: loadTestData,
    latestAjax: latestAjax,
    latestAjaxWithUrlMatching: latestAjaxWithUrlMatching,
    log: new Logger()
  };

  $.ajax = function(options) {
    jasmine.FakeAjax.recordedSession.addAjaxCall(options);
    var urls = jasmine.FakeAjax.urls;
    if (!urls) {
      jasmine.FakeAjax.log.warn("There are no ajax url mappings defined.");
    } else if (!urls[options.url]) {
      jasmine.FakeAjax.log.warn("Applying default success data for url '" + options.url + "'.");
      if (!options.success) {
        jasmine.FakeAjax.log.error("Ajax success handler is not defined in system under test for url '" + options.url + "'. See firebug script stack for more info.");
      } else {
        options.success("default success data");
      }
    } else if (urls[options.url].successData) {
      options.success(urls[options.url].successData);
    } else if (urls[options.url].errorMessage) {
      options.error({responseText: urls[options.url].errorMessage});
    } else {
      jasmine.FakeAjax.log.error("Unknown mapping value for url '" + options.url + "'. Expected either successData or errorMessage.");
    }
  };

  function initContext(options) {
    this.urls = options.urls;
    this.recordedSession = new RecordedSession();
  }

  function loadTestData(selector, url) {
    var fixture;
    jasmine.FakeAjax.realAjax({
      url: url,
      async: false,
      success: function(data) {
        fixture = data;
      },
      error: function() {
        jasmine.FakeAjax.log.error("Failed loading test data by url '" + url + "'.");
      }
    });
    var testDataContainer = $(fixture).find(selector);
    if (testDataContainer.length > 0) {
      return testDataContainer.html();
    } else {
      jasmine.FakeAjax.log.error("Failed loading test data by selector: '" + selector + "' from url: '" + url + "'. Whole fixture: " + fixture);
      return undefined;
    }
  }

  function latestAjax() {
    return lastDecoded(jasmine.FakeAjax.recordedSession.ajaxCalls);
  }

  function latestAjaxWithUrlMatching(partialUrl) {
    return lastDecoded(jasmine.FakeAjax.recordedSession.ajaxCalls.filter(function(ajaxOptions) {
      return ajaxOptions.url.match(partialUrl);
    }));
  }

  function lastDecoded(list) {
    return $.URLDecode(list[list.length - 1]);
  }

  function RecordedSession() {
    this.ajaxCalls = [];

    this.addAjaxCall = function(ajaxOptions) {
      this.ajaxCalls.push(ajaxOptions);
    }
  }

  function Logger() {
    this.error = function(message) {
      withFirebugConsole(function(c) {
        c.error(message);
        debugger;
      });
    };

    this.warn = function(message) {
      withFirebugConsole(function(c) {
        c.warn(message);
      });
    };

    function withFirebugConsole(callback) {
      if (window.console) {
        callback(window.console);
      }
    }
  }
})(jQuery, jasmine);
{'fraction_non_alphanumeric': 0.13110119047619048, 'fraction_numerical': 0.0005952380952380953, 'mean_word_length': 3.2645939086294415, 'pattern_counts': {'":': 0, '<': 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': '1338550', 'n_tokens_mistral': 2125, 'n_tokens_neox': 2066, 'n_words': 401}