Permalink
Browse files

v0.28

  • Loading branch information...
1 parent d53233d commit a1cf8df55c8c630569ec9a4e3b8aed3555755ae9 ingy committed Aug 28, 2008
View
@@ -1,6 +1,13 @@
---
+version: 0.16
+date: Thu Aug 28 00:43:35 PDT 2008
+changes:
+- Add section_delim config option.
+- Added 'eval' filter.
+
+---
version: 0.15
-date: Fri Aug 22 15:36:35 PDT 2008
+date: Thu Aug 28 00:21:25 PDT 2008
changes:
- Update sample Makefile to be more portable
- Add in Socialtext refactorings from the last couple years
View
@@ -2,8 +2,8 @@ use inc::Module::Install;
all_from 'lib/JS/Test/Base.pod';
-requires 'JS' => '0.15';
-requires 'JS::Test::Simple' => '0.27';
+requires 'JS' => '0.17';
+requires 'JS::Test::Simple' => '0.28';
clean_files 'META.yml';
View
@@ -3,5 +3,5 @@ use Test::More tests => 1;
use JS::Test::Base;
-is $JS::Test::Base::VERSION, '0.14',
+is $JS::Test::Base::VERSION, '0.16',
'Perl Module loads';
@@ -3,7 +3,7 @@ Test.Base = function() {
}
proto = Test.Base.prototype;
-Test.Base.VERSION = '0.14';
+Test.Base.VERSION = '0.16';
proto.init = function() {
this.builder = Test.Builder.instance();
@@ -2,7 +2,7 @@ package JS::Test::Base;
use 5.008;
-our $VERSION = '0.14';
+our $VERSION = '0.16';
1;
View
@@ -6,7 +6,7 @@ Test.Base = function() {
}
var proto = Test.Base.prototype;
-Test.Base.VERSION = '0.15';
+Test.Base.VERSION = '0.16';
Test.Base.newSubclass = function(name, base, isFinal) {
if (
@@ -62,6 +62,7 @@ proto.init = function() {
this.state.spec_content = null;
this.state.filters_map = {};
this.state.blocks = [];
+ this.section_delim = '---';
}
proto.spec = function(url) {
@@ -173,8 +174,8 @@ proto.make_block = function(hunk) {
block.name = name.replace(/^\s*(.*?)\s*$/, '$1');
var chunks = [];
- while (hunk.indexOf('\n--- ') >= 0) {
- index = hunk.indexOf('\n--- ') + 1;
+ while (hunk.indexOf('\n' + this.section_delim + ' ') >= 0) {
+ index = hunk.indexOf('\n' + this.section_delim + ' ') + 1;
var chunk = hunk.substr(0, index);
hunk = hunk.substr(index);
chunks.push(chunk);
@@ -187,7 +188,12 @@ proto.make_block = function(hunk) {
if (index < 0) throw('xxx1');
var line1 = chunk.substr(0, index);
var section_data = chunk.substr(index + 1);
- line1 = line1.replace(/^---\s+/, '');
+ var re = new RegExp(
+ '^' +
+ this.section_delim.replace(/([\+\*])/g, '\\$1') +
+ '\\s+'
+ );
+ line1 = line1.replace(re, '');
if (! line1.length) throw('xxx2');
var section_name = '';
var section_filters = [];
@@ -264,7 +270,10 @@ proto.filter_section = function(section, filters) {
if (typeof filter == 'function') {
data = filter.call(this, data, this);
}
- else if (typeof window[filter] == 'function')
+ else if (
+ typeof window[filter] == 'function' &&
+ filter != 'eval'
+ )
data = (window[filter]).call(this, data, this);
else if (typeof this.filter_object[filter] == 'function')
data = (this.filter_object[filter]).call(this, data, this);
@@ -304,6 +313,12 @@ proto.evaluate = function(content, block) {
return object;
}
+proto.eval = function(content, block) {
+ var javascript = content;
+ var object = eval(content);
+ return object;
+}
+
//------------------------------------------------------------------------------
// Debugging Support
//------------------------------------------------------------------------------
@@ -1,9 +1,56 @@
+// XXX Wrap this class.
+// (function() {
+
Test.Base = function() {
this.init.apply(this, arguments);
}
-proto = Test.Base.prototype;
+var proto = Test.Base.prototype;
+
+Test.Base.VERSION = '0.15';
+
+Test.Base.newSubclass = function(name, base, isFinal) {
+ if (
+ !name || typeof(name) != 'string' ||
+ base && typeof(base) != 'string'
+ ) throw "Usage: Test.Base.newSubclass('subclass.name' [, 'baseclass.name'])";
+ if (!base)
+ base = 'Test.Base';
+
+ var parts = name.split('.');
+ var subclass = window;
+ for (var i = 0; i < parts.length; i++) {
+ if (! subclass[parts[i]])
+ subclass[parts[i]] = function() {
+ try { this.init() } catch(e) {throw(e)}
+ };
+ subclass = subclass[parts[i]];
+ }
+
+ var baseclass = eval('new ' + base + '()');
+ subclass.prototype = baseclass;
+ subclass.prototype.className = name;
+ subclass.prototype.baseClassName = base;
+
+ if (! isFinal) {
+ subclass.prototype.init = function() {
+ eval(base).prototype.init.call(this);
+ this.block_class = name + '.Block';
+ }
+
+ var block_proto =
+ Test.Base.newSubclass(name + '.Block', base + '.Block', true);
-Test.Base.VERSION = '0.14';
+ block_proto.init = function() {
+ eval(base + '.Block').prototype.init.call(this);
+ this.filter_object = eval('new ' + name + '.Filter()');
+ }
+
+ Test.Base.newSubclass(name + '.Filter', base + '.Filter', true);
+ }
+
+ subclass.prototype.classname = name;
+ return subclass.prototype;
+}
proto.init = function() {
this.builder = Test.Builder.instance();
@@ -15,6 +62,7 @@ proto.init = function() {
this.state.spec_content = null;
this.state.filters_map = {};
this.state.blocks = [];
+ this.section_delim = '---';
}
proto.spec = function(url) {
@@ -41,6 +89,7 @@ proto.run_is = function(x, y) {
}
}
+// TODO Add more proxy functions for common builder stuffs
proto.plan = function(number) {
var cmds = {tests: number};
return this.builder.plan(cmds);
@@ -54,6 +103,10 @@ proto.fail = function(name) {
return this.builder.ok(false, name);
}
+proto.ok = function(test, desc) {
+ this.builder.ok(test, desc);
+}
+
proto.is = function (got, expect, desc) {
return this.builder.isEq(got, expect, desc);
};
@@ -70,6 +123,14 @@ proto.unlike = function (val, regex, desc) {
return this.builder.unlike(val, regex, desc);
};
+proto.skip = function(why) {
+ return this.builder.skip(why);
+};
+
+proto.skipAll = function(why) {
+ return this.builder.skipAll(why);
+};
+
proto.compile = function() {
if (this.state.compiled) return;
this.get_spec();
@@ -113,8 +174,8 @@ proto.make_block = function(hunk) {
block.name = name.replace(/^\s*(.*?)\s*$/, '$1');
var chunks = [];
- while (hunk.indexOf('\n--- ') >= 0) {
- index = hunk.indexOf('\n--- ') + 1;
+ while (hunk.indexOf('\n' + this.section_delim + ' ') >= 0) {
+ index = hunk.indexOf('\n' + this.section_delim + ' ') + 1;
var chunk = hunk.substr(0, index);
hunk = hunk.substr(index);
chunks.push(chunk);
@@ -127,7 +188,12 @@ proto.make_block = function(hunk) {
if (index < 0) throw('xxx1');
var line1 = chunk.substr(0, index);
var section_data = chunk.substr(index + 1);
- line1 = line1.replace(/^---\s*/, '');
+ var re = new RegExp(
+ '^' +
+ this.section_delim.replace(/([\+\*])/g, '\\$1') +
+ '\\s+'
+ );
+ line1 = line1.replace(re, '');
if (! line1.length) throw('xxx2');
var section_name = '';
var section_filters = [];
@@ -201,7 +267,13 @@ proto.filter_section = function(section, filters) {
var data = this.data[section];
for (var i = 0; i < filters.length; i++) {
var filter = filters[i];
- if (typeof window[filter] == 'function')
+ if (typeof filter == 'function') {
+ data = filter.call(this, data, this);
+ }
+ else if (
+ typeof window[filter] == 'function' &&
+ filter != 'eval'
+ )
data = (window[filter]).call(this, data, this);
else if (typeof this.filter_object[filter] == 'function')
data = (this.filter_object[filter]).call(this, data, this);
@@ -241,6 +313,12 @@ proto.evaluate = function(content, block) {
return object;
}
+proto.eval = function(content, block) {
+ var javascript = content;
+ var object = eval(content);
+ return object;
+}
+
//------------------------------------------------------------------------------
// Debugging Support
//------------------------------------------------------------------------------
@@ -249,10 +327,11 @@ function XXX(msg) {
//if (! confirm(arguments.join('\n')))
if (! confirm(msg))
throw("terminated...");
+ return msg;
}
function JJJ(obj) {
- XXX(JSON.stringify(obj));
+ return XXX(JSON.stringify(obj));
}
//------------------------------------------------------------------------------
@@ -1,4 +1,4 @@
-// $Id: /mirror/openjsan/users/theory/Test.Simple/trunk/lib/Test/Builder.js 22299 2008-08-07T04:29:11.167550Z theory $
+// $Id: /mirror/openjsan/users/theory/Test.Simple/trunk/lib/Test/Builder.js 2136 2008-08-22T22:17:42.999815Z theory $
/*global JSAN, Test, WScript, _global */
@@ -36,7 +36,7 @@ Test.Builder.globalScope = typeof JSAN != 'undefined'
? _global
: this;
-Test.Builder.VERSION = '0.27';
+Test.Builder.VERSION = '0.28';
Test.Builder.Instances = [];
Test.Builder.lineEndingRx = /\r?\n|\r/g;
Test.Builder.StringOps = {
@@ -279,6 +279,7 @@ Test.Builder.prototype.ok = function (test, desc) {
this._print(out);
if (!test) {
+ // Add URL and line numer using code from http://pastie.org/253058?
var msg = todo ? "Failed (TODO)" : "Failed";
this.diag(" " + msg + " test");
}
@@ -1,4 +1,4 @@
-// $Id: /mirror/openjsan/users/theory/Test.Simple/trunk/lib/Test/Harness.js 22299 2008-08-07T04:29:11.167550Z theory $
+// $Id: /mirror/openjsan/users/theory/Test.Simple/trunk/lib/Test/Harness.js 1950 2008-08-20T06:40:51.750920Z ingy $
/*global JSAN, Test, _global, _player */
@@ -16,7 +16,7 @@ if (typeof self != 'undefined') {
}
Test.Harness = function () {};
-Test.Harness.VERSION = '0.27';
+Test.Harness.VERSION = '0.28';
Test.Harness.Done = 0;
// Stoopid IE.
@@ -1,4 +1,4 @@
-// $Id: /mirror/openjsan/users/theory/Test.Simple/trunk/lib/Test/Harness/Browser.js 1942 2008-08-07T04:29:11.167550Z theory $
+// $Id: /mirror/openjsan/users/theory/Test.Simple/trunk/lib/Test/Harness/Browser.js 2139 2008-08-22T23:44:09.596660Z ingy $
/*global JSAN, Test, ActiveXObject */
@@ -74,7 +74,7 @@ if (window.parent != window &&
this.includes.push('');
};
- Test.Harness.Browser.VERSION = '0.26';
+ Test.Harness.Browser.VERSION = '0.28';
Test.Harness.Browser.runTests = function () {
var harness = new Test.Harness.Browser();
@@ -113,7 +113,9 @@ if (window.parent != window &&
// Trailing space added and replaced to work around yet another
// Safari bug.
node.innerHTML = node.innerHTML.replace(
- / ?(\w[\w\.\-]+?\w)(?=\.\.\.)/m, '<a href="$1">$1</a>'
+ / ?(\w[\w\.\-]+?\w)(?=\.\.\.)/m,
+ (/MSIE/.test(navigator.userAgent) ? '<br>' : '') +
+ '<a href="$1">$1</a>'
) + ' ';
};
return {

0 comments on commit a1cf8df

Please sign in to comment.