<commit_before>describe("a realm", function() {

	var global = Function('return this')();
	var globalRealm = global.realm || require('..');
	var Realm = globalRealm.constructor;

	var testRealm;

	beforeEach(function() {
		testRealm = new Realm();
	});

	it("does not call definition functions on define.", function() {
		var definitionHasBeenCalled = false;
		testRealm.define('MyClass', function(require, exports, module) {
			definitionHasBeenCalled = true;
			module.exports = function MyClass() {};
		});
		expect(definitionHasBeenCalled).toBe(false);
	});

	it("allows one definition to require a definition defined later.", function() {
		var CLASSA = function() {};
		testRealm.define("ClassB", function(require, exports, module) {
			exports.parent = require("ClassA");
		});
		testRealm.define("ClassA", function(require, exports, module) {
			module.exports = CLASSA;
		});

		var classB = testRealm.require('ClassB');
		expect(classB.parent).toBe(CLASSA);
	});

	it("allows one definition to require another in a relative way.", function() {
		var CLASSA = function() {};
		testRealm.define("my/classes/derived/ClassB", function(require, exports, module) {
			exports.parent = require("../original/ClassA");
		});
		testRealm.define("my/classes/original/ClassA", function(require, exports, module) {
			module.exports = CLASSA;
		});

		var classB = testRealm.require('my/classes/derived/ClassB');
		expect(classB.parent).toBe(CLASSA);
	});

	it("throws an error if there is a circular reference", function() {
		var CLASSA = function() {};
		testRealm.define("ClassA", function(require, exports, module) {
			require("ClassB");
			module.exports = CLASSA;
		});
		var CLASSB = function() {};
		testRealm.define("ClassB", function(require, exports, module) {
			require("ClassA");
			module.exports = CLASSB;
		});

		expect(function() {
			testRealm.require('ClassA');
		}).toThrow(Error("Circular dependency detected: the module 'ClassA' (requested by module 'ClassB') is still in the process of exporting."));
	});

	it("we consider it to be a circular reference even if a module has partially exported", function() {
		var CLASSA = function() {};
		testRealm.define("ClassA", function(require, exports, module) {
			require("ClassB");
			module.exports = CLASSA;
		});
		testRealm.define("ClassB", function(require, exports, module) {
			exports.X = 'X';
			require("ClassA");
			exports.Y = 'Y';
		});

		expect(function() {
			testRealm.require('ClassA');
		}).toThrow(Error("Circular dependency detected: the module 'ClassA' (requested by module 'ClassB') is still in the process of exporting."));
	});

	it("we don't consider it to be a circular reference if the module has already exported at the point the circle is formed", function() {
		var CLASSA = function() {};
		testRealm.define("ClassA", function(require, exports, module) {
			module.exports = CLASSA;
			require("ClassB");
		});
		var CLASSB = function() {};
		testRealm.define("ClassB", function(require, exports, module) {
			require("ClassA");
			module.exports = CLASSB;
		});

		testRealm.require('ClassA');
	});

	it("allows the redefinition of a class in a subrealm.", function() {
		var CLASSA = function() {};
		testRealm.define("my/classes/derived/ClassB", function(require, exports, module) {
			exports.parent = require("../original/ClassA");
		});
		testRealm.define("my/classes/original/ClassA", function(require, exports, module) {
			module.exports = CLASSA;
		});

		var classB = testRealm.require('my/classes/derived/ClassB');<commit_msg>Improved the success-case circular depenendency test so that it verifies that what gets returened when a circular dependency has been detected is actually valid.<commit_after>describe("a realm", function() {

	var global = Function('return this')();
	var globalRealm = global.realm || require('..');
	var Realm = globalRealm.constructor;

	var testRealm;

	beforeEach(function() {
		testRealm = new Realm();
	});

	it("does not call definition functions on define.", function() {
		var definitionHasBeenCalled = false;
		testRealm.define('MyClass', function(require, exports, module) {
			definitionHasBeenCalled = true;
			module.exports = function MyClass() {};
		});
		expect(definitionHasBeenCalled).toBe(false);
	});

	it("allows one definition to require a definition defined later.", function() {
		var CLASSA = function() {};
		testRealm.define("ClassB", function(require, exports, module) {
			exports.parent = require("ClassA");
		});
		testRealm.define("ClassA", function(require, exports, module) {
			module.exports = CLASSA;
		});

		var classB = testRealm.require('ClassB');
		expect(classB.parent).toBe(CLASSA);
	});

	it("allows one definition to require another in a relative way.", function() {
		var CLASSA = function() {};
		testRealm.define("my/classes/derived/ClassB", function(require, exports, module) {
			exports.parent = require("../original/ClassA");
		});
		testRealm.define("my/classes/original/ClassA", function(require, exports, module) {
			module.exports = CLASSA;
		});

		var classB = testRealm.require('my/classes/derived/ClassB');
		expect(classB.parent).toBe(CLASSA);
	});

	it("throws an error if there is a circular reference", function() {
		var CLASSA = function() {};
		testRealm.define("ClassA", function(require, exports, module) {
			require("ClassB");
			module.exports = CLASSA;
		});
		var CLASSB = function() {};
		testRealm.define("ClassB", function(require, exports, module) {
			require("ClassA");
			module.exports = CLASSB;
		});

		expect(function() {
			testRealm.require('ClassA');
		}).toThrow(Error("Circular dependency detected: the module 'ClassA' (requested by module 'ClassB') is still in the process of exporting."));
	});

	it("we consider it to be a circular reference even if a module has partially exported", function() {
		var CLASSA = function() {};
		testRealm.define("ClassA", function(require, exports, module) {
			require("ClassB");
			module.exports = CLASSA;
		});
		testRealm.define("ClassB", function(require, exports, module) {
			exports.X = 'X';
			require("ClassA");
			exports.Y = 'Y';
		});

		expect(function() {
			testRealm.require('ClassA');
		}).toThrow(Error("Circular dependency detected: the module 'ClassA' (requested by module 'ClassB') is still in the process of exporting."));
	});

	it("we don't consider it to be a circular reference if the module has already exported at the point the circle is formed", function() {
		testRealm.define("ClassA", function(require, exports, module) {
			function LocalClass() {
			};
			module.exports = LocalClass;
			require("ClassB");
		});
		testRealm.define("ClassB", function(require, exports, module) {
			var SuperClass = require("ClassA");
			function LocalClass() {
			};
			LocalClass.prototype = new SuperClass();
			module.exports = LocalClass;
		});

		var ClassA = testRealm.require('ClassA');
		var ClassB = testRealm.require('ClassB');
		expect((new ClassB()) instanceof ClassA).toBeTruthy();
	});

	it("allows the redefinition of a class in a subrealm.", function() {
		var CLASSA = function() {};
		testRealm.define("my/classes/derived/ClassB", function(require, exports, module) {
			exports.parent = require("../original/ClassA");
		});
		testRealm.define("my/classes/original/ClassA", function(require, exports, module) {
			module.exports = CLASSA;
		});

		var classB = testRealm.require('my/classes/derived/ClassB');
{'fraction_non_alphanumeric': 0.15374241402562375, 'fraction_numerical': 0.0, 'mean_word_length': 4.592760180995475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2836826', 'n_tokens_mistral': 2483, 'n_tokens_neox': 2235, 'n_words': 584}