<commit_before>module("Rules");

test("Undefined", function() {
	
	strictEqual( dominoes.rule("non-existing") , undefined , "Undefined was returned" );
	
});

test("Setting / retrieving", function() {
	
	strictEqual ( dominoes.rule( "test" , "SOME_URL" ) , dominoes , "Setting a rule returns dominoes" );
	strictEqual ( {}.toString.call ( dominoes.rule( "test" ) ) , "[object Function]" , "Rules are stored as functions" );
	
});

test("Empty list" , function() {
	
	dominoes.rule( "NAME" , "" );
	
	dominoes.rule();
	
	strictEqual( dominoes.rule("NAME") , undefined , "Rules were removed" );	
	
});

test("Expansion" , function() {
	
	expect( 2 );
	
	stop();
	
	var string = "";
	
	dominoes.rule( "myFunction" , function() {
		
		string += "myFunction was called";
		
	});
	
	dominoes( "myFunction" , function() {
		
		strictEqual( string , "myFunction was called" , "Rules was properly expanded" );
		
	} , "myFunction" , function() {
		
		strictEqual( string, "myFunction was called" , "Rules are only executed once" );
		dominoes.rule();
		start();
		
	});
	
});

test("On-the-fly definition" , function() {
	
	expect( 1 );
	
	stop();
	
	var string = "";
	
	dominoes( function() {
		
		dominoes.rule("myFunction" , function() {
			
			string += "myFunction was called";
			
		});
		
	} , "myFunction" , function() {

		strictEqual( string, "myFunction was called" , "Rules can be created on-the-fly" );
		dominoes.rule();
		start();
	});
	
});

test("Multiple definition" , function() {
	
	expect( 1 );
	
	stop();
	
	var string = "";
	
	dominoes.rule( "myFunction" , function() {
		
		string += "rule 1, ";
		
	});
	
	dominoes.rule( "myFunction" , function() {
		
		string += "rule 2";
		
	});
	
	dominoes( "myFunction" , function() {

		strictEqual( string, "rule 1, rule 2" , "Rules accept multiple definitions" );
		dominoes.rule();
		start();
	});
	
});

test("On-the-fly multiple definition" , function() {
	
	expect( 1 );
	
	stop();
	
	var string = "";
	
	dominoes.rule( "myFunction" , function() {
		
		string += "rule 1, ";
		
		dominoes.rule( "myFunction" , function() {
			
			string += "rule 2";
			
		});
	
	});
	
	dominoes( "myFunction" , function() {

		strictEqual( string, "rule 1, rule 2" , "Rules accept multiple definitions" );
		dominoes.rule();
		start();
	});
	
});
<commit_msg>Added a bunch of test for rules so that it covers more ground<commit_after>module("Rules");

test("Undefined", function() {
	
	strictEqual( dominoes.rule("non-existing") , undefined , "Undefined was returned" );
	
});

test("Setting / retrieving", function() {
	
	strictEqual ( dominoes.rule( "test" , "SOME_URL" ) , dominoes , "Setting a rule returns dominoes" );
	strictEqual ( {}.toString.call ( dominoes.rule( "test" ) ) , "[object Function]" , "Rules are stored as functions" );
	
});

test("Empty list" , function() {
	
	dominoes.rule( "NAME" , "" );
	
	dominoes.rule();
	
	strictEqual( dominoes.rule("NAME") , undefined , "Rules were removed" );	
	
});

test("Expansion" , function() {
	
	expect( 2 );
	
	stop();
	
	var string = "";
	
	dominoes.rule( "myFunction" , function() {
		
		string += "myFunction was called";
		
	});
	
	dominoes( "myFunction" , function() {
		
		strictEqual( string , "myFunction was called" , "Rules was properly expanded" );
		
	} , "myFunction" , function() {
		
		strictEqual( string, "myFunction was called" , "Rules are only executed once" );
		dominoes.rule();
		start();
		
	});
	
});

test("On-the-fly definition" , function() {
	
	expect( 1 );
	
	stop();
	
	var string = "";
	
	dominoes( function() {
		
		dominoes.rule("myFunction" , function() {
			
			string += "myFunction was called";
			
		});
		
	} , "myFunction" , function() {

		strictEqual( string, "myFunction was called" , "Rules can be created on-the-fly" );
		dominoes.rule();
		start();
	});
	
});

