<commit_before>$(document).ready(function() {

  var view;

  module("Backbone.View", {

    setup: function() {
      view = new Backbone.View({
        id        : 'test-view',
        className : 'test-view'
      });
    }

  });

  test("View: constructor", 4, function() {
    equal(view.el.id, 'test-view');
    equal(view.el.className, 'test-view');
    equal(view.options.id, 'test-view');
    equal(view.options.className, 'test-view');
  });

  test("View: jQuery", 2, function() {
    view.setElement(document.body);
    ok(view.$('#qunit-header a').get(0).innerHTML.match(/Backbone Test Suite/));
    ok(view.$('#qunit-header a').get(1).innerHTML.match(/Backbone Speed Suite/));
  });

  test("View: make", 3, function() {
    var div = view.make('div', {id: 'test-div'}, "one two three");
    equal(div.tagName.toLowerCase(), 'div');
    equal(div.id, 'test-div');
    equal($(div).text(), 'one two three');
  });

  test("View: make can take falsy values for content", 2, function() {
    var div = view.make('div', {id: 'test-div'}, 0);
    equal($(div).text(), '0');

    var div = view.make('div', {id: 'test-div'}, '');
    equal($(div).text(), '');
  });

  test("View: initialize", 1, function() {
    var View = Backbone.View.extend({
      initialize: function() {
        this.one = 1;
      }
    });
    var view = new View;
    equal(view.one, 1);
  });

  test("View: delegateEvents", 6, function() {
    var counter = 0;
    var counter2 = 0;
    view.setElement(document.body);
    view.increment = function(){ counter++; };
    view.$el.bind('click', function(){ counter2++; });
    var events = {"click #qunit-banner": "increment"};
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(counter, 1);
    equal(counter2, 1);
    $('#qunit-banner').trigger('click');
    equal(counter, 2);
    equal(counter2, 2);
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(counter, 3);
    equal(counter2, 3);
  });

  test("View: delegateEvents allows functions for callbacks", 3, function() {
    view.counter = 0;
    view.setElement("#qunit-banner");
    var events = {"click": function() { this.counter++; }};
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(view.counter, 1);
    $('#qunit-banner').trigger('click');
    equal(view.counter, 2);
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(view.counter, 3);
  });

  test("View: undelegateEvents", 6, function() {
    var counter = 0;
    var counter2 = 0;
    view.setElement(document.body);
    view.increment = function(){ counter++; };
    $(view.el).unbind('click');
    $(view.el).bind('click', function(){ counter2++; });
    var events = {"click #qunit-userAgent": "increment"};
    view.delegateEvents(events);
    $('#qunit-userAgent').trigger('click');
    equal(counter, 1);
    equal(counter2, 1);
    view.undelegateEvents();
    $('#qunit-userAgent').trigger('click');
    equal(counter, 1);
    equal(counter2, 2);
    view.delegateEvents(events);
    $('#qunit-userAgent').trigger('click');
    equal(counter, 2);
    equal(counter2, 3);
  });

  test("View: _ensureElement with DOM node el", 1, function() {
    var ViewClass = Backbone.View.extend({
      el: document.body
    });
    var view = new ViewClass;
    equal(view.el, document.body);
  });

  test("View: _ensureElement with string el", 3, function() {
    var ViewClass = Backbone.View.extend({
      el: "body"
    });
    var view = new ViewClass;
    strictEqual(view.el, document.body);

    ViewClass = Backbone.View.extend({
      el: "#testElement > h1"
    });
    view = new ViewClass;
    strictEqual(view.el, $("#testElement > h1").get(0));

    ViewClass = Backbone.View.extend({
      el: "#nonexistent"
    });
    view = new ViewClass;
    ok(!view.el);
  });

  test("View: with className and id functions", 2, function() {
    var viewClass = Backbone.View.extend({
      className: function() {
        return 'one';
      },
      id: function() {
        return 'two';
      }
    });
    equal((new viewClass).el.className, 'one');
    equal((new viewClass).el.id, 'two');
  });

  test("View: with attributes", 2, function() {
    var view = new Backbone.View({attributes : {'class': 'one', id: 'two'}});
    equal(view.el.className, 'one');
    equal(view.el.id, 'two');
  });

  test("View: with attributes as a function", 1, function() {
    var viewClass = Backbone.View.extend({
      attributes: function() {
        return {'class': 'dynamic'};
      }
    });
    equal((new viewClass).el.className, 'dynamic');
  });
<commit_msg>Tweak id/className test.<commit_after>$(document).ready(function() {

  var view;

  module("Backbone.View", {

    setup: function() {
      view = new Backbone.View({
        id        : 'test-view',
        className : 'test-view'
      });
    }

  });

  test("View: constructor", 4, function() {
    equal(view.el.id, 'test-view');
    equal(view.el.className, 'test-view');
    equal(view.options.id, 'test-view');
    equal(view.options.className, 'test-view');
  });

  test("View: jQuery", 2, function() {
    view.setElement(document.body);
    ok(view.$('#qunit-header a').get(0).innerHTML.match(/Backbone Test Suite/));
    ok(view.$('#qunit-header a').get(1).innerHTML.match(/Backbone Speed Suite/));
  });

  test("View: make", 3, function() {
    var div = view.make('div', {id: 'test-div'}, "one two three");
    equal(div.tagName.toLowerCase(), 'div');
    equal(div.id, 'test-div');
    equal($(div).text(), 'one two three');
  });

  test("View: make can take falsy values for content", 2, function() {
    var div = view.make('div', {id: 'test-div'}, 0);
    equal($(div).text(), '0');

    var div = view.make('div', {id: 'test-div'}, '');
    equal($(div).text(), '');
  });

  test("View: initialize", 1, function() {
    var View = Backbone.View.extend({
      initialize: function() {
        this.one = 1;
      }
    });
    var view = new View;
    equal(view.one, 1);
  });

  test("View: delegateEvents", 6, function() {
    var counter = 0;
    var counter2 = 0;
    view.setElement(document.body);
    view.increment = function(){ counter++; };
    view.$el.bind('click', function(){ counter2++; });
    var events = {"click #qunit-banner": "increment"};
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(counter, 1);
    equal(counter2, 1);
    $('#qunit-banner').trigger('click');
    equal(counter, 2);
    equal(counter2, 2);
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(counter, 3);
    equal(counter2, 3);
  });

  test("View: delegateEvents allows functions for callbacks", 3, function() {
    view.counter = 0;
    view.setElement("#qunit-banner");
    var events = {"click": function() { this.counter++; }};
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(view.counter, 1);
    $('#qunit-banner').trigger('click');
    equal(view.counter, 2);
    view.delegateEvents(events);
    $('#qunit-banner').trigger('click');
    equal(view.counter, 3);
  });

  test("View: undelegateEvents", 6, function() {
    var counter = 0;
    var counter2 = 0;
    view.setElement(document.body);
    view.increment = function(){ counter++; };
    $(view.el).unbind('click');
    $(view.el).bind('click', function(){ counter2++; });
    var events = {"click #qunit-userAgent": "increment"};
    view.delegateEvents(events);
    $('#qunit-userAgent').trigger('click');
    equal(counter, 1);
    equal(counter2, 1);
    view.undelegateEvents();
    $('#qunit-userAgent').trigger('click');
    equal(counter, 1);
    equal(counter2, 2);
    view.delegateEvents(events);
    $('#qunit-userAgent').trigger('click');
    equal(counter, 2);
    equal(counter2, 3);
  });

  test("View: _ensureElement with DOM node el", 1, function() {
    var ViewClass = Backbone.View.extend({
      el: document.body
    });
    var view = new ViewClass;
    equal(view.el, document.body);
  });

  test("View: _ensureElement with string el", 3, function() {
    var ViewClass = Backbone.View.extend({
      el: "body"
    });
    var view = new ViewClass;
    strictEqual(view.el, document.body);

    ViewClass = Backbone.View.extend({
      el: "#testElement > h1"
    });
    view = new ViewClass;
    strictEqual(view.el, $("#testElement > h1").get(0));

    ViewClass = Backbone.View.extend({
      el: "#nonexistent"
    });
    view = new ViewClass;
    ok(!view.el);
  });

  test("View: with className and id functions", 2, function() {
    var View = Backbone.View.extend({
      className: function() {
        return 'className';
      },
      id: function() {
        return 'id';
      }
    });
    var view = new View();
    strictEqual(view.el.className, 'className');
    strictEqual(view.el.id, 'id');
  });

  test("View: with attributes", 2, function() {
    var view = new Backbone.View({attributes : {'class': 'one', id: 'two'}});
    equal(view.el.className, 'one');
    equal(view.el.id, 'two');
  });

  test("View: with attributes as a function", 1, function() {
    var viewClass = Backbone.View.extend({
      attributes: function() {
        return {'class': 'dynamic'};
      }
    });
    equal((new viewClass).el.className, 'dynamic');
  });

{'fraction_non_alphanumeric': 0.20130495240132634, 'fraction_numerical': 0.01112418440474917, 'mean_word_length': 3.1116974494283203, 'pattern_counts': {'":': 6, '<': 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': '1010819', 'n_tokens_mistral': 3125, 'n_tokens_neox': 3026, 'n_words': 650}