⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tinyunit.class.js

📁 一款使用javascript為基礎的html產生器 很不錯用的html editor source code
💻 JS
字号:
var TinyUnit = {
	_failures : new Array(),
	_currentTest : '',
	_assertCount : 0,

	init : function(s) {
	},

	assert : function(/*[comment], boolean_value*/) {
		var v = TinyUnit.getValueArg(arguments);
		var c = TinyUnit.getCommentArg(arguments);

		if (!v)
			TinyUnit._failures[TinyUnit._failures.length] = c;

		TinyUnit._assertCount++;
	},

	getValueArg : function(a) {
		if (a.length > 1)
			return a[1];

		return a[0];
	},

	getCommentArg : function(a) {
		if (a.length > 1)
			return 'Assert ' + TinyUnit._assertCount + ' failed, ' + a[0] + '.';

		return 'Assert ' + TinyUnit._assertCount + ' failed. ';
	},

	run : function(t) {
		var n, d = document, r = d.getElementById('result'), e, h, i;

		for (n in t) {
			// Reset states
			TinyUnit._assertCount = 0;
			TinyUnit._failures = new Array();
			TinyUnit._currentTest = n;
			h = '';

			// Run test
			t[n]();

			// Create failure
			if (TinyUnit._failures.length > 0) {
				h = '<div class="failedtest"><div>Test \"' + n + '\" failed, assers: ' + TinyUnit._assertCount + ', failures: ' + TinyUnit._failures.length + ':</div>';

				for (i=0; i<TinyUnit._failures.length; i++)
					h += '<div class="failed">' + TinyUnit._failures[i] + '</div>';

				h += '</div>';
			} else
				h = '<div class="passedtest">Test \"' + n + '\" passed, assers: ' + TinyUnit._assertCount + '.</div>';

			e = d.createElement("div");
			e.innerHTML = h;

			r.appendChild(e);
		}
	}
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -