<commit_before><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<script src="http://code.jquery.com/jquery-latest.js"></script>
	<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
	<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
	<script type="text/javascript" src="../crafty.js"></script>

<script>
$(document).ready(function() {
	var first = Crafty.e("test");
	Crafty.e("test");
	Crafty.e("test");
	Crafty.e("test");
	
	Crafty.e("test2");
	Crafty.e("test2");
	Crafty.e("test2");
	Crafty.e("test2");
	
	Crafty.e("test, test2");
	Crafty.e("test, test2");
	Crafty.e("test, test2");
	Crafty.e("test, test2");
	
	Crafty.c("comp", {
		added: true
	});
	
	module("CORE");
		
	test("selectors", function() {
		equal( Crafty("test").length, 8, "Single component" );
		equal( Crafty("test test2").length, 4, "Two components ANDed" );
		equal( Crafty("test, test2").length, 12, "Two components ORed" );
		
		equal( Crafty("*").length, 13, "All components - universal selector" );
		
		equal( Crafty(1), first, "Get by ID" );
	});
	
	test("addComponent", function() {
		first.addComponent("test3");
		equal( first.has("test3"), true, "component added" );
		
		first.addComponent("comp");
		equal( first.added, true, "component with property exists" );
		
		first.addComponent("multi1, multi2");
		equal( first.has("multi1") && first.has("multi2"), true, "multiple components added" );
	});
	
	test("removeComponent", function() {
		first.removeComponent("test3");
		equal( first.has("test3"), false, "component removed");
		
		first.removeComponent("comp");
		equal( first.added && !first.has("comp"), true, "component not haz but properties remain" );
	});
	
	test("attr", function() {
		first.attr("single", true);
		equal( first.single, true, "single attribute assigned" );
		
		first.attr({prop: "test", another: 56});
		equal( first.prop, "test", "properties from object assigned" );
		equal( first.another, 56, "properties from object assigned" );
	});

    test("setter", function() {
        first.setter('p1', function(v) {this._p1 = v*2 });
        first.p1 = 2;
        equal(first._p1, 4, "single property setter");

        first.setter('p2', function(v) {this._p2 = v*2 }).setter('p3', function(v) {this._p3 = v*2 });
        first.p2 = 2;
        first.p3 = 3;
        equal(first._p2 + first._p3, 10, "two property setters");
    });
	
    test("bind", function () {
    	var triggered = false;
    	first.bind("myevent", function () {
    		triggered = true;
    	});
    	first.trigger("myevent");
    	equal(triggered, true, "custom event triggered");
    });
	
	test("unbind", function() {
		first.bind("myevent", function() {
			ok(false, "This should not be triggered (unbinding all)");
		});
		first.unbind("myevent");
		first.trigger("myevent");
		
		function callback() {
			ok(false, "This should also not be triggered (unbind by FN)");
		}
		
		function callback2() {
			ok(true, "This should be triggered");
		}
		
		first.bind("myevent", callback);
		first.bind("myevent", callback2);
		first.unbind("myevent", callback);
		first.trigger("myevent");
	});
	
	test("each", function() {
		var count = 0;
		Crafty("test").each(function(i) {
			count++;
		});
		equal(count, 8, "Iterated all elements");
	});
	
	test("requires", function() {
		Crafty.c("already", {
			already: true
		});
		Crafty.c("notyet", {
			notyet: true
		});
		
		first.addComponent("already");
		first.already = "already";
		
		first.requires("already, notyet");
		
		equal(first.already, "already", "Didn't overwrite property");
		equal(first.notyet, true, "Assigned if didn't have");<commit_msg>add unit tests<commit_after><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
                    "http://www.w3.org/TR/html4/loose.dtd">
<html>

<!-- Note to developers: To run these tests without regenerating crafty.js or
     setting up a local server:
       (1) Copy this file into the Crafty parent folder [because firefox security
             blocks local files from seeing parent folders];
       (2) Change "../crafty.js" to "./crafty-local.js" (in the HTML head below).
       (3) Now you can open the HTML file in Firefox.
       (4) Chrome has more restrictive security, you can pass a flag to loosen
             the security. Run this command in a Linux terminal:
             chromium-browser /path/to/core.html --allow-file-access-from-files
 -->

<head>
	<script src="http://code.jquery.com/jquery-latest.js"></script>
	<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
	<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
	<script type="text/javascript" src="../crafty.js"></script>

<script>

// These tests are NOT atomic / side-effect-free! They must be run in order!
QUnit.config.reorder = false;

$(document).ready(function() {
	var first = Crafty.e("test");
	Crafty.e("test");
	Crafty.e("test");
	Crafty.e("test");
	
	Crafty.e("test2");
	Crafty.e("test2");
	Crafty.e("test2");
	Crafty.e("test2");
	
	Crafty.e("test, test2");
	Crafty.e("test, test2");
	Crafty.e("test, test2");
	Crafty.e("test, test2");
	
	Crafty.c("comp", {
		added: true
	});
	
	module("CORE");
		
	test("selectors", function() {
		equal( Crafty("test").length, 8, "Single component" );
		equal( Crafty("test test2").length, 4, "Two components ANDed" );
		equal( Crafty("test, test2").length, 12, "Two components ORed" );
		
		equal( Crafty("*").length, 13, "All components - universal selector" );
		
		equal( Crafty(1), first, "Get by ID" );
	});
	
	test("addComponent", function() {
		first.addComponent("test3");
		equal( first.has("test3"), true, "component added" );
		
		first.addComponent("comp");
		equal( first.added, true, "component with property exists" );
		
		first.addComponent("multi1, multi2");
		equal( first.has("multi1") && first.has("multi2"), true, "multiple components added" );
	});
	
	test("removeComponent", function() {
		first.removeComponent("test3");
		equal( first.has("test3"), false, "component removed");
		
		first.removeComponent("comp");
		equal( first.added && !first.has("comp"), true, "component not haz but properties remain" );
	});
	
	test("attr", function() {
		first.attr("single", true);
		equal( first.single, true, "single attribute assigned" );
		
		first.attr({prop: "test", another: 56});
		equal( first.prop, "test", "properties from object assigned" );
		equal( first.another, 56, "properties from object assigned" );
	});

    test("setter", function() {
        first.setter('p1', function(v) {this._p1 = v*2 });
        first.p1 = 2;
        equal(first._p1, 4, "single property setter");

        first.setter('p2', function(v) {this._p2 = v*2 }).setter('p3', function(v) {this._p3 = v*2 });
        first.p2 = 2;
        first.p3 = 3;
        equal(first._p2 + first._p3, 10, "two property setters");
    });
	
    test("bind", function () {
    	var triggered = false;
    	first.bind("myevent", function () {
    		triggered = true;
    	});
    	first.trigger("myevent");
    	equal(triggered, true, "custom event triggered");
    });

	test("unbind", function() {
		first.bind("myevent", function() {
			ok(false, "This should not be triggered (unbinding all)");
		});
		first.unbind("myevent");
		first.trigger("myevent");
		
		function callback() {
			ok(false, "This should also not be triggered (unbind by FN)");
		}
		
		function callback2() {
			ok(true, "This should be triggered");
		}
		
		first.bind("myevent", callback);
		first.bind("myevent", callback2);
		first.unbind("myevent", callback);
		first.trigger("myevent");
	});
	
    test("globalBindAndUnbind", function () {
    	var flag = 0;
    	var add_1 = function () {flag += 1;};
    	var add_10 = function () {flag += 10;};
    	var add_100 = function () {flag += 100;};
    	Crafty.bind("theglobalevent", add_1);
    	Crafty.bind("theglobalevent", add_10);
    	Crafty.bind("theglobalevent", add_100);
    	Crafty.trigger("theglobalevent");
    	equal(flag, 111, "global event binding worked");
    	Crafty.unbind("theglobalevent", add_1);
    	Crafty.trigger("theglobalevent");
    	equal(flag, 221, "global event single-function unbinding worked");
    	Crafty.unbind("theglobalevent");
    	Crafty.trigger("theglobalevent");
    	equal(flag, 221, "global event full unbinding worked");
    });
	
	test("each", function() {
		var count = 0;
		Crafty("test").each(function(i) {
			count++;
		});
		equal(count, 8, "Iterated all elements with certain component");

		var count = 0;
		Crafty("*").each(function(i) {
			count++;
		});
		equal(count, 12, "Iterated all elements");
		
	});
	
	test("requires", function() {
		Crafty.c("already", {
			already: true
		});
		Crafty.c("notyet", {
			notyet: true
		});
		
		first.addComponent("already");
		first.already = "already";
		
		first.requires("already, notyet");
		
		equal(first.already, "already", "Didn't overwrite property");
		equal(first.notyet, true, "Assigned if didn't have");
{'fraction_non_alphanumeric': 0.18762300459217143, 'fraction_numerical': 0.017056636781106495, 'mean_word_length': 3.6360871768879877, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6490101', 'n_tokens_mistral': 3415, 'n_tokens_neox': 3012, 'n_words': 710}