<commit_before>describe('Mutiny.init()', function() {
  beforeEach(function() {
    Mutiny.widget = {
      'init': function(){}
    };
    spyOn(Mutiny.widget, 'init');
  });

  afterEach(function() {
    delete Mutiny.widget;
  });

  describe("<div data-mutiny-widget='' />", function() {
    beforeEach(function() {
      this.el = $("<div data-mutiny-widget='' />");
    });

    it("invokes with empty options", function() {
      Mutiny.init(this.el);
      expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {});
    });

    it("invokes with defaults", function() {
      Mutiny.widget.defaults = {'default': 'option'};
      Mutiny.init(this.el);
      expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'default': 'option'});
    });
  });

  describe('<div data-mutiny-widget=\'{"key": "value"}\' />', function() {
    beforeEach(function() {
      this.el = $('<div data-mutiny-widget=\'{"key": "value"}\' />');
    });

    it("invokes with options", function() {
      Mutiny.init(this.el);
      expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'key': 'value'});
    });

    it("invokes with defaults merged with options", function() {
      Mutiny.widget.defaults = {'default': 'option'};
      Mutiny.init(this.el);
      expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'default': 'option', 'key': 'value'});
    });

    it("invokes with overridden defaults", function() {
      Mutiny.widget.defaults = {'key': 'default'};
      Mutiny.init(this.el);
      expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'key': 'value'});
    });
  });

  describe('<div data-mutiny-widget="string" />', function() {
    beforeEach(function() {
      this.el = $('<div data-mutiny-widget="string" />');
    });

    it("cannot parse stringArg by default", function() {
      var el = this.el;
      expect(function() {
        Mutiny.init(el);
      }).toThrow('"widget" cannot parse "string"');
    });

    describe('with stringArg defined', function() {
      beforeEach(function() {
        Mutiny.widget.stringArg = 'objectize';
        this.el = $('<div data-mutiny-widget="string" />');
      });

      it("converts options into {Mutiny.widget.stringArg: 'string'}", function() {
        Mutiny.init(this.el);
        expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'objectize': 'string'});
      });

      it("merges defaults with options", function() {
        Mutiny.widget.defaults = {'default': 'option'};
        Mutiny.init(this.el);
        expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'default': 'option', 'objectize': 'string'});
      });

      it("overrides defaults with options", function() {
        Mutiny.widget.defaults = {'objectize': 'default'};
        Mutiny.init(this.el);
        expect(Mutiny.widget.init).wasCalledWith($(this.el[0]), {'objectize': 'string'});
      });
    });
  });

  describe("<div data-custom-widget=''>", function() {
    beforeEach(function() {
      this.el = $("<div data-custom-widget='' />");
    });

    it("triggers using argument", function() {
      Mutiny.init(this.el, 'custom');
      expect(Mutiny.widget.init).wasCalled();
    });
  });

  describe("exceptions", function() {
    it("<div data-mutiny-nonexistent=''> throws nonexistent widget", function() {
      var el = $("<div data-mutiny-nonexistent='' />");
      expect(function() {
        Mutiny.init(el);
      }).toThrow('"nonexistent" not found');
    });
  });
});
<commit_msg>Moved tests to Mutiny.widgets namespace<commit_after>describe('Mutiny.init()', function() {
  beforeEach(function() {
    Mutiny.widgets.widget = {
      'init': function(){}
    };
    spyOn(Mutiny.widgets.widget, 'init');
  });

  afterEach(function() {
    delete Mutiny.widgets.widget;
  });

  describe("<div data-mutiny-widget='' />", function() {
    beforeEach(function() {
      this.el = $("<div data-mutiny-widget='' />");
    });

    it("invokes with empty options", function() {
      Mutiny.init(this.el);
      expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {});
    });

    it("invokes with defaults", function() {
      Mutiny.widgets.widget.defaults = {'default': 'option'};
      Mutiny.init(this.el);
      expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'default': 'option'});
    });
  });

  describe('<div data-mutiny-widget=\'{"key": "value"}\' />', function() {
    beforeEach(function() {
      this.el = $('<div data-mutiny-widget=\'{"key": "value"}\' />');
    });

    it("invokes with options", function() {
      Mutiny.init(this.el);
      expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'key': 'value'});
    });

    it("invokes with defaults merged with options", function() {
      Mutiny.widgets.widget.defaults = {'default': 'option'};
      Mutiny.init(this.el);
      expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'default': 'option', 'key': 'value'});
    });

    it("invokes with overridden defaults", function() {
      Mutiny.widgets.widget.defaults = {'key': 'default'};
      Mutiny.init(this.el);
      expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'key': 'value'});
    });
  });

  describe('<div data-mutiny-widget="string" />', function() {
    beforeEach(function() {
      this.el = $('<div data-mutiny-widget="string" />');
    });

    it("cannot parse stringArg by default", function() {
      var el = this.el;
      expect(function() {
        Mutiny.init(el);
      }).toThrow('"widget" cannot parse "string"');
    });

    describe('with stringArg defined', function() {
      beforeEach(function() {
        Mutiny.widgets.widget.stringArg = 'objectize';
        this.el = $('<div data-mutiny-widget="string" />');
      });

      it("converts options into {Mutiny.widgets.widget.stringArg: 'string'}", function() {
        Mutiny.init(this.el);
        expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'objectize': 'string'});
      });

      it("merges defaults with options", function() {
        Mutiny.widgets.widget.defaults = {'default': 'option'};
        Mutiny.init(this.el);
        expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'default': 'option', 'objectize': 'string'});
      });

      it("overrides defaults with options", function() {
        Mutiny.widgets.widget.defaults = {'objectize': 'default'};
        Mutiny.init(this.el);
        expect(Mutiny.widgets.widget.init).wasCalledWith($(this.el[0]), {'objectize': 'string'});
      });
    });
  });

  describe("<div data-custom-widget=''>", function() {
    beforeEach(function() {
      this.el = $("<div data-custom-widget='' />");
    });

    it("triggers using argument", function() {
      Mutiny.init(this.el, 'custom');
      expect(Mutiny.widgets.widget.init).wasCalled();
    });
  });

  describe("exceptions", function() {
    it("<div data-mutiny-nonexistent=''> throws nonexistent widget", function() {
      var el = $("<div data-mutiny-nonexistent='' />");
      expect(function() {
        Mutiny.init(el);
      }).toThrow('"nonexistent" not found');
    });
  });
});

{'fraction_non_alphanumeric': 0.21458625525946703, 'fraction_numerical': 0.002244039270687237, 'mean_word_length': 3.1873165002935995, 'pattern_counts': {'":': 4, '<': 25, '<?xml version=': 0, '>': 25, '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': '1326145', 'n_tokens_mistral': 2315, 'n_tokens_neox': 2274, 'n_words': 366}