Permalink
Browse files

Adding more unit tests

  • Loading branch information...
1 parent 47afa94 commit 3247be780685d53fd72e2ceda8b481db2064744b @jbrantly committed Apr 14, 2010
@@ -0,0 +1,44 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+
+ <script type="text/javascript">
+
+ var tests = [
+ ['simple', ['moduleA', 'moduleB']],
+ ['terms', ['moduleA', 'moduleB', 'moduleC', 'moduleD', 'moduleE', 'moduleF', 'moduleG']],
+ ['string', ['"\'moduleA', '"\'moduleB', '"\'moduleC"\'', '"\'moduleD"\'']],
+ ['ensuresimple', ['moduleA', 'moduleC']],
+ ['ensuredouble', ['moduleA']],
+ ['ensureterms', ['moduleA']],
+ ['ensurestrings', ['moduleA']],
+ ['knownfailure', ['moduleA']]
+ ];
+
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ test(tests[i][0], (function(test) {
+ return function() {
+ var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
+ xhr.open('GET', 'modules/'+test[0]+'.js', false);
+ xhr.send(null);
+ same(require.unit.determineShallowDependencies(xhr.responseText), test[1]);
+ };
+ })(tests[i]));
+ }
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble determineShallowDependencies</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>
@@ -0,0 +1,5 @@
+require('moduleA');
+require.ensure(['moduleB', 'moduleC'], function(require) {
+ require('moduleB');
+ require('moduleC');
+});
@@ -0,0 +1,5 @@
+require('moduleA');
+require.ensure(['moduleB'], function(require) {
+ require('moduleB');
+ require('moduleC');
+});
@@ -0,0 +1,5 @@
+require('moduleA');
+require.ensure(['[moduleB]', '[moduleC]'], function(require) {
+ require('[moduleB]');
+ require('[moduleC]');
+});
@@ -0,0 +1,11 @@
+require('moduleA');
+require.ensure(
+ [
+ 'moduleB',
+ 'moduleC'
+ ],
+ function(require) {
+ require('moduleB');
+ require('moduleC');
+ }
+);
@@ -0,0 +1,4 @@
+require('moduleA');
+require.ensure(['moduleA'], function(require) {
+ require('moduleA');
+});
@@ -0,0 +1,2 @@
+require("moduleA");
+require('moduleB');
@@ -0,0 +1,4 @@
+require("\"'moduleA");
+require('"\'moduleB');
+require("\"'moduleC\"'");
+require('"\'moduleD"\'');
@@ -0,0 +1,12 @@
+require('moduleA');
+$require('bad');
+_require('bad');
+;require('moduleB');
+something.require('bad');
+require ('moduleC');
+require ('moduleD');
+require
+('moduleE');
+require
+require( 'moduleF' );
+require( 'moduleG' );
@@ -0,0 +1,268 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html>
+ <head>
+ <title></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+
+ <script type="text/javascript" src="../../yabble.js"></script>
+
+ <script type="text/javascript" src="../qunit.js"></script>
+ <link rel="stylesheet" href="../qunit.css" type="text/css" media="screen" />
+
+ <script type="text/javascript">
+ var absolutes = [
+ ['moduleId', 'moduleId'],
+ ['path/moduleId', 'path/moduleId'],
+ ['path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ var relativesdot = [
+ ['./moduleId', 'moduleId'],
+ ['./path/moduleId', 'path/moduleId'],
+ ['./path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ var relativesup1 = [
+ ['../moduleId', '../moduleId'],
+ ['../path/moduleId', '../path/moduleId'],
+ ['../path/path2/moduleId', '../path/path2/moduleId']
+ ];
+
+
+
+ test("no refpath, absolute", function() {
+ var tests = [
+ ['moduleId', 'moduleId'],
+ ['path/moduleId', 'path/moduleId'],
+ ['path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0]), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("no refpath, relative to current", function() {
+ var tests = [
+ ['./moduleId', 'moduleId'],
+ ['./path/moduleId', 'path/moduleId'],
+ ['./path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0]), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("no refpath, relative up one", function() {
+ var tests = [
+ ['../moduleId', '../moduleId'],
+ ['../path/moduleId', '../path/moduleId'],
+ ['../path/path2/moduleId', '../path/path2/moduleId']
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0]), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("no refpath, relative up two", function() {
+ var tests = [
+ ['../../moduleId', '../../moduleId'],
+ ['../../path/moduleId', '../../path/moduleId'],
+ ['../../path/path2/moduleId', '../../path/path2/moduleId']
+ ];
+
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0]), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath, absolute", function() {
+ var tests = [
+ ['moduleId', 'moduleId'],
+ ['path/moduleId', 'path/moduleId'],
+ ['path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath, relative to current", function() {
+ var tests = [
+ ['./moduleId', 'basePath/moduleId'],
+ ['./path/moduleId', 'basePath/path/moduleId'],
+ ['./path/path2/moduleId', 'basePath/path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath, relative up one", function() {
+ var tests = [
+ ['../moduleId', 'moduleId'],
+ ['../path/moduleId', 'path/moduleId'],
+ ['../path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath, relative up two", function() {
+ var tests = [
+ ['../../moduleId', '../moduleId'],
+ ['../../path/moduleId', '../path/moduleId'],
+ ['../../path/path2/moduleId', '../path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath, relative up three", function() {
+ var tests = [
+ ['../../../moduleId', '../../moduleId'],
+ ['../../../path/moduleId', '../../path/moduleId'],
+ ['../../../path/path2/moduleId', '../../path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath/basePath2, absolute", function() {
+ var tests = [
+ ['moduleId', 'moduleId'],
+ ['path/moduleId', 'path/moduleId'],
+ ['path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath/basePath2';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/basePath2/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath/basePath2, relative to current", function() {
+ var tests = [
+ ['./moduleId', 'basePath/basePath2/moduleId'],
+ ['./path/moduleId', 'basePath/basePath2/path/moduleId'],
+ ['./path/path2/moduleId', 'basePath/basePath2/path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath/basePath2';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/basePath2/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath/basePath2, relative up one", function() {
+ var tests = [
+ ['../moduleId', 'basePath/moduleId'],
+ ['../path/moduleId', 'basePath/path/moduleId'],
+ ['../path/path2/moduleId', 'basePath/path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath/basePath2';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/basePath2/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath/basePath2, relative up two", function() {
+ var tests = [
+ ['../../moduleId', 'moduleId'],
+ ['../../path/moduleId', 'path/moduleId'],
+ ['../../path/path2/moduleId', 'path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath/basePath2';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/basePath2/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+
+ test("refpath = basePath/basePath2, relative up three", function() {
+ var tests = [
+ ['../../../moduleId', '../moduleId'],
+ ['../../../path/moduleId', '../path/moduleId'],
+ ['../../../path/path2/moduleId', '../path/path2/moduleId']
+ ];
+
+ var basePath = 'basePath/basePath2';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+
+ var basePath = 'basePath/basePath2/';
+ for (var i = 0, n = tests.length; i<n; i++) {
+ equals(require.unit.resolveModuleId(tests[i][0], basePath), tests[i][1], tests[i][0]);
+ }
+ });
+ </script>
+ </head>
+ <body>
+ <h1 id="qunit-header">Yabble resolveModuleId</h1>
+ <h2 id="qunit-banner"></h2>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ </body>
+</html>

0 comments on commit 3247be7

Please sign in to comment.