test("Multiple definition" , function() {
	
	expect( 1 );
	
	stop();
	
	var string = "";
	
	dominoes.rule( "myFunction" , function() {
		
		string += "rule 1, ";
		
	});
	
	dominoes.rule( "myFunction" , function() {
		
		string += "rule 2";
		
	});
	
	dominoes( "myFunction" , function() {

		strictEqual( string, "rule 1, rule 2" , "Rules accept multiple definitions" );
		dominoes.rule();
		start();
	});
	
});

test("On-the-fly multiple definition" , function() {
	
	expect( 1 );
	
	stop();
	
	var string = "";
	
	dominoes.rule( "myFunction" , function() {
		
		string += "rule 1, ";
		
		dominoes.rule( "myFunction" , function() {
			
			string += "rule 2";
			
		});
	
	});
	
	dominoes( "myFunction" , function() {

		strictEqual( string, "rule 1, rule 2" , "Rules accept multiple definitions" );
		dominoes.rule();
		start();
	});
	
});

test("Recursive definitions" , function() {
	
	stop();
	
	var flag = false;
	
	dominoes.rule( "secondLevel" , function() {
		
		flag = true;
		
	} );
	
	dominoes.rule( "firstLevel" , "secondLevel" );
	
	dominoes( "firstLevel" , function() {
		
		ok( flag , "Recursive definition was expanded" );
		dominoes.rule();
		start();
		
	} );
	
});

test("URL rule" , function() {
	
	window.DOMINOES_UNIT_STRING = "";
	
	stop();
	
	dominoes.rule( "url" , url("./data/concat.php?wait=200&str=a") );
	
	dominoes( "url" , function() {
		
		strictEqual( window.DOMINOES_UNIT_STRING , "a" , "Script was blocking" );
		dominoes.rule();
		start();
		
	});
	
});

test("Function rule" , function() {
	
	window.DOMINOES_UNIT_STRING = "";
	
	stop();
	
	dominoes.rule( "function" , function( callback ) {
		setTimeout( function() {
			window.DOMINOES_UNIT_STRING += "a";
			callback();
		} , 100);
		return TRUE;
	} );
	
	dominoes( "function" , function() {
		
		strictEqual( window.DOMINOES_UNIT_STRING , "a" , "Script was blocking" );
		dominoes.rule();
		start();
		
	});
	
});

test("Sequenced dependencies" , function() {
	
	window.DOMINOES_UNIT_STRING = "";
	
	stop();
	
	dominoes.rule( "module1.load" , url("./data/module.php?number=1&load=") );
	dominoes.rule( "module2.load" , url("./data/module.php?number=2&load=") );
	dominoes.rule( "module3.load" , url("./data/module.php?number=3&load=") );
	
	dominoes.rule( "module1" , "module1.load > module1.start" );
	dominoes.rule( "module2" , "module2.load module1 > module2.start" );
	dominoes.rule( "module3" , "module3.load module2 > module3.start" );
	
	dominoes( "module3" , function() {
		strictEqual( window.DOMINOES_UNIT_STRING , "L3L2L1S1S2S3" , "Script cascading dependencies handled properly" );
		dominoes.rule();
		start();
	});
	
});

test("Sequenced dependencies (all together" , function() {
	
	window.DOMINOES_UNIT_STRING = "";
	
	stop();
	
	dominoes.rule( "module1.load" , url("./data/module.php?number=1") );
	dominoes.rule( "module2.load" , url("./data/module.php?number=2") );
	dominoes.rule( "module3.load" , url("./data/module.php?number=3") );
	
	dominoes.rule( "module1" , "module1.load > module1.start" );
	dominoes.rule( "module2" , "module2.load module1 > module2.start" );
	dominoes.rule( "module3" , "module3.load module2 > module3.start" );
	
	dominoes( "module1 module2 module3" , function() {
		strictEqual( window.DOMINOES_UNIT_STRING , "S1S2S3" , "Script cascading dependencies handled properly" );
		dominoes.rule();
		start();
	});
	
});

{'fraction_non_alphanumeric': 0.18515417887540114, 'fraction_numerical': 0.010743686340170224, 'mean_word_length': 3.482801751094434, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4971069', 'n_tokens_mistral': 2842, 'n_tokens_neox': 2431, 'n_words': 543}