From e4f89a2c115a56a7b8eaffa5f0deb4470c2432ea Mon Sep 17 00:00:00 2001 From: Michael Monteleone Date: Sat, 5 Sep 2009 22:16:23 -0500 Subject: [PATCH] initial commit --- .gitignore | 5 + README.markdown | 477 ++++++++++++++ Rakefile | 105 +++ doc/GPL-LICENSE.txt | 278 ++++++++ doc/MIT-LICENSE.txt | 20 + doc/example/example.specs.html | 19 + doc/example/example.specs.js | 44 ++ jsTestDriver.conf | 7 + lib/jquery/GPL-LICENSE.txt | 278 ++++++++ lib/jquery/MIT-LICENSE.txt | 20 + lib/jquery/jquery-1.3.2.min.js | 19 + lib/js-test-driver/qunit/History.txt | 10 + lib/js-test-driver/qunit/QUnitAdapter.js | 77 +++ lib/js-test-driver/qunit/README | 74 +++ lib/js-test-driver/qunit/equiv.js | 185 ++++++ lib/qunit/testrunner.js | 803 +++++++++++++++++++++++ lib/qunit/testsuite.css | 120 ++++ spec/pavlov.specs.html | 19 + spec/pavlov.specs.js | 670 +++++++++++++++++++ src/header.js | 10 + src/pavlov.js | 463 +++++++++++++ 21 files changed, 3703 insertions(+) create mode 100644 .gitignore create mode 100755 README.markdown create mode 100755 Rakefile create mode 100644 doc/GPL-LICENSE.txt create mode 100644 doc/MIT-LICENSE.txt create mode 100755 doc/example/example.specs.html create mode 100755 doc/example/example.specs.js create mode 100755 jsTestDriver.conf create mode 100644 lib/jquery/GPL-LICENSE.txt create mode 100644 lib/jquery/MIT-LICENSE.txt create mode 100755 lib/jquery/jquery-1.3.2.min.js create mode 100644 lib/js-test-driver/qunit/History.txt create mode 100644 lib/js-test-driver/qunit/QUnitAdapter.js create mode 100644 lib/js-test-driver/qunit/README create mode 100644 lib/js-test-driver/qunit/equiv.js create mode 100755 lib/qunit/testrunner.js create mode 100755 lib/qunit/testsuite.css create mode 100755 spec/pavlov.specs.html create mode 100755 spec/pavlov.specs.js create mode 100755 src/header.js create mode 100755 src/pavlov.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a96d983 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +*.jar +dist + + diff --git a/README.markdown b/README.markdown new file mode 100755 index 0000000..d7380d2 --- /dev/null +++ b/README.markdown @@ -0,0 +1,477 @@ +Pavlov +====== +Behavioral API over [QUnit][1] +http://github.com/mmonteleone/pavlov + + +What's all this then? +--------------------- + +Pavlov extends JavaScript testing framework [QUnit][1] with a rich, higher-level, Behavioral API with the following: + +### Features: + +* Nested examples (describes) +* Cascading befores and afters (setups and teardowns) +* Generative row tests +* Fluent, extendable, assertions +* Spec stubbing +* Simplified async support +* Non-DOM-polluting + +### Example! + +**Given the following (nested) specification...** (With a nod to [RSpec][9]) + + describe("Bowling", function(){ + // variables scoped only to this and nested examples + var bowling; + + + // befores and afters: + + before(function(){ + // this setup occurs before all specs both + // in this example, and any nested examples + bowling = new Bowling(); + }); + + + // specs: + + it("should score 0 for gutter game", function(){ + for(var i=0;i<20;i++) { + bowling.hit(0); + } + + assert(bowling.score).equals(0); + }); + + it("should only allow 10 frames", function(){ + // add 10 frames + for(var i=0;i<10;i++) { + bowling.moveNextFrame(); + } + + // try to add an 11th + // expect an exception + assert(function(){ + bowling.moveNextFrame(); + }).throwsException(); + }); + + + // stubs specs which yield "Not Implemented" failures: + + it("should allow 2 rolls on frame 1-9"); + it("should allow 3 rolls on the last frame"); + + + // generative row tests: + + given([5, 4], [8, 2], [9, 1]). + it("should award a spare if all knocked down on 2nd roll", function(roll1, roll2) { + // this spec is called 3 times, with each of the 3 sets of given()'s + // parameters applied to it as arguments + + if(roll1 + roll2 == 10) { + bowling.display('Spare!'); + } + + assert(bowling.displayMessage).equals('Spare!'); + }); + + + // nested example: + + describe("Duck Pin Variation", function(){ + + before(function(){ + // setup method which occurs before all of this example's + // specs, but after the parent example's before() + bowling.mode = BowlingMode.DuckPin; + }) + + it("should allow 3 balls per frame"); + it("should award no bonus if knocked down in 3rd frame"); + + }); + + }); + +**...Pavlov compiles the examples down into flattened vanilla QUnit `module` and `test` statements which are then executed** + + Bowling: should score 0 for gutter game + Bowling: should only allow 10 frames + Bowling: should allow 2 rolls on frame 1-9 + Bowling: should allow 3 rolls on the last frame + Bowling: given 5,4, should award a spare if all knocked down on 2nd roll + Bowling: given 8,2, should award a spare if all knocked down on 2nd roll + Bowling: given 9,1, should award a spare if all knocked down on 2nd roll + Bowling, Duck Pin Variation: should allow 3 balls per frame + Bowling, Duck Pin Variation: should award no bonus if knocked down in 3rd frame + +Notice how the nested example became a composite module, and how the given() call generated three tests, one for each argument. + + +Reasonable Questions Reasonable People Should Ask +------------------------------------------------- + +**Really? Another JavaScript testing framework? Really?** + +No, not really. Pavlov is just a library providing a higher-level way of interacting with an already established framework, [QUnit][1]. In fact, Pavlov examples can live alongside standard QUnit tests even within the same script. + +**So it's just an aliased syntax for the QUnit?** + +No. Pavlov provides a different mode of testing with higher level constructs for operating in that mode. Just like other Behavior Driven Development (BDD) testing frameworks, this shifts the focus of unit testing from QA to Design. Here is the point in the worn-out debate where many reasonable arguments can be made about how that's what TDD was always about in the first place. I'd probably agree. + +At any rate, being able to define nested, private, example scopes with cascading befores/afters and data-generated row tests can be really useful, strict BDD or otherwise. It's a natural, hierarchical, way of composing and testing functionality. + +**So why would I want this?** + +You want a BDD framework that can boast wide stability and support out of the gate by offloading the work to QUnit. You like the idea of your Pavlov specs being able to "just work" against QUnit-supporting [JsTestDriver][2] and [TestSwarm][3]. You already have an investment in QUnit, but are envious of other frameworks' richer APIs. You want specific testing features not necessarily available in other BDD frameworks like async support, generative data row-tests, spec stubbing, nested examples with cascading setups and teardowns, and more. + +**And why would I not want this?** + +You might already have a large investment in some other test framework, and simply no need for another. You might not like its use of jQuery. You might not care for the BDD approach. + +**Looks like [Screw.Unit][6]. Why not just use Screw.Unit or fork it?** + +Yeah, it looks *really* similar. And Screw.Unit might well be perfect for you and your project. However, Pavlov is a response to a need for certain features not provided by other BDD frameworks, including among others, compatibility with QUnit. + +By simply layering on top of QUnit, Pavlov gains all of QUnit's simplicity, stability, and maturity/integration with tools, while also being able to quickly build up a BDD API. + +Surprisingly, Pavlov's API similarities with Screw.Unit are purely coincidental and are due to its imitation of RSpec rather than other JS librarires. I will admit to shamelessly borrowing one trick from Screw.Unit: [Yehuda Katz][5]'s clever metaprogramming technique for injecting extra scope (like api methods) into a function instead of extending the global scope. This *can* be disabled for scenarios when it destroys your debugging. + + +Documentation: +-------------- + +### Usage Requirements + +* [jQuery][0] 1.3.2 or later +* [QUnit][1] (testrunner.js, testsuite.css, testsuite.html) + +### Downloading/Installing/Setup + +If you're just using Pavlov and not developing it or running its unit tests, just download the [latest packaged release from Github][0]. + +Contained in the package is a barebones **example spec setup**, which is just a standard QUnit test host document including the the normal QUnit dependencies, but also pavlov.js and a spec suite script. + +### Running tests + +Tests can be run by simply opening the test host document in a browser or by taking advantage of any other tools which can run QUnit tests, including [JsTestDriver][2], [TestSwarm][3], etc. For a demonstration of how this can be accomplished, Pavlov's source uses Pavlov, QUnit, and JsTestDriver to test itself. + +### Creating Examples + +#### QUnit.specify() + +Function which declares a new QUnit.specify context. It's the required top-level method which provides an overall scope for creation, compilation, and running of Pavlov specs. + +*Parameters* + +* name (String) - name of what's being specified +* fn (Function) - Function containing exmaples and specs + +*Example* + + QUnit.specify("The Rules of Bowling", function(){ + // descriptions contained within specification context + describe(.... + describe(.... + }); + +#### describe() + +Initiates a new Example. A description translates to a QUnit module. + +*Parameters* + +* description (String) - Name of what's being "described" +* fn (Function) - containing description (before, after, specs, nested examples) + +*Example* + + //... within a QUnit.specify scope + describe("Bowling", function(){ + // specs contained within this description + it(... + it(... + }); + +#### before() + +Sets a function to occur before all contained specs and nested examples' specs. The function(s) is/are executed within a QUnit module's setup option. + +*Parameters* + +* fn (Function) - function to occur + +*Example* + + describe("Bowling", function(){ + var bowling; + + before(function(){ + bowling = new Bowling(); + }); + ... + +#### after() + +Sets a function to occur after all contained specs and nested examples' specs. The function(s) is/are executed within a QUnit module's teardown option. + +*Parameters* + +* fn (Function) - function to occur + +*Example* + + describe("Bowling", function(){ + var bowling; + + before(function(){ + bowling = new Bowling(); + }); + ... + +#### Nested Examples + +Examples can be nested as deep as necessary. + +* A nested example has access to the parent's scope. +* A a parent example's before and after methods still occur before and after all nested example's specs, in the following pattern: + * Nested befores are executed before specs in order from outermost-to-innermost + * Nested afters are executed after specs in order from innermost-to-outermost + +*Example* + + //... within a QUnit.specify scope + describe("Bowling", function(){ + // specs contained within this description + before(... + after(... + it(... + it(... + + // nested example + describe("Duck Pin Variation", function(){ + before(... + after(... + it(... + it(... + }); + }); + +### Defining Specs + +#### it() + +Creates a spec (test) to occur within an example (decribe) +When not passed fn, creates a spec-stubbing fn which asserts fail "Not Implemented" + +*Parameters* +* specification (String) - Description of what "it" "should do" +* fn (Function) - Optional function containing a test to assert that it does indeed do it (optional) + +*Example* + + //.. within a describe + it("should score 0 for gutter game", function(){ + // code and assertion to test the specification + for(var i=0;i<20;i++) { + bowling.hit(0); + } + assert(bowling.score).equals(0); + }); + + // stubs specs which yield "Not Implemented" failures: + it("should allow 2 rolls on frame 1-9"); + it("should allow 3 rolls on the last frame"); + +#### given() + +Generates a row spec for each argument passed, applying each argument to a new call against the spec. +Returns an object with an it() function for declaring a spec to be called for each of the given's arguments. + +*Parameters* + +* arguments (Array) - either a list of values or list of arrays of values (when the spec's fn accepts multiple arguments) + +*Example* + + given([2,2,4], [5,2,7], [6,-4,2]). + it("can generate row data tests", function(a, b, c) { + assert(c).equals(a + b); + }); + + given(1, 3, 4). + it("doesn't require arrays", function(x) { + assert(x > 0).isTrue(); + }); + +### Using Assertions + +Pavlov's assertions are fluent extensions to QUnit's assertion primitives. Pavlov's assertions can be extended with custom domain-specific fluent assertions for more readable tests. + +Syntax usually follows the pattern: + + assert(actual).comparisonMethod(expected, optionalMessage); + +A few Examples: + + assert(foo).equals("bar"); + assert(foo).isNotNull(); + assert(bar).isUndefined("this should be undefined"); // message here was optional + assert(function(){ + // asserting that contained code should properly throw an exception + }).throwsException(); + assert(baz).isFalse(); + assert(foo).isSameAs(bar); // uses QUnit's equiv to deep-compare objects/arrays + assert.fail(); // explicitly fail a test + +#### Built-in Assertions + +Most are self-explanatory. Message parameter is always optional. + +* assert(actual).equals(expected, message); +* assert(actual).isEqualTo(expected, message); +* assert(actual).isNotEqualTo(expected, message); +* assert(actual).isSameAs(expected, message); // deep value comparison using QUnit's equiv() +* assert(actual).isNotSameAs: function(actual, expected, message); +* assert(actual).isTrue(message); +* assert(actual).isFalse(message); +* assert(actual).isNull(message); +* assert(actual).isNotNull(message); +* assert(actual).isDefined(message); +* assert(actual).isUndefined(message); +* assert.pass(message); // shortcut for assert().pass(message); +* assert.fail(message); // shortcut for assert().fail(message); +* assert(fn).throwsException(message); // asserts that executing passed fn throws an exception + +#### Adding custom Assertions + +`QUnit.specify.extendAssertions()` + +For more readable tests, domain-specific assertions can be added. + +*Parameters* + +* asserts (Object) - object containing implementations for assertions. Each gets wrapped into an extension available when calling assert(). + +*Example* + + // first provide assertion implementations + // each accepts an actual, optional expected, and message + // the implementation names become the names of the assertions + + QUnit.specify.extendAssertions({ + isGreaterThan: function(actual, expected, message) { + ok(actual > expected, message); + }, + isLessThan: function(actual, expected, message) { + ok(actual < expected, message); + }, + containsExactlyTwoElements(actual, message) { + // note this does not have an expected parameter + ok(actual.length == 2); + } + }); + + // then make use of the generated assertions + + assert(4).isGreaterThan(2); + assert(5).isLessThan(10, "some message"); + assert(["a", b]).containsExactlyTwoElements(); + + +### Extra + +#### wait() + +One of QUnit's strengths is its support for testing asynchronous code. To slightly help with this, the `wait` method wraps up the pattern of pausing the test runner for a duration, running code, and then re-starting. Not unlike a setTimeout, except it backs against QUnit's `stop` and `start`. This is really only meant for scenarios where injecting/overriding the clock isn't practical. + +*Parameters* + +* ms (Number) - number of milliseconds to pause the test runner +* fn (Function) - function to run after waiting, but before restarting test runner + +*Example* + + describe("a wait()", function(){ + it("should pause the test runner", function(){ + var timeoutCompleted = false; + + setTimeout(function(){ + timeoutCompleted = true; + }, 40); + + // wait long enough for timeout to have completed + wait(50, function(){ + assert(timeoutCompleted).isTrue(); + }); + }); + }); + +#### Toggling global scope + +Pavlov shamelessly borrows Screw.Unit's clever metaprogramming technique to keep from having to inject its API into the global scope. But if you're debugging, the fun can quickly come to an end as your tests' source have been modified and re-evaled. Thankfully, Pavlov allows the API to be injected globally as well. + +Just set `QUnit.specify.globalApi = true;` before a `QUnit.specify()` block. It defaults to `false`. + +*Property* + +* QUnit.specify.globalApi + * false (default): does not globally inject API, uses metaprogramming + * true: globally injects API, no metaprogramming + +*Example* + + QUnit.specify.globalApi = true; // injects API into global scope + // before a standard specify + QUnit.specify(... + +Contributing +------------ + +Development Requirements (for building and test running): + +* Ruby + Rake and PackR gems: for building and minifying +* Java: if you want to test using the included JsTestDriver setup + +Clone the source at `http://github.com/mmonteleone/pavlov.git` and have at it. + +The following build tasks are available: + + rake build # builds package and minifies + rake test # runs Pavlov specs against QUnit testrunner in default browser + rake server # downloads, starts [JsTestDriver][2] server, binds common browsers + rake testdrive # runs Pavlov specs against running JsTestDriver server + +Credit +------ + +Credit of course goes to: + +[QUnit][1]: Copyright (c) 2008 John Resig, Jörn Zaefferer, used under the terms of the MIT LICENSE +[RSpec][9]: David Chelimsky and RSpec Development Team +[Screw.Unit][6]: Copyright (c) 2008 Nick Kallen and especially Yehuda Katz metaprogramming contributions to it + +License +------- + +Copyright (c) 2009 Michael Monteleone +Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses. + +[0]: http://jquery.com "jQuery" +[1]: http://docs.jquery.com/QUnit "QUnit" +[2]: http://code.google.com/p/js-test-driver/ "JsTestDriver" +[3]: http://wiki.github.com/jeresig/testswarm "TestSwarm" +[4]: http://michaelmonteleone.net "Michael Monteleone" +[5]: http://yehudakatz.com/ "Yehuda Katz" +[6]: http://github.com/nathansobo/screw-unit/tree/master "Screw.Unit" +[7]: http://github.com/jcoglan/packr "PackR" +[8]: http://rake.rubyforge.org/ "Rake" +[9]: http://rspec.info/ "RSpec" + + diff --git a/Rakefile b/Rakefile new file mode 100755 index 0000000..96435c3 --- /dev/null +++ b/Rakefile @@ -0,0 +1,105 @@ +require 'rubygems' +require 'net/http' +require 'rake/clean' +require 'packr' +require 'fileutils' +include FileUtils + +task :default => :test + +# list of browsers to auto-bind to JsTestDrive Server +# non-existent browsers will be ignored +BROWSERS = [ + '/Applications/Safari.app/Contents/MacOS/Safari', + '/Applications/Firefox.app/Contents/MacOS/firefox', + '/Applications/Chromium.app/Contents/MacOS/Chromium', + '/Applications/Opera.app/Contents/MacOS/Opera', + 'C:/Program Files/Mozilla Firefox/firefox.exe', + 'C:/Program Files/Internet Explorer/iexplore.exe', + 'C:/Program Files/Safari/Safari.exe', + 'C:/Program Files/Opera/opera.exe' ] + + +desc "Builds a release" +task :build => [:clean] do + # build dist and lib directories + mkdir 'dist' + mkdir 'dist/lib' + mkdir 'dist/example' + + # copy src + cp 'src/pavlov.js', 'dist/pavlov.js' + + # copy documentation + cp 'doc/GPL-LICENSE.txt', 'dist/GPL-LICENSE.txt' + cp 'doc/MIT-LICENSE.txt', 'dist/MIT-LICENSE.txt' + cp 'README.markdown', 'dist/README.markdown' + + # copy lib + cp 'lib/jquery/jquery-1.3.2.min.js', 'dist/lib/jquery-1.3.2.min.js' + cp 'lib/qunit/testrunner.js', 'dist/lib/testrunner.js' + cp 'lib/qunit/testsuite.css', 'dist/lib/testsuite.css' + cp 'lib/jquery/GPL-LICENSE.txt', 'dist/lib/GPL-LICENSE.txt' + cp 'lib/jquery/MIT-LICENSE.txt', 'dist/lib/MIT-LICENSE.txt' + + # copy example + cp 'doc/example/example.specs.html', 'dist/example/example.specs.html' + cp 'doc/example/example.specs.js', 'dist/example/example.specs.js' + + + # minify src + source = File.read('dist/pavlov.js') + minified = Packr.pack(source, :shrink_vars => true, :base62 => false) + + # inject header + File.open('dist/pavlov.min.js', 'w') do |combined| + combined.puts(IO.read('src/header.js')) + combined.write(minified) + end +end + + +desc "Run the tests in default browser" +task :test => [:build] do + begin + # mac + sh("open spec/pavlov.specs.html") + rescue + # windows + sh("start spec/pavlov.specs.html") + end +end + + +desc "Run the tests against JsTestDriver" +task :testdrive => [:build] do + sh("java -jar lib/js-test-driver/JsTestDriver.jar --tests all --captureConsole --reset") +end + + +desc "Start the JsTestDriver server" +task :server => [:install_server] do + browsers = BROWSERS.find_all{|b| File.exists? b}.join(',') + sh("java -jar lib/js-test-driver/JsTestDriver.jar --port 9876 --browser \"#{browsers}\"") +end + + +desc "Download Google JsTestDriver" +task :install_server do + if !File.exist?('lib/js-test-driver/JsTestDriver.jar') then + puts 'Downloading JsTestDriver from Google (http://js-test-driver.googlecode.com/files/JsTestDriver-1.0b.jar) ...' + Net::HTTP.start("js-test-driver.googlecode.com") do |http| + resp = http.get("/files/JsTestDriver-1.0b.jar") + open("lib/js-test-driver/JsTestDriver.jar", "wb") do |file| + file.write(resp.body) + end + end + puts 'JsTestDriver Downloaded' + end +end + + +# clean deletes built copies +CLEAN.include('dist/') +# clobber cleans and uninstalls JsTestDriver server +CLOBBER.include('lib/js-test-driver/*.jar') diff --git a/doc/GPL-LICENSE.txt b/doc/GPL-LICENSE.txt new file mode 100644 index 0000000..11dddd0 --- /dev/null +++ b/doc/GPL-LICENSE.txt @@ -0,0 +1,278 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. diff --git a/doc/MIT-LICENSE.txt b/doc/MIT-LICENSE.txt new file mode 100644 index 0000000..2740856 --- /dev/null +++ b/doc/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2009 Michael Monteleone, http://michaelmonteleone.net + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/doc/example/example.specs.html b/doc/example/example.specs.html new file mode 100755 index 0000000..5737d1e --- /dev/null +++ b/doc/example/example.specs.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + +

+ +

+
    +
    + + \ No newline at end of file diff --git a/doc/example/example.specs.js b/doc/example/example.specs.js new file mode 100755 index 0000000..243ea76 --- /dev/null +++ b/doc/example/example.specs.js @@ -0,0 +1,44 @@ +QUnit.specify("Pavlov Example", function(){ + + describe("A feature that is being described", function(){ + + var foo; + + before(function(){ + foo = "bar"; + }); + + after(function(){ + foo = "baz"; + }); + + it("can be specified like so", function(){ + assert(foo).equals('bar'); + }); + + given([2,2,4], [5,2,7], [6,-4,2]). + it("can generate row data tests", function(a, b, c) { + assert(c).equals(a + b); + }); + + it("can contain as many specs as necessary", function(){ + assert(function(){ + throw "Exception!"; + }).throwsException(); + }); + + describe("can also have nested examples", function(){ + + before(function(){ + foo = foo + "bar"; + }); + + it("with their own specs", function(){ + assert(foo).equals("barbar"); + }); + + }); + + }); + +}); diff --git a/jsTestDriver.conf b/jsTestDriver.conf new file mode 100755 index 0000000..89bafec --- /dev/null +++ b/jsTestDriver.conf @@ -0,0 +1,7 @@ +server: http://localhost:9876 + +load: + - lib/js-test-driver/qunit/equiv.js + - lib/js-test-driver/qunit/QUnitAdapter.js + - dist/*.js + - spec/*.js diff --git a/lib/jquery/GPL-LICENSE.txt b/lib/jquery/GPL-LICENSE.txt new file mode 100644 index 0000000..11dddd0 --- /dev/null +++ b/lib/jquery/GPL-LICENSE.txt @@ -0,0 +1,278 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. diff --git a/lib/jquery/MIT-LICENSE.txt b/lib/jquery/MIT-LICENSE.txt new file mode 100644 index 0000000..8ec2b0b --- /dev/null +++ b/lib/jquery/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2009 John Resig, http://jquery.com/ + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/jquery/jquery-1.3.2.min.js b/lib/jquery/jquery-1.3.2.min.js new file mode 100755 index 0000000..b1ae21d --- /dev/null +++ b/lib/jquery/jquery-1.3.2.min.js @@ -0,0 +1,19 @@ +/* + * jQuery JavaScript Library v1.3.2 + * http://jquery.com/ + * + * Copyright (c) 2009 John Resig + * Dual licensed under the MIT and GPL licenses. + * http://docs.jquery.com/License + * + * Date: 2009-02-19 17:34:21 -0500 (Thu, 19 Feb 2009) + * Revision: 6246 + */ +(function(){var l=this,g,y=l.jQuery,p=l.$,o=l.jQuery=l.$=function(E,F){return new o.fn.init(E,F)},D=/^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,f=/^.[^:#\[\.,]*$/;o.fn=o.prototype={init:function(E,H){E=E||document;if(E.nodeType){this[0]=E;this.length=1;this.context=E;return this}if(typeof E==="string"){var G=D.exec(E);if(G&&(G[1]||!H)){if(G[1]){E=o.clean([G[1]],H)}else{var I=document.getElementById(G[3]);if(I&&I.id!=G[3]){return o().find(E)}var F=o(I||[]);F.context=document;F.selector=E;return F}}else{return o(H).find(E)}}else{if(o.isFunction(E)){return o(document).ready(E)}}if(E.selector&&E.context){this.selector=E.selector;this.context=E.context}return this.setArray(o.isArray(E)?E:o.makeArray(E))},selector:"",jquery:"1.3.2",size:function(){return this.length},get:function(E){return E===g?Array.prototype.slice.call(this):this[E]},pushStack:function(F,H,E){var G=o(F);G.prevObject=this;G.context=this.context;if(H==="find"){G.selector=this.selector+(this.selector?" ":"")+E}else{if(H){G.selector=this.selector+"."+H+"("+E+")"}}return G},setArray:function(E){this.length=0;Array.prototype.push.apply(this,E);return this},each:function(F,E){return o.each(this,F,E)},index:function(E){return o.inArray(E&&E.jquery?E[0]:E,this)},attr:function(F,H,G){var E=F;if(typeof F==="string"){if(H===g){return this[0]&&o[G||"attr"](this[0],F)}else{E={};E[F]=H}}return this.each(function(I){for(F in E){o.attr(G?this.style:this,F,o.prop(this,E[F],G,I,F))}})},css:function(E,F){if((E=="width"||E=="height")&&parseFloat(F)<0){F=g}return this.attr(E,F,"curCSS")},text:function(F){if(typeof F!=="object"&&F!=null){return this.empty().append((this[0]&&this[0].ownerDocument||document).createTextNode(F))}var E="";o.each(F||this,function(){o.each(this.childNodes,function(){if(this.nodeType!=8){E+=this.nodeType!=1?this.nodeValue:o.fn.text([this])}})});return E},wrapAll:function(E){if(this[0]){var F=o(E,this[0].ownerDocument).clone();if(this[0].parentNode){F.insertBefore(this[0])}F.map(function(){var G=this;while(G.firstChild){G=G.firstChild}return G}).append(this)}return this},wrapInner:function(E){return this.each(function(){o(this).contents().wrapAll(E)})},wrap:function(E){return this.each(function(){o(this).wrapAll(E)})},append:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.appendChild(E)}})},prepend:function(){return this.domManip(arguments,true,function(E){if(this.nodeType==1){this.insertBefore(E,this.firstChild)}})},before:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this)})},after:function(){return this.domManip(arguments,false,function(E){this.parentNode.insertBefore(E,this.nextSibling)})},end:function(){return this.prevObject||o([])},push:[].push,sort:[].sort,splice:[].splice,find:function(E){if(this.length===1){var F=this.pushStack([],"find",E);F.length=0;o.find(E,this[0],F);return F}else{return this.pushStack(o.unique(o.map(this,function(G){return o.find(E,G)})),"find",E)}},clone:function(G){var E=this.map(function(){if(!o.support.noCloneEvent&&!o.isXMLDoc(this)){var I=this.outerHTML;if(!I){var J=this.ownerDocument.createElement("div");J.appendChild(this.cloneNode(true));I=J.innerHTML}return o.clean([I.replace(/ jQuery\d+="(?:\d+|null)"/g,"").replace(/^\s*/,"")])[0]}else{return this.cloneNode(true)}});if(G===true){var H=this.find("*").andSelf(),F=0;E.find("*").andSelf().each(function(){if(this.nodeName!==H[F].nodeName){return}var I=o.data(H[F],"events");for(var K in I){for(var J in I[K]){o.event.add(this,K,I[K][J],I[K][J].data)}}F++})}return E},filter:function(E){return this.pushStack(o.isFunction(E)&&o.grep(this,function(G,F){return E.call(G,F)})||o.multiFilter(E,o.grep(this,function(F){return F.nodeType===1})),"filter",E)},closest:function(E){var G=o.expr.match.POS.test(E)?o(E):null,F=0;return this.map(function(){var H=this;while(H&&H.ownerDocument){if(G?G.index(H)>-1:o(H).is(E)){o.data(H,"closest",F);return H}H=H.parentNode;F++}})},not:function(E){if(typeof E==="string"){if(f.test(E)){return this.pushStack(o.multiFilter(E,this,true),"not",E)}else{E=o.multiFilter(E,this)}}var F=E.length&&E[E.length-1]!==g&&!E.nodeType;return this.filter(function(){return F?o.inArray(this,E)<0:this!=E})},add:function(E){return this.pushStack(o.unique(o.merge(this.get(),typeof E==="string"?o(E):o.makeArray(E))))},is:function(E){return !!E&&o.multiFilter(E,this).length>0},hasClass:function(E){return !!E&&this.is("."+E)},val:function(K){if(K===g){var E=this[0];if(E){if(o.nodeName(E,"option")){return(E.attributes.value||{}).specified?E.value:E.text}if(o.nodeName(E,"select")){var I=E.selectedIndex,L=[],M=E.options,H=E.type=="select-one";if(I<0){return null}for(var F=H?I:0,J=H?I+1:M.length;F=0||o.inArray(this.name,K)>=0)}else{if(o.nodeName(this,"select")){var N=o.makeArray(K);o("option",this).each(function(){this.selected=(o.inArray(this.value,N)>=0||o.inArray(this.text,N)>=0)});if(!N.length){this.selectedIndex=-1}}else{this.value=K}}})},html:function(E){return E===g?(this[0]?this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g,""):null):this.empty().append(E)},replaceWith:function(E){return this.after(E).remove()},eq:function(E){return this.slice(E,+E+1)},slice:function(){return this.pushStack(Array.prototype.slice.apply(this,arguments),"slice",Array.prototype.slice.call(arguments).join(","))},map:function(E){return this.pushStack(o.map(this,function(G,F){return E.call(G,F,G)}))},andSelf:function(){return this.add(this.prevObject)},domManip:function(J,M,L){if(this[0]){var I=(this[0].ownerDocument||this[0]).createDocumentFragment(),F=o.clean(J,(this[0].ownerDocument||this[0]),I),H=I.firstChild;if(H){for(var G=0,E=this.length;G1||G>0?I.cloneNode(true):I)}}if(F){o.each(F,z)}}return this;function K(N,O){return M&&o.nodeName(N,"table")&&o.nodeName(O,"tr")?(N.getElementsByTagName("tbody")[0]||N.appendChild(N.ownerDocument.createElement("tbody"))):N}}};o.fn.init.prototype=o.fn;function z(E,F){if(F.src){o.ajax({url:F.src,async:false,dataType:"script"})}else{o.globalEval(F.text||F.textContent||F.innerHTML||"")}if(F.parentNode){F.parentNode.removeChild(F)}}function e(){return +new Date}o.extend=o.fn.extend=function(){var J=arguments[0]||{},H=1,I=arguments.length,E=false,G;if(typeof J==="boolean"){E=J;J=arguments[1]||{};H=2}if(typeof J!=="object"&&!o.isFunction(J)){J={}}if(I==H){J=this;--H}for(;H-1}},swap:function(H,G,I){var E={};for(var F in G){E[F]=H.style[F];H.style[F]=G[F]}I.call(H);for(var F in G){H.style[F]=E[F]}},css:function(H,F,J,E){if(F=="width"||F=="height"){var L,G={position:"absolute",visibility:"hidden",display:"block"},K=F=="width"?["Left","Right"]:["Top","Bottom"];function I(){L=F=="width"?H.offsetWidth:H.offsetHeight;if(E==="border"){return}o.each(K,function(){if(!E){L-=parseFloat(o.curCSS(H,"padding"+this,true))||0}if(E==="margin"){L+=parseFloat(o.curCSS(H,"margin"+this,true))||0}else{L-=parseFloat(o.curCSS(H,"border"+this+"Width",true))||0}})}if(H.offsetWidth!==0){I()}else{o.swap(H,G,I)}return Math.max(0,Math.round(L))}return o.curCSS(H,F,J)},curCSS:function(I,F,G){var L,E=I.style;if(F=="opacity"&&!o.support.opacity){L=o.attr(E,"opacity");return L==""?"1":L}if(F.match(/float/i)){F=w}if(!G&&E&&E[F]){L=E[F]}else{if(q.getComputedStyle){if(F.match(/float/i)){F="float"}F=F.replace(/([A-Z])/g,"-$1").toLowerCase();var M=q.getComputedStyle(I,null);if(M){L=M.getPropertyValue(F)}if(F=="opacity"&&L==""){L="1"}}else{if(I.currentStyle){var J=F.replace(/\-(\w)/g,function(N,O){return O.toUpperCase()});L=I.currentStyle[F]||I.currentStyle[J];if(!/^\d+(px)?$/i.test(L)&&/^\d/.test(L)){var H=E.left,K=I.runtimeStyle.left;I.runtimeStyle.left=I.currentStyle.left;E.left=L||0;L=E.pixelLeft+"px";E.left=H;I.runtimeStyle.left=K}}}}return L},clean:function(F,K,I){K=K||document;if(typeof K.createElement==="undefined"){K=K.ownerDocument||K[0]&&K[0].ownerDocument||document}if(!I&&F.length===1&&typeof F[0]==="string"){var H=/^<(\w+)\s*\/?>$/.exec(F[0]);if(H){return[K.createElement(H[1])]}}var G=[],E=[],L=K.createElement("div");o.each(F,function(P,S){if(typeof S==="number"){S+=""}if(!S){return}if(typeof S==="string"){S=S.replace(/(<(\w+)[^>]*?)\/>/g,function(U,V,T){return T.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i)?U:V+">"});var O=S.replace(/^\s+/,"").substring(0,10).toLowerCase();var Q=!O.indexOf("",""]||!O.indexOf("",""]||O.match(/^<(thead|tbody|tfoot|colg|cap)/)&&[1,"","
    "]||!O.indexOf("",""]||(!O.indexOf("",""]||!O.indexOf("",""]||!o.support.htmlSerialize&&[1,"div
    ","
    "]||[0,"",""];L.innerHTML=Q[1]+S+Q[2];while(Q[0]--){L=L.lastChild}if(!o.support.tbody){var R=/"&&!R?L.childNodes:[];for(var M=N.length-1;M>=0;--M){if(o.nodeName(N[M],"tbody")&&!N[M].childNodes.length){N[M].parentNode.removeChild(N[M])}}}if(!o.support.leadingWhitespace&&/^\s/.test(S)){L.insertBefore(K.createTextNode(S.match(/^\s*/)[0]),L.firstChild)}S=o.makeArray(L.childNodes)}if(S.nodeType){G.push(S)}else{G=o.merge(G,S)}});if(I){for(var J=0;G[J];J++){if(o.nodeName(G[J],"script")&&(!G[J].type||G[J].type.toLowerCase()==="text/javascript")){E.push(G[J].parentNode?G[J].parentNode.removeChild(G[J]):G[J])}else{if(G[J].nodeType===1){G.splice.apply(G,[J+1,0].concat(o.makeArray(G[J].getElementsByTagName("script"))))}I.appendChild(G[J])}}return E}return G},attr:function(J,G,K){if(!J||J.nodeType==3||J.nodeType==8){return g}var H=!o.isXMLDoc(J),L=K!==g;G=H&&o.props[G]||G;if(J.tagName){var F=/href|src|style/.test(G);if(G=="selected"&&J.parentNode){J.parentNode.selectedIndex}if(G in J&&H&&!F){if(L){if(G=="type"&&o.nodeName(J,"input")&&J.parentNode){throw"type property can't be changed"}J[G]=K}if(o.nodeName(J,"form")&&J.getAttributeNode(G)){return J.getAttributeNode(G).nodeValue}if(G=="tabIndex"){var I=J.getAttributeNode("tabIndex");return I&&I.specified?I.value:J.nodeName.match(/(button|input|object|select|textarea)/i)?0:J.nodeName.match(/^(a|area)$/i)&&J.href?0:g}return J[G]}if(!o.support.style&&H&&G=="style"){return o.attr(J.style,"cssText",K)}if(L){J.setAttribute(G,""+K)}var E=!o.support.hrefNormalized&&H&&F?J.getAttribute(G,2):J.getAttribute(G);return E===null?g:E}if(!o.support.opacity&&G=="opacity"){if(L){J.zoom=1;J.filter=(J.filter||"").replace(/alpha\([^)]*\)/,"")+(parseInt(K)+""=="NaN"?"":"alpha(opacity="+K*100+")")}return J.filter&&J.filter.indexOf("opacity=")>=0?(parseFloat(J.filter.match(/opacity=([^)]*)/)[1])/100)+"":""}G=G.replace(/-([a-z])/ig,function(M,N){return N.toUpperCase()});if(L){J[G]=K}return J[G]},trim:function(E){return(E||"").replace(/^\s+|\s+$/g,"")},makeArray:function(G){var E=[];if(G!=null){var F=G.length;if(F==null||typeof G==="string"||o.isFunction(G)||G.setInterval){E[0]=G}else{while(F){E[--F]=G[F]}}}return E},inArray:function(G,H){for(var E=0,F=H.length;E0?this.clone(true):this).get();o.fn[F].apply(o(L[K]),I);J=J.concat(I)}return this.pushStack(J,E,G)}});o.each({removeAttr:function(E){o.attr(this,E,"");if(this.nodeType==1){this.removeAttribute(E)}},addClass:function(E){o.className.add(this,E)},removeClass:function(E){o.className.remove(this,E)},toggleClass:function(F,E){if(typeof E!=="boolean"){E=!o.className.has(this,F)}o.className[E?"add":"remove"](this,F)},remove:function(E){if(!E||o.filter(E,[this]).length){o("*",this).add([this]).each(function(){o.event.remove(this);o.removeData(this)});if(this.parentNode){this.parentNode.removeChild(this)}}},empty:function(){o(this).children().remove();while(this.firstChild){this.removeChild(this.firstChild)}}},function(E,F){o.fn[E]=function(){return this.each(F,arguments)}});function j(E,F){return E[0]&&parseInt(o.curCSS(E[0],F,true),10)||0}var h="jQuery"+e(),v=0,A={};o.extend({cache:{},data:function(F,E,G){F=F==l?A:F;var H=F[h];if(!H){H=F[h]=++v}if(E&&!o.cache[H]){o.cache[H]={}}if(G!==g){o.cache[H][E]=G}return E?o.cache[H][E]:H},removeData:function(F,E){F=F==l?A:F;var H=F[h];if(E){if(o.cache[H]){delete o.cache[H][E];E="";for(E in o.cache[H]){break}if(!E){o.removeData(F)}}}else{try{delete F[h]}catch(G){if(F.removeAttribute){F.removeAttribute(h)}}delete o.cache[H]}},queue:function(F,E,H){if(F){E=(E||"fx")+"queue";var G=o.data(F,E);if(!G||o.isArray(H)){G=o.data(F,E,o.makeArray(H))}else{if(H){G.push(H)}}}return G},dequeue:function(H,G){var E=o.queue(H,G),F=E.shift();if(!G||G==="fx"){F=E[0]}if(F!==g){F.call(H)}}});o.fn.extend({data:function(E,G){var H=E.split(".");H[1]=H[1]?"."+H[1]:"";if(G===g){var F=this.triggerHandler("getData"+H[1]+"!",[H[0]]);if(F===g&&this.length){F=o.data(this[0],E)}return F===g&&H[1]?this.data(H[0]):F}else{return this.trigger("setData"+H[1]+"!",[H[0],G]).each(function(){o.data(this,E,G)})}},removeData:function(E){return this.each(function(){o.removeData(this,E)})},queue:function(E,F){if(typeof E!=="string"){F=E;E="fx"}if(F===g){return o.queue(this[0],E)}return this.each(function(){var G=o.queue(this,E,F);if(E=="fx"&&G.length==1){G[0].call(this)}})},dequeue:function(E){return this.each(function(){o.dequeue(this,E)})}}); +/* + * Sizzle CSS Selector Engine - v0.9.3 + * Copyright 2009, The Dojo Foundation + * Released under the MIT, BSD, and GPL Licenses. + * More information: http://sizzlejs.com/ + */ +(function(){var R=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^[\]]*\]|['"][^'"]*['"]|[^[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?/g,L=0,H=Object.prototype.toString;var F=function(Y,U,ab,ac){ab=ab||[];U=U||document;if(U.nodeType!==1&&U.nodeType!==9){return[]}if(!Y||typeof Y!=="string"){return ab}var Z=[],W,af,ai,T,ad,V,X=true;R.lastIndex=0;while((W=R.exec(Y))!==null){Z.push(W[1]);if(W[2]){V=RegExp.rightContext;break}}if(Z.length>1&&M.exec(Y)){if(Z.length===2&&I.relative[Z[0]]){af=J(Z[0]+Z[1],U)}else{af=I.relative[Z[0]]?[U]:F(Z.shift(),U);while(Z.length){Y=Z.shift();if(I.relative[Y]){Y+=Z.shift()}af=J(Y,af)}}}else{var ae=ac?{expr:Z.pop(),set:E(ac)}:F.find(Z.pop(),Z.length===1&&U.parentNode?U.parentNode:U,Q(U));af=F.filter(ae.expr,ae.set);if(Z.length>0){ai=E(af)}else{X=false}while(Z.length){var ah=Z.pop(),ag=ah;if(!I.relative[ah]){ah=""}else{ag=Z.pop()}if(ag==null){ag=U}I.relative[ah](ai,ag,Q(U))}}if(!ai){ai=af}if(!ai){throw"Syntax error, unrecognized expression: "+(ah||Y)}if(H.call(ai)==="[object Array]"){if(!X){ab.push.apply(ab,ai)}else{if(U.nodeType===1){for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&(ai[aa]===true||ai[aa].nodeType===1&&K(U,ai[aa]))){ab.push(af[aa])}}}else{for(var aa=0;ai[aa]!=null;aa++){if(ai[aa]&&ai[aa].nodeType===1){ab.push(af[aa])}}}}}else{E(ai,ab)}if(V){F(V,U,ab,ac);if(G){hasDuplicate=false;ab.sort(G);if(hasDuplicate){for(var aa=1;aa":function(Z,U,aa){var X=typeof U==="string";if(X&&!/\W/.test(U)){U=aa?U:U.toUpperCase();for(var V=0,T=Z.length;V=0)){if(!V){T.push(Y)}}else{if(V){U[X]=false}}}}return false},ID:function(T){return T[1].replace(/\\/g,"")},TAG:function(U,T){for(var V=0;T[V]===false;V++){}return T[V]&&Q(T[V])?U[1]:U[1].toUpperCase()},CHILD:function(T){if(T[1]=="nth"){var U=/(-?)(\d*)n((?:\+|-)?\d*)/.exec(T[2]=="even"&&"2n"||T[2]=="odd"&&"2n+1"||!/\D/.test(T[2])&&"0n+"+T[2]||T[2]);T[2]=(U[1]+(U[2]||1))-0;T[3]=U[3]-0}T[0]=L++;return T},ATTR:function(X,U,V,T,Y,Z){var W=X[1].replace(/\\/g,"");if(!Z&&I.attrMap[W]){X[1]=I.attrMap[W]}if(X[2]==="~="){X[4]=" "+X[4]+" "}return X},PSEUDO:function(X,U,V,T,Y){if(X[1]==="not"){if(X[3].match(R).length>1||/^\w/.test(X[3])){X[3]=F(X[3],null,null,U)}else{var W=F.filter(X[3],U,V,true^Y);if(!V){T.push.apply(T,W)}return false}}else{if(I.match.POS.test(X[0])||I.match.CHILD.test(X[0])){return true}}return X},POS:function(T){T.unshift(true);return T}},filters:{enabled:function(T){return T.disabled===false&&T.type!=="hidden"},disabled:function(T){return T.disabled===true},checked:function(T){return T.checked===true},selected:function(T){T.parentNode.selectedIndex;return T.selected===true},parent:function(T){return !!T.firstChild},empty:function(T){return !T.firstChild},has:function(V,U,T){return !!F(T[3],V).length},header:function(T){return/h\d/i.test(T.nodeName)},text:function(T){return"text"===T.type},radio:function(T){return"radio"===T.type},checkbox:function(T){return"checkbox"===T.type},file:function(T){return"file"===T.type},password:function(T){return"password"===T.type},submit:function(T){return"submit"===T.type},image:function(T){return"image"===T.type},reset:function(T){return"reset"===T.type},button:function(T){return"button"===T.type||T.nodeName.toUpperCase()==="BUTTON"},input:function(T){return/input|select|textarea|button/i.test(T.nodeName)}},setFilters:{first:function(U,T){return T===0},last:function(V,U,T,W){return U===W.length-1},even:function(U,T){return T%2===0},odd:function(U,T){return T%2===1},lt:function(V,U,T){return UT[3]-0},nth:function(V,U,T){return T[3]-0==U},eq:function(V,U,T){return T[3]-0==U}},filter:{PSEUDO:function(Z,V,W,aa){var U=V[1],X=I.filters[U];if(X){return X(Z,W,V,aa)}else{if(U==="contains"){return(Z.textContent||Z.innerText||"").indexOf(V[3])>=0}else{if(U==="not"){var Y=V[3];for(var W=0,T=Y.length;W=0)}}},ID:function(U,T){return U.nodeType===1&&U.getAttribute("id")===T},TAG:function(U,T){return(T==="*"&&U.nodeType===1)||U.nodeName===T},CLASS:function(U,T){return(" "+(U.className||U.getAttribute("class"))+" ").indexOf(T)>-1},ATTR:function(Y,W){var V=W[1],T=I.attrHandle[V]?I.attrHandle[V](Y):Y[V]!=null?Y[V]:Y.getAttribute(V),Z=T+"",X=W[2],U=W[4];return T==null?X==="!=":X==="="?Z===U:X==="*="?Z.indexOf(U)>=0:X==="~="?(" "+Z+" ").indexOf(U)>=0:!U?Z&&T!==false:X==="!="?Z!=U:X==="^="?Z.indexOf(U)===0:X==="$="?Z.substr(Z.length-U.length)===U:X==="|="?Z===U||Z.substr(0,U.length+1)===U+"-":false},POS:function(X,U,V,Y){var T=U[2],W=I.setFilters[T];if(W){return W(X,V,U,Y)}}}};var M=I.match.POS;for(var O in I.match){I.match[O]=RegExp(I.match[O].source+/(?![^\[]*\])(?![^\(]*\))/.source)}var E=function(U,T){U=Array.prototype.slice.call(U);if(T){T.push.apply(T,U);return T}return U};try{Array.prototype.slice.call(document.documentElement.childNodes)}catch(N){E=function(X,W){var U=W||[];if(H.call(X)==="[object Array]"){Array.prototype.push.apply(U,X)}else{if(typeof X.length==="number"){for(var V=0,T=X.length;V";var T=document.documentElement;T.insertBefore(U,T.firstChild);if(!!document.getElementById(V)){I.find.ID=function(X,Y,Z){if(typeof Y.getElementById!=="undefined"&&!Z){var W=Y.getElementById(X[1]);return W?W.id===X[1]||typeof W.getAttributeNode!=="undefined"&&W.getAttributeNode("id").nodeValue===X[1]?[W]:g:[]}};I.filter.ID=function(Y,W){var X=typeof Y.getAttributeNode!=="undefined"&&Y.getAttributeNode("id");return Y.nodeType===1&&X&&X.nodeValue===W}}T.removeChild(U)})();(function(){var T=document.createElement("div");T.appendChild(document.createComment(""));if(T.getElementsByTagName("*").length>0){I.find.TAG=function(U,Y){var X=Y.getElementsByTagName(U[1]);if(U[1]==="*"){var W=[];for(var V=0;X[V];V++){if(X[V].nodeType===1){W.push(X[V])}}X=W}return X}}T.innerHTML="";if(T.firstChild&&typeof T.firstChild.getAttribute!=="undefined"&&T.firstChild.getAttribute("href")!=="#"){I.attrHandle.href=function(U){return U.getAttribute("href",2)}}})();if(document.querySelectorAll){(function(){var T=F,U=document.createElement("div");U.innerHTML="

    ";if(U.querySelectorAll&&U.querySelectorAll(".TEST").length===0){return}F=function(Y,X,V,W){X=X||document;if(!W&&X.nodeType===9&&!Q(X)){try{return E(X.querySelectorAll(Y),V)}catch(Z){}}return T(Y,X,V,W)};F.find=T.find;F.filter=T.filter;F.selectors=T.selectors;F.matches=T.matches})()}if(document.getElementsByClassName&&document.documentElement.getElementsByClassName){(function(){var T=document.createElement("div");T.innerHTML="
    ";if(T.getElementsByClassName("e").length===0){return}T.lastChild.className="e";if(T.getElementsByClassName("e").length===1){return}I.order.splice(1,0,"CLASS");I.find.CLASS=function(U,V,W){if(typeof V.getElementsByClassName!=="undefined"&&!W){return V.getElementsByClassName(U[1])}}})()}function P(U,Z,Y,ad,aa,ac){var ab=U=="previousSibling"&&!ac;for(var W=0,V=ad.length;W0){X=T;break}}}T=T[U]}ad[W]=X}}}var K=document.compareDocumentPosition?function(U,T){return U.compareDocumentPosition(T)&16}:function(U,T){return U!==T&&(U.contains?U.contains(T):true)};var Q=function(T){return T.nodeType===9&&T.documentElement.nodeName!=="HTML"||!!T.ownerDocument&&Q(T.ownerDocument)};var J=function(T,aa){var W=[],X="",Y,V=aa.nodeType?[aa]:aa;while((Y=I.match.PSEUDO.exec(T))){X+=Y[0];T=T.replace(I.match.PSEUDO,"")}T=I.relative[T]?T+"*":T;for(var Z=0,U=V.length;Z0||T.offsetHeight>0};F.selectors.filters.animated=function(T){return o.grep(o.timers,function(U){return T===U.elem}).length};o.multiFilter=function(V,T,U){if(U){V=":not("+V+")"}return F.matches(V,T)};o.dir=function(V,U){var T=[],W=V[U];while(W&&W!=document){if(W.nodeType==1){T.push(W)}W=W[U]}return T};o.nth=function(X,T,V,W){T=T||1;var U=0;for(;X;X=X[V]){if(X.nodeType==1&&++U==T){break}}return X};o.sibling=function(V,U){var T=[];for(;V;V=V.nextSibling){if(V.nodeType==1&&V!=U){T.push(V)}}return T};return;l.Sizzle=F})();o.event={add:function(I,F,H,K){if(I.nodeType==3||I.nodeType==8){return}if(I.setInterval&&I!=l){I=l}if(!H.guid){H.guid=this.guid++}if(K!==g){var G=H;H=this.proxy(G);H.data=K}var E=o.data(I,"events")||o.data(I,"events",{}),J=o.data(I,"handle")||o.data(I,"handle",function(){return typeof o!=="undefined"&&!o.event.triggered?o.event.handle.apply(arguments.callee.elem,arguments):g});J.elem=I;o.each(F.split(/\s+/),function(M,N){var O=N.split(".");N=O.shift();H.type=O.slice().sort().join(".");var L=E[N];if(o.event.specialAll[N]){o.event.specialAll[N].setup.call(I,K,O)}if(!L){L=E[N]={};if(!o.event.special[N]||o.event.special[N].setup.call(I,K,O)===false){if(I.addEventListener){I.addEventListener(N,J,false)}else{if(I.attachEvent){I.attachEvent("on"+N,J)}}}}L[H.guid]=H;o.event.global[N]=true});I=null},guid:1,global:{},remove:function(K,H,J){if(K.nodeType==3||K.nodeType==8){return}var G=o.data(K,"events"),F,E;if(G){if(H===g||(typeof H==="string"&&H.charAt(0)==".")){for(var I in G){this.remove(K,I+(H||""))}}else{if(H.type){J=H.handler;H=H.type}o.each(H.split(/\s+/),function(M,O){var Q=O.split(".");O=Q.shift();var N=RegExp("(^|\\.)"+Q.slice().sort().join(".*\\.")+"(\\.|$)");if(G[O]){if(J){delete G[O][J.guid]}else{for(var P in G[O]){if(N.test(G[O][P].type)){delete G[O][P]}}}if(o.event.specialAll[O]){o.event.specialAll[O].teardown.call(K,Q)}for(F in G[O]){break}if(!F){if(!o.event.special[O]||o.event.special[O].teardown.call(K,Q)===false){if(K.removeEventListener){K.removeEventListener(O,o.data(K,"handle"),false)}else{if(K.detachEvent){K.detachEvent("on"+O,o.data(K,"handle"))}}}F=null;delete G[O]}}})}for(F in G){break}if(!F){var L=o.data(K,"handle");if(L){L.elem=null}o.removeData(K,"events");o.removeData(K,"handle")}}},trigger:function(I,K,H,E){var G=I.type||I;if(!E){I=typeof I==="object"?I[h]?I:o.extend(o.Event(G),I):o.Event(G);if(G.indexOf("!")>=0){I.type=G=G.slice(0,-1);I.exclusive=true}if(!H){I.stopPropagation();if(this.global[G]){o.each(o.cache,function(){if(this.events&&this.events[G]){o.event.trigger(I,K,this.handle.elem)}})}}if(!H||H.nodeType==3||H.nodeType==8){return g}I.result=g;I.target=H;K=o.makeArray(K);K.unshift(I)}I.currentTarget=H;var J=o.data(H,"handle");if(J){J.apply(H,K)}if((!H[G]||(o.nodeName(H,"a")&&G=="click"))&&H["on"+G]&&H["on"+G].apply(H,K)===false){I.result=false}if(!E&&H[G]&&!I.isDefaultPrevented()&&!(o.nodeName(H,"a")&&G=="click")){this.triggered=true;try{H[G]()}catch(L){}}this.triggered=false;if(!I.isPropagationStopped()){var F=H.parentNode||H.ownerDocument;if(F){o.event.trigger(I,K,F,true)}}},handle:function(K){var J,E;K=arguments[0]=o.event.fix(K||l.event);K.currentTarget=this;var L=K.type.split(".");K.type=L.shift();J=!L.length&&!K.exclusive;var I=RegExp("(^|\\.)"+L.slice().sort().join(".*\\.")+"(\\.|$)");E=(o.data(this,"events")||{})[K.type];for(var G in E){var H=E[G];if(J||I.test(H.type)){K.handler=H;K.data=H.data;var F=H.apply(this,arguments);if(F!==g){K.result=F;if(F===false){K.preventDefault();K.stopPropagation()}}if(K.isImmediatePropagationStopped()){break}}}},props:"altKey attrChange attrName bubbles button cancelable charCode clientX clientY ctrlKey currentTarget data detail eventPhase fromElement handler keyCode metaKey newValue originalTarget pageX pageY prevValue relatedNode relatedTarget screenX screenY shiftKey srcElement target toElement view wheelDelta which".split(" "),fix:function(H){if(H[h]){return H}var F=H;H=o.Event(F);for(var G=this.props.length,J;G;){J=this.props[--G];H[J]=F[J]}if(!H.target){H.target=H.srcElement||document}if(H.target.nodeType==3){H.target=H.target.parentNode}if(!H.relatedTarget&&H.fromElement){H.relatedTarget=H.fromElement==H.target?H.toElement:H.fromElement}if(H.pageX==null&&H.clientX!=null){var I=document.documentElement,E=document.body;H.pageX=H.clientX+(I&&I.scrollLeft||E&&E.scrollLeft||0)-(I.clientLeft||0);H.pageY=H.clientY+(I&&I.scrollTop||E&&E.scrollTop||0)-(I.clientTop||0)}if(!H.which&&((H.charCode||H.charCode===0)?H.charCode:H.keyCode)){H.which=H.charCode||H.keyCode}if(!H.metaKey&&H.ctrlKey){H.metaKey=H.ctrlKey}if(!H.which&&H.button){H.which=(H.button&1?1:(H.button&2?3:(H.button&4?2:0)))}return H},proxy:function(F,E){E=E||function(){return F.apply(this,arguments)};E.guid=F.guid=F.guid||E.guid||this.guid++;return E},special:{ready:{setup:B,teardown:function(){}}},specialAll:{live:{setup:function(E,F){o.event.add(this,F[0],c)},teardown:function(G){if(G.length){var E=0,F=RegExp("(^|\\.)"+G[0]+"(\\.|$)");o.each((o.data(this,"events").live||{}),function(){if(F.test(this.type)){E++}});if(E<1){o.event.remove(this,G[0],c)}}}}}};o.Event=function(E){if(!this.preventDefault){return new o.Event(E)}if(E&&E.type){this.originalEvent=E;this.type=E.type}else{this.type=E}this.timeStamp=e();this[h]=true};function k(){return false}function u(){return true}o.Event.prototype={preventDefault:function(){this.isDefaultPrevented=u;var E=this.originalEvent;if(!E){return}if(E.preventDefault){E.preventDefault()}E.returnValue=false},stopPropagation:function(){this.isPropagationStopped=u;var E=this.originalEvent;if(!E){return}if(E.stopPropagation){E.stopPropagation()}E.cancelBubble=true},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=u;this.stopPropagation()},isDefaultPrevented:k,isPropagationStopped:k,isImmediatePropagationStopped:k};var a=function(F){var E=F.relatedTarget;while(E&&E!=this){try{E=E.parentNode}catch(G){E=this}}if(E!=this){F.type=F.data;o.event.handle.apply(this,arguments)}};o.each({mouseover:"mouseenter",mouseout:"mouseleave"},function(F,E){o.event.special[E]={setup:function(){o.event.add(this,F,a,E)},teardown:function(){o.event.remove(this,F,a)}}});o.fn.extend({bind:function(F,G,E){return F=="unload"?this.one(F,G,E):this.each(function(){o.event.add(this,F,E||G,E&&G)})},one:function(G,H,F){var E=o.event.proxy(F||H,function(I){o(this).unbind(I,E);return(F||H).apply(this,arguments)});return this.each(function(){o.event.add(this,G,E,F&&H)})},unbind:function(F,E){return this.each(function(){o.event.remove(this,F,E)})},trigger:function(E,F){return this.each(function(){o.event.trigger(E,F,this)})},triggerHandler:function(E,G){if(this[0]){var F=o.Event(E);F.preventDefault();F.stopPropagation();o.event.trigger(F,G,this[0]);return F.result}},toggle:function(G){var E=arguments,F=1;while(F=0){var E=G.slice(I,G.length);G=G.slice(0,I)}var H="GET";if(J){if(o.isFunction(J)){K=J;J=null}else{if(typeof J==="object"){J=o.param(J);H="POST"}}}var F=this;o.ajax({url:G,type:H,dataType:"html",data:J,complete:function(M,L){if(L=="success"||L=="notmodified"){F.html(E?o("
    ").append(M.responseText.replace(//g,"")).find(E):M.responseText)}if(K){F.each(K,[M.responseText,L,M])}}});return this},serialize:function(){return o.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?o.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||/select|textarea/i.test(this.nodeName)||/text|hidden|password|search/i.test(this.type))}).map(function(E,F){var G=o(this).val();return G==null?null:o.isArray(G)?o.map(G,function(I,H){return{name:F.name,value:I}}):{name:F.name,value:G}}).get()}});o.each("ajaxStart,ajaxStop,ajaxComplete,ajaxError,ajaxSuccess,ajaxSend".split(","),function(E,F){o.fn[F]=function(G){return this.bind(F,G)}});var r=e();o.extend({get:function(E,G,H,F){if(o.isFunction(G)){H=G;G=null}return o.ajax({type:"GET",url:E,data:G,success:H,dataType:F})},getScript:function(E,F){return o.get(E,null,F,"script")},getJSON:function(E,F,G){return o.get(E,F,G,"json")},post:function(E,G,H,F){if(o.isFunction(G)){H=G;G={}}return o.ajax({type:"POST",url:E,data:G,success:H,dataType:F})},ajaxSetup:function(E){o.extend(o.ajaxSettings,E)},ajaxSettings:{url:location.href,global:true,type:"GET",contentType:"application/x-www-form-urlencoded",processData:true,async:true,xhr:function(){return l.ActiveXObject?new ActiveXObject("Microsoft.XMLHTTP"):new XMLHttpRequest()},accepts:{xml:"application/xml, text/xml",html:"text/html",script:"text/javascript, application/javascript",json:"application/json, text/javascript",text:"text/plain",_default:"*/*"}},lastModified:{},ajax:function(M){M=o.extend(true,M,o.extend(true,{},o.ajaxSettings,M));var W,F=/=\?(&|$)/g,R,V,G=M.type.toUpperCase();if(M.data&&M.processData&&typeof M.data!=="string"){M.data=o.param(M.data)}if(M.dataType=="jsonp"){if(G=="GET"){if(!M.url.match(F)){M.url+=(M.url.match(/\?/)?"&":"?")+(M.jsonp||"callback")+"=?"}}else{if(!M.data||!M.data.match(F)){M.data=(M.data?M.data+"&":"")+(M.jsonp||"callback")+"=?"}}M.dataType="json"}if(M.dataType=="json"&&(M.data&&M.data.match(F)||M.url.match(F))){W="jsonp"+r++;if(M.data){M.data=(M.data+"").replace(F,"="+W+"$1")}M.url=M.url.replace(F,"="+W+"$1");M.dataType="script";l[W]=function(X){V=X;I();L();l[W]=g;try{delete l[W]}catch(Y){}if(H){H.removeChild(T)}}}if(M.dataType=="script"&&M.cache==null){M.cache=false}if(M.cache===false&&G=="GET"){var E=e();var U=M.url.replace(/(\?|&)_=.*?(&|$)/,"$1_="+E+"$2");M.url=U+((U==M.url)?(M.url.match(/\?/)?"&":"?")+"_="+E:"")}if(M.data&&G=="GET"){M.url+=(M.url.match(/\?/)?"&":"?")+M.data;M.data=null}if(M.global&&!o.active++){o.event.trigger("ajaxStart")}var Q=/^(\w+:)?\/\/([^\/?#]+)/.exec(M.url);if(M.dataType=="script"&&G=="GET"&&Q&&(Q[1]&&Q[1]!=location.protocol||Q[2]!=location.host)){var H=document.getElementsByTagName("head")[0];var T=document.createElement("script");T.src=M.url;if(M.scriptCharset){T.charset=M.scriptCharset}if(!W){var O=false;T.onload=T.onreadystatechange=function(){if(!O&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){O=true;I();L();T.onload=T.onreadystatechange=null;H.removeChild(T)}}}H.appendChild(T);return g}var K=false;var J=M.xhr();if(M.username){J.open(G,M.url,M.async,M.username,M.password)}else{J.open(G,M.url,M.async)}try{if(M.data){J.setRequestHeader("Content-Type",M.contentType)}if(M.ifModified){J.setRequestHeader("If-Modified-Since",o.lastModified[M.url]||"Thu, 01 Jan 1970 00:00:00 GMT")}J.setRequestHeader("X-Requested-With","XMLHttpRequest");J.setRequestHeader("Accept",M.dataType&&M.accepts[M.dataType]?M.accepts[M.dataType]+", */*":M.accepts._default)}catch(S){}if(M.beforeSend&&M.beforeSend(J,M)===false){if(M.global&&!--o.active){o.event.trigger("ajaxStop")}J.abort();return false}if(M.global){o.event.trigger("ajaxSend",[J,M])}var N=function(X){if(J.readyState==0){if(P){clearInterval(P);P=null;if(M.global&&!--o.active){o.event.trigger("ajaxStop")}}}else{if(!K&&J&&(J.readyState==4||X=="timeout")){K=true;if(P){clearInterval(P);P=null}R=X=="timeout"?"timeout":!o.httpSuccess(J)?"error":M.ifModified&&o.httpNotModified(J,M.url)?"notmodified":"success";if(R=="success"){try{V=o.httpData(J,M.dataType,M)}catch(Z){R="parsererror"}}if(R=="success"){var Y;try{Y=J.getResponseHeader("Last-Modified")}catch(Z){}if(M.ifModified&&Y){o.lastModified[M.url]=Y}if(!W){I()}}else{o.handleError(M,J,R)}L();if(X){J.abort()}if(M.async){J=null}}}};if(M.async){var P=setInterval(N,13);if(M.timeout>0){setTimeout(function(){if(J&&!K){N("timeout")}},M.timeout)}}try{J.send(M.data)}catch(S){o.handleError(M,J,null,S)}if(!M.async){N()}function I(){if(M.success){M.success(V,R)}if(M.global){o.event.trigger("ajaxSuccess",[J,M])}}function L(){if(M.complete){M.complete(J,R)}if(M.global){o.event.trigger("ajaxComplete",[J,M])}if(M.global&&!--o.active){o.event.trigger("ajaxStop")}}return J},handleError:function(F,H,E,G){if(F.error){F.error(H,E,G)}if(F.global){o.event.trigger("ajaxError",[H,F,G])}},active:0,httpSuccess:function(F){try{return !F.status&&location.protocol=="file:"||(F.status>=200&&F.status<300)||F.status==304||F.status==1223}catch(E){}return false},httpNotModified:function(G,E){try{var H=G.getResponseHeader("Last-Modified");return G.status==304||H==o.lastModified[E]}catch(F){}return false},httpData:function(J,H,G){var F=J.getResponseHeader("content-type"),E=H=="xml"||!H&&F&&F.indexOf("xml")>=0,I=E?J.responseXML:J.responseText;if(E&&I.documentElement.tagName=="parsererror"){throw"parsererror"}if(G&&G.dataFilter){I=G.dataFilter(I,H)}if(typeof I==="string"){if(H=="script"){o.globalEval(I)}if(H=="json"){I=l["eval"]("("+I+")")}}return I},param:function(E){var G=[];function H(I,J){G[G.length]=encodeURIComponent(I)+"="+encodeURIComponent(J)}if(o.isArray(E)||E.jquery){o.each(E,function(){H(this.name,this.value)})}else{for(var F in E){if(o.isArray(E[F])){o.each(E[F],function(){H(F,this)})}else{H(F,o.isFunction(E[F])?E[F]():E[F])}}}return G.join("&").replace(/%20/g,"+")}});var m={},n,d=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]];function t(F,E){var G={};o.each(d.concat.apply([],d.slice(0,E)),function(){G[this]=F});return G}o.fn.extend({show:function(J,L){if(J){return this.animate(t("show",3),J,L)}else{for(var H=0,F=this.length;H").appendTo("body");K=I.css("display");if(K==="none"){K="block"}I.remove();m[G]=K}o.data(this[H],"olddisplay",K)}}for(var H=0,F=this.length;H=0;H--){if(G[H].elem==this){if(E){G[H](true)}G.splice(H,1)}}});if(!E){this.dequeue()}return this}});o.each({slideDown:t("show",1),slideUp:t("hide",1),slideToggle:t("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"}},function(E,F){o.fn[E]=function(G,H){return this.animate(F,G,H)}});o.extend({speed:function(G,H,F){var E=typeof G==="object"?G:{complete:F||!F&&H||o.isFunction(G)&&G,duration:G,easing:F&&H||H&&!o.isFunction(H)&&H};E.duration=o.fx.off?0:typeof E.duration==="number"?E.duration:o.fx.speeds[E.duration]||o.fx.speeds._default;E.old=E.complete;E.complete=function(){if(E.queue!==false){o(this).dequeue()}if(o.isFunction(E.old)){E.old.call(this)}};return E},easing:{linear:function(G,H,E,F){return E+F*G},swing:function(G,H,E,F){return((-Math.cos(G*Math.PI)/2)+0.5)*F+E}},timers:[],fx:function(F,E,G){this.options=E;this.elem=F;this.prop=G;if(!E.orig){E.orig={}}}});o.fx.prototype={update:function(){if(this.options.step){this.options.step.call(this.elem,this.now,this)}(o.fx.step[this.prop]||o.fx.step._default)(this);if((this.prop=="height"||this.prop=="width")&&this.elem.style){this.elem.style.display="block"}},cur:function(F){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null)){return this.elem[this.prop]}var E=parseFloat(o.css(this.elem,this.prop,F));return E&&E>-10000?E:parseFloat(o.curCSS(this.elem,this.prop))||0},custom:function(I,H,G){this.startTime=e();this.start=I;this.end=H;this.unit=G||this.unit||"px";this.now=this.start;this.pos=this.state=0;var E=this;function F(J){return E.step(J)}F.elem=this.elem;if(F()&&o.timers.push(F)&&!n){n=setInterval(function(){var K=o.timers;for(var J=0;J=this.options.duration+this.startTime){this.now=this.end;this.pos=this.state=1;this.update();this.options.curAnim[this.prop]=true;var E=true;for(var F in this.options.curAnim){if(this.options.curAnim[F]!==true){E=false}}if(E){if(this.options.display!=null){this.elem.style.overflow=this.options.overflow;this.elem.style.display=this.options.display;if(o.css(this.elem,"display")=="none"){this.elem.style.display="block"}}if(this.options.hide){o(this.elem).hide()}if(this.options.hide||this.options.show){for(var I in this.options.curAnim){o.attr(this.elem.style,I,this.options.orig[I])}}this.options.complete.call(this.elem)}return false}else{var J=G-this.startTime;this.state=J/this.options.duration;this.pos=o.easing[this.options.easing||(o.easing.swing?"swing":"linear")](this.state,J,0,1,this.options.duration);this.now=this.start+((this.end-this.start)*this.pos);this.update()}return true}};o.extend(o.fx,{speeds:{slow:600,fast:200,_default:400},step:{opacity:function(E){o.attr(E.elem.style,"opacity",E.now)},_default:function(E){if(E.elem.style&&E.elem.style[E.prop]!=null){E.elem.style[E.prop]=E.now+E.unit}else{E.elem[E.prop]=E.now}}}});if(document.documentElement.getBoundingClientRect){o.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return o.offset.bodyOffset(this[0])}var G=this[0].getBoundingClientRect(),J=this[0].ownerDocument,F=J.body,E=J.documentElement,L=E.clientTop||F.clientTop||0,K=E.clientLeft||F.clientLeft||0,I=G.top+(self.pageYOffset||o.boxModel&&E.scrollTop||F.scrollTop)-L,H=G.left+(self.pageXOffset||o.boxModel&&E.scrollLeft||F.scrollLeft)-K;return{top:I,left:H}}}else{o.fn.offset=function(){if(!this[0]){return{top:0,left:0}}if(this[0]===this[0].ownerDocument.body){return o.offset.bodyOffset(this[0])}o.offset.initialized||o.offset.initialize();var J=this[0],G=J.offsetParent,F=J,O=J.ownerDocument,M,H=O.documentElement,K=O.body,L=O.defaultView,E=L.getComputedStyle(J,null),N=J.offsetTop,I=J.offsetLeft;while((J=J.parentNode)&&J!==K&&J!==H){M=L.getComputedStyle(J,null);N-=J.scrollTop,I-=J.scrollLeft;if(J===G){N+=J.offsetTop,I+=J.offsetLeft;if(o.offset.doesNotAddBorder&&!(o.offset.doesAddBorderForTableAndCells&&/^t(able|d|h)$/i.test(J.tagName))){N+=parseInt(M.borderTopWidth,10)||0,I+=parseInt(M.borderLeftWidth,10)||0}F=G,G=J.offsetParent}if(o.offset.subtractsBorderForOverflowNotVisible&&M.overflow!=="visible"){N+=parseInt(M.borderTopWidth,10)||0,I+=parseInt(M.borderLeftWidth,10)||0}E=M}if(E.position==="relative"||E.position==="static"){N+=K.offsetTop,I+=K.offsetLeft}if(E.position==="fixed"){N+=Math.max(H.scrollTop,K.scrollTop),I+=Math.max(H.scrollLeft,K.scrollLeft)}return{top:N,left:I}}}o.offset={initialize:function(){if(this.initialized){return}var L=document.body,F=document.createElement("div"),H,G,N,I,M,E,J=L.style.marginTop,K='
    ';M={position:"absolute",top:0,left:0,margin:0,border:0,width:"1px",height:"1px",visibility:"hidden"};for(E in M){F.style[E]=M[E]}F.innerHTML=K;L.insertBefore(F,L.firstChild);H=F.firstChild,G=H.firstChild,I=H.nextSibling.firstChild.firstChild;this.doesNotAddBorder=(G.offsetTop!==5);this.doesAddBorderForTableAndCells=(I.offsetTop===5);H.style.overflow="hidden",H.style.position="relative";this.subtractsBorderForOverflowNotVisible=(G.offsetTop===-5);L.style.marginTop="1px";this.doesNotIncludeMarginInBodyOffset=(L.offsetTop===0);L.style.marginTop=J;L.removeChild(F);this.initialized=true},bodyOffset:function(E){o.offset.initialized||o.offset.initialize();var G=E.offsetTop,F=E.offsetLeft;if(o.offset.doesNotIncludeMarginInBodyOffset){G+=parseInt(o.curCSS(E,"marginTop",true),10)||0,F+=parseInt(o.curCSS(E,"marginLeft",true),10)||0}return{top:G,left:F}}};o.fn.extend({position:function(){var I=0,H=0,F;if(this[0]){var G=this.offsetParent(),J=this.offset(),E=/^body|html$/i.test(G[0].tagName)?{top:0,left:0}:G.offset();J.top-=j(this,"marginTop");J.left-=j(this,"marginLeft");E.top+=j(G,"borderTopWidth");E.left+=j(G,"borderLeftWidth");F={top:J.top-E.top,left:J.left-E.left}}return F},offsetParent:function(){var E=this[0].offsetParent||document.body;while(E&&(!/^body|html$/i.test(E.tagName)&&o.css(E,"position")=="static")){E=E.offsetParent}return o(E)}});o.each(["Left","Top"],function(F,E){var G="scroll"+E;o.fn[G]=function(H){if(!this[0]){return null}return H!==g?this.each(function(){this==l||this==document?l.scrollTo(!F?H:o(l).scrollLeft(),F?H:o(l).scrollTop()):this[G]=H}):this[0]==l||this[0]==document?self[F?"pageYOffset":"pageXOffset"]||o.boxModel&&document.documentElement[G]||document.body[G]:this[0][G]}});o.each(["Height","Width"],function(I,G){var E=I?"Left":"Top",H=I?"Right":"Bottom",F=G.toLowerCase();o.fn["inner"+G]=function(){return this[0]?o.css(this[0],F,false,"padding"):null};o.fn["outer"+G]=function(K){return this[0]?o.css(this[0],F,false,K?"margin":"border"):null};var J=G.toLowerCase();o.fn[J]=function(K){return this[0]==l?document.compatMode=="CSS1Compat"&&document.documentElement["client"+G]||document.body["client"+G]:this[0]==document?Math.max(document.documentElement["client"+G],document.body["scroll"+G],document.documentElement["scroll"+G],document.body["offset"+G],document.documentElement["offset"+G]):K===g?(this.length?o.css(this[0],J):null):this.css(J,typeof K==="string"?K:K+"px")}})})(); \ No newline at end of file diff --git a/lib/js-test-driver/qunit/History.txt b/lib/js-test-driver/qunit/History.txt new file mode 100644 index 0000000..1ec0714 --- /dev/null +++ b/lib/js-test-driver/qunit/History.txt @@ -0,0 +1,10 @@ +1.0.1 +----- + +Fixed ok() assertion to behave the same as jquery (it now succeeds with anything other than 0, false, or null) + + +1.0 +--- + +First release \ No newline at end of file diff --git a/lib/js-test-driver/qunit/QUnitAdapter.js b/lib/js-test-driver/qunit/QUnitAdapter.js new file mode 100644 index 0000000..bf71aea --- /dev/null +++ b/lib/js-test-driver/qunit/QUnitAdapter.js @@ -0,0 +1,77 @@ +/* +QUnitAdapter +Version: 1.0.1 + +Run qunit tests using JS Test Driver + +This provides almost the same api as qunit. + +Tests must run sychronously, which means no use of stop and start methods. +You can use jsUnit Clock object to deal with timeouts and intervals: +http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html + +The qunit #main DOM element is not included. If you need to do any DOM manipulation +you need to set it up and tear it down in each test. + +*/ +(function() { + + window.module = function(name, lifecycle) { + QUnitTestCase = TestCase(name); + QUnitTestCase.tearDown = function() {}; + + if (lifecycle) { + QUnitTestCase.prototype.setUp = lifecycle.setup; + QUnitTestCase.tearDown = lifecycle.teardown; + } + }; + + window.test = function(name, test) { + var tearDown = QUnitTestCase.tearDown; + QUnitTestCase.prototype['test ' + name] = function() { + try { + test(); + } catch(ex) { + throw(ex); + } finally { + tearDown(); + } + }; + }; + + window.expect = function(count) { + expectAsserts(count); + }; + + window.ok = function(actual, msg) { + assertTrue(msg ? msg : '', !!actual); + }; + + window.equals = function(a, b, msg) { + assertEquals(msg ? msg : '', b, a); + }; + + window.start = window.stop = function() { + fail('start and stop methods are not available when using JS Test Driver.\n' + + 'Use jsUnit Clock object to deal with timeouts and intervals:\n' + + 'http://googletesting.blogspot.com/2007/03/javascript-simulating-time-in-jsunit.html.'); + }; + + window.same = function(a, b, msg) { + assertTrue(msg ? msg : '', window.equiv(b, a)); + }; + + window.reset = function() { + fail('reset method is not available when using JS Test Driver'); + }; + + window.isLocal = function() { + return false; + }; + + window.QUnit = { + equiv: window.equiv, + ok: window.ok + }; + +})(); diff --git a/lib/js-test-driver/qunit/README b/lib/js-test-driver/qunit/README new file mode 100644 index 0000000..5784151 --- /dev/null +++ b/lib/js-test-driver/qunit/README @@ -0,0 +1,74 @@ +QUnit to JS Test Driver adapter +=============================== + +Version: 1.0.1 +Author: Karl O'Keeffe (karl@monket.net, http://monket.net) +Blog post introduction: http://monket.net/blog/2009/06/new-qunit-to-js-test-driver-adapter/ +http://code.google.com/p/js-test-driver/source/browse/#svn/trunk/JsTestDriver/contrib/qunit + +Introduction +------------ + +Qunit Adapter provides a small wrapper around your QUnit tests that allows them to be run using JS Test Driver. + +It works by converting each qunit test and assertion into corresponding JS Test Driver test methods and assertions. Each qunit module maps to a JS Test Driver TestCase, each qunit test maps to a test method on that TestCase. And each qunit ok, equals, or same assertion maps to a JS Test Driver assertion. Qunit lifecycles (setup and teardown) also map to JS Test Driver setUp and tearDown. + +This ensures you still get assertion level error reporting when running your qunit tests with JS Test Driver. + +Essentially this adapter allows you to write native JS Test Driver tests, but using the less verbose qunit syntax. + + +Installing the QUnit Adapter +---------------------------- + +Copy both the equiv.js and QUnitAdapter.js files to your project test directory (for example tests/qunit/). + + +Configuring JS Test Driver +-------------------------- + +To run your qunit tests in JS Test Driver you need to configure it to load the adapter before your qunit tests. + +Update your jsTestDriver.conf to load the files: + + server: http://localhost:9876 + + load: + # Add these lines to load the equiv function and adapter in order, before the tests + # (assuming they are saved to tests/qunit/) + - tests/qunit/equiv.js + - tests/qunit/QUnitAdapter.js + + # This is where we load the qunit tests + - tests/js/*.js + + # And this loads the source files we are testing + - src/js/*.js + + +Running JS Test Driver with qunit tests +--------------------------------------- + +Now we can run JS Test Driver and watch as it runs all our qunit tests! + +The tests will run as individual JS Test Driver tests, with the format Module Name.Test Name. + +Example output: + + [PASSED] Module 1.test Test 1 + [PASSED] Module 1.test Test 2 + [PASSED] Module 2.test Test 1 + Total 3 tests (Passed: 3; Fails: 0; Errors: 0) (1.00 ms) + Safari 530.18: Run 3 tests (Passed: 3; Fails: 0; Errors 0) (1.00 ms) + + +Limitations +----------- + +There are a few limitations on which qunit tests will successfully be converted. + +The tests must run synchronously (which means no use of the qunit stop and start methods). + +If you need to test timeouts, intervals, or other asynchronous sections of code, consider using the jsUnit Clock object to deal with timeouts and intervals. + +QUnit DOM support is not included. Consider avoiding interacting directly with the browser within your unit tests. But if you do need to, you’ll need to create and remove the DOM objects yourself with each test, or the setup and teardown methods. diff --git a/lib/js-test-driver/qunit/equiv.js b/lib/js-test-driver/qunit/equiv.js new file mode 100644 index 0000000..a69b974 --- /dev/null +++ b/lib/js-test-driver/qunit/equiv.js @@ -0,0 +1,185 @@ + +// Tests for equality any JavaScript type and structure without unexpected results. +// Discussions and reference: http://philrathe.com/articles/equiv +// Test suites: http://philrathe.com/tests/equiv +// Author: Philippe RathŽ +window.equiv = function () { + + var innerEquiv; // the real equiv function + var callers = []; // stack to decide between skip/abort functions + + // Determine what is o. + function hoozit(o) { + if (typeof o === "string") { + return "string"; + + } else if (typeof o === "boolean") { + return "boolean"; + + } else if (typeof o === "number") { + + if (isNaN(o)) { + return "nan"; + } else { + return "number"; + } + + } else if (typeof o === "undefined") { + return "undefined"; + + // consider: typeof null === object + } else if (o === null) { + return "null"; + + // consider: typeof [] === object + } else if (o instanceof Array) { + return "array"; + + // consider: typeof new Date() === object + } else if (o instanceof Date) { + return "date"; + + // consider: /./ instanceof Object; + // /./ instanceof RegExp; + // typeof /./ === "function"; // => false in IE and Opera, + // true in FF and Safari + } else if (o instanceof RegExp) { + return "regexp"; + + } else if (typeof o === "object") { + return "object"; + + } else if (o instanceof Function) { + return "function"; + } + } + + // Call the o related callback with the given arguments. + function bindCallbacks(o, callbacks, args) { + var prop = hoozit(o); + if (prop) { + if (hoozit(callbacks[prop]) === "function") { + return callbacks[prop].apply(callbacks, args); + } else { + return callbacks[prop]; // or undefined + } + } + } + + var callbacks = function () { + + // for string, boolean, number and null + function useStrictEquality(b, a) { + return a === b; + } + + return { + "string": useStrictEquality, + "boolean": useStrictEquality, + "number": useStrictEquality, + "null": useStrictEquality, + "undefined": useStrictEquality, + + "nan": function (b) { + return isNaN(b); + }, + + "date": function (b, a) { + return hoozit(b) === "date" && a.valueOf() === b.valueOf(); + }, + + "regexp": function (b, a) { + return hoozit(b) === "regexp" && + a.source === b.source && // the regex itself + a.global === b.global && // and its modifers (gmi) ... + a.ignoreCase === b.ignoreCase && + a.multiline === b.multiline; + }, + + // - skip when the property is a method of an instance (OOP) + // - abort otherwise, + // initial === would have catch identical references anyway + "function": function () { + var caller = callers[callers.length - 1]; + return caller !== Object && + typeof caller !== "undefined"; + }, + + "array": function (b, a) { + var i; + var len; + + // b could be an object literal here + if ( ! (hoozit(b) === "array")) { + return false; + } + + len = a.length; + if (len !== b.length) { // safe and faster + return false; + } + for (i = 0; i < len; i++) { + if( ! innerEquiv(a[i], b[i])) { + return false; + } + } + return true; + }, + + "object": function (b, a) { + var i; + var eq = true; // unless we can proove it + var aProperties = [], bProperties = []; // collection of strings + + // comparing constructors is more strict than using instanceof + if ( a.constructor !== b.constructor) { + return false; + } + + // stack constructor before traversing properties + callers.push(a.constructor); + + for (i in a) { // be strict: don't ensures hasOwnProperty and go deep + + aProperties.push(i); // collect a's properties + + if ( ! innerEquiv(a[i], b[i])) { + eq = false; + } + } + + callers.pop(); // unstack, we are done + + for (i in b) { + bProperties.push(i); // collect b's properties + } + + // Ensures identical properties name + return eq && innerEquiv(aProperties.sort(), bProperties.sort()); + } + }; + }(); + + innerEquiv = function () { // can take multiple arguments + var args = Array.prototype.slice.apply(arguments); + if (args.length < 2) { + return true; // end transition + } + + return (function (a, b) { + if (a === b) { + return true; // catch the most you can + + } else if (typeof a !== typeof b || a === null || b === null || typeof a === "undefined" || typeof b === "undefined") { + return false; // don't lose time with error prone cases + + } else { + return bindCallbacks(a, callbacks, [b, a]); + } + + // apply transition with (1..n) arguments + })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1)); + }; + + return innerEquiv; +}(); // equiv \ No newline at end of file diff --git a/lib/qunit/testrunner.js b/lib/qunit/testrunner.js new file mode 100755 index 0000000..c1c5cae --- /dev/null +++ b/lib/qunit/testrunner.js @@ -0,0 +1,803 @@ +/* + * QUnit - jQuery unit testrunner + * + * http://docs.jquery.com/QUnit + * + * Copyright (c) 2008 John Resig, Jörn Zaefferer + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * $Id: testrunner.js 6416 2009-07-10 16:08:27Z joern.zaefferer $ + */ + +(function($) { + +// Test for equality any JavaScript type. +// Discussions and reference: http://philrathe.com/articles/equiv +// Test suites: http://philrathe.com/tests/equiv +// Author: Philippe Rathé +var equiv = function () { + + var innerEquiv; // the real equiv function + var callers = []; // stack to decide between skip/abort functions + + + // Determine what is o. + function hoozit(o) { + if (o.constructor === String) { + return "string"; + + } else if (o.constructor === Boolean) { + return "boolean"; + + } else if (o.constructor === Number) { + + if (isNaN(o)) { + return "nan"; + } else { + return "number"; + } + + } else if (typeof o === "undefined") { + return "undefined"; + + // consider: typeof null === object + } else if (o === null) { + return "null"; + + // consider: typeof [] === object + } else if (o instanceof Array) { + return "array"; + + // consider: typeof new Date() === object + } else if (o instanceof Date) { + return "date"; + + // consider: /./ instanceof Object; + // /./ instanceof RegExp; + // typeof /./ === "function"; // => false in IE and Opera, + // true in FF and Safari + } else if (o instanceof RegExp) { + return "regexp"; + + } else if (typeof o === "object") { + return "object"; + + } else if (o instanceof Function) { + return "function"; + } else { + return undefined; + } + } + + // Call the o related callback with the given arguments. + function bindCallbacks(o, callbacks, args) { + var prop = hoozit(o); + if (prop) { + if (hoozit(callbacks[prop]) === "function") { + return callbacks[prop].apply(callbacks, args); + } else { + return callbacks[prop]; // or undefined + } + } + } + + var callbacks = function () { + + // for string, boolean, number and null + function useStrictEquality(b, a) { + if (b instanceof a.constructor || a instanceof b.constructor) { + // to catch short annotaion VS 'new' annotation of a declaration + // e.g. var i = 1; + // var j = new Number(1); + return a == b; + } else { + return a === b; + } + } + + return { + "string": useStrictEquality, + "boolean": useStrictEquality, + "number": useStrictEquality, + "null": useStrictEquality, + "undefined": useStrictEquality, + + "nan": function (b) { + return isNaN(b); + }, + + "date": function (b, a) { + return hoozit(b) === "date" && a.valueOf() === b.valueOf(); + }, + + "regexp": function (b, a) { + return hoozit(b) === "regexp" && + a.source === b.source && // the regex itself + a.global === b.global && // and its modifers (gmi) ... + a.ignoreCase === b.ignoreCase && + a.multiline === b.multiline; + }, + + // - skip when the property is a method of an instance (OOP) + // - abort otherwise, + // initial === would have catch identical references anyway + "function": function () { + var caller = callers[callers.length - 1]; + return caller !== Object && + typeof caller !== "undefined"; + }, + + "array": function (b, a) { + var i; + var len; + + // b could be an object literal here + if ( ! (hoozit(b) === "array")) { + return false; + } + + len = a.length; + if (len !== b.length) { // safe and faster + return false; + } + for (i = 0; i < len; i++) { + if( ! innerEquiv(a[i], b[i])) { + return false; + } + } + return true; + }, + + "object": function (b, a) { + var i; + var eq = true; // unless we can proove it + var aProperties = [], bProperties = []; // collection of strings + + // comparing constructors is more strict than using instanceof + if ( a.constructor !== b.constructor) { + return false; + } + + // stack constructor before traversing properties + callers.push(a.constructor); + + for (i in a) { // be strict: don't ensures hasOwnProperty and go deep + + aProperties.push(i); // collect a's properties + + if ( ! innerEquiv(a[i], b[i])) { + eq = false; + } + } + + callers.pop(); // unstack, we are done + + for (i in b) { + bProperties.push(i); // collect b's properties + } + + // Ensures identical properties name + return eq && innerEquiv(aProperties.sort(), bProperties.sort()); + } + }; + }(); + + innerEquiv = function () { // can take multiple arguments + var args = Array.prototype.slice.apply(arguments); + if (args.length < 2) { + return true; // end transition + } + + return (function (a, b) { + if (a === b) { + return true; // catch the most you can + } else if (a === null || b === null || typeof a === "undefined" || typeof b === "undefined" || hoozit(a) !== hoozit(b)) { + return false; // don't lose time with error prone cases + } else { + return bindCallbacks(a, callbacks, [b, a]); + } + + // apply transition with (1..n) arguments + })(args[0], args[1]) && arguments.callee.apply(this, args.splice(1, args.length -1)); + }; + + return innerEquiv; + +}(); + +var GETParams = $.map( location.search.slice(1).split('&'), decodeURIComponent ), + ngindex = $.inArray("noglobals", GETParams), + noglobals = ngindex !== -1; + +if( noglobals ) + GETParams.splice( ngindex, 1 ); + +var config = { + stats: { + all: 0, + bad: 0 + }, + queue: [], + // block until document ready + blocking: true, + //restrict modules/tests by get parameters + filters: GETParams, + isLocal: !!(window.location.protocol == 'file:') +}; + +// public API as global methods +$.extend(window, { + test: test, + module: module, + expect: expect, + ok: ok, + equals: equals, + start: start, + stop: stop, + reset: reset, + isLocal: config.isLocal, + same: function(a, b, message) { + push(equiv(a, b), a, b, message); + }, + QUnit: { + equiv: equiv, + ok: ok, + done: function(failures, total){}, + log: function(result, message){} + }, + // legacy methods below + isSet: isSet, + isObj: isObj, + compare: function() { + throw "compare is deprecated - use same() instead"; + }, + compare2: function() { + throw "compare2 is deprecated - use same() instead"; + }, + serialArray: function() { + throw "serialArray is deprecated - use jsDump.parse() instead"; + }, + q: q, + t: t, + url: url, + triggerEvent: triggerEvent +}); + +$(window).load(function() { + + if (!$("#header, #banner, #userAgent, #tests").length) { + $('body').prepend( + '

    ' + document.title + '

    ' + + '' + + '

    ' + + '
      ' + ); + } + + $('#userAgent').html(navigator.userAgent); + var head = $('
      ').insertAfter("#userAgent"); + $('').attr("disabled", true).prependTo(head).click(function() { + $('li.pass')[this.checked ? 'hide' : 'show'](); + }); + $('').attr("disabled", true).appendTo(head).click(function() { + $("li.fail:contains('missing test - untested code is broken code')").parent('ol').parent('li.fail')[this.checked ? 'hide' : 'show'](); + }); + $("#filter-missing").after(''); + runTest(); +}); + +function synchronize(callback) { + config.queue.push(callback); + if(!config.blocking) { + process(); + } +} + +function process() { + while(config.queue.length && !config.blocking) { + config.queue.shift()(); + } +} + +function stop(timeout) { + config.blocking = true; + if (timeout) + config.timeout = setTimeout(function() { + QUnit.ok( false, "Test timed out" ); + start(); + }, timeout); +} +function start() { + // A slight delay, to avoid any current callbacks + setTimeout(function() { + if(config.timeout) + clearTimeout(config.timeout); + config.blocking = false; + process(); + }, 13); +} + +function validTest( name ) { + var i = config.filters.length, + run = false; + + if( !i ) + return true; + + while( i-- ){ + var filter = config.filters[i], + not = filter.charAt(0) == '!'; + if( not ) + filter = filter.slice(1); + if( name.indexOf(filter) != -1 ) + return !not; + if( not ) + run = true; + } + return run; +} + +function runTest() { + config.blocking = false; + var started = +new Date; + config.fixture = document.getElementById('main').innerHTML; + config.ajaxSettings = $.ajaxSettings; + synchronize(function() { + $('

      ').html(['Tests completed in ', + +new Date - started, ' milliseconds.
      ', + '', config.stats.all - config.stats.bad, ' tests of ', config.stats.all, ' passed, ', config.stats.bad,' failed.'] + .join('')) + .appendTo("body"); + $("#banner").addClass(config.stats.bad ? "fail" : "pass"); + QUnit.done( config.stats.bad, config.stats.all ); + }); +} + +var pollution; + +function saveGlobal(){ + pollution = [ ]; + + if( noglobals ) + for( var key in window ) + pollution.push(key); +} +function checkPollution( name ){ + var old = pollution; + saveGlobal(); + + if( pollution.length > old.length ){ + ok( false, "Introduced global variable(s): " + diff(old, pollution).join(", ") ); + config.expected++; + } +} + +function diff( clean, dirty ){ + return $.grep( dirty, function(name){ + return $.inArray( name, clean ) == -1; + }); +} + +function test(name, callback) { + if(config.currentModule) + name = config.currentModule + " module: " + name + ""; + var lifecycle = $.extend({ + setup: function() {}, + teardown: function() {} + }, config.moduleLifecycle); + + if ( !validTest(name) ) + return; + + var testEnvironment = {}; + + synchronize(function() { + config.assertions = []; + config.expected = null; + try { + if( !pollution ) + saveGlobal(); + lifecycle.setup.call(testEnvironment); + } catch(e) { + QUnit.ok( false, "Setup failed on " + name + ": " + e.message ); + } + }); + synchronize(function() { + try { + callback.call(testEnvironment); + } catch(e) { + fail("Test " + name + " died, exception and test follows", e, callback); + QUnit.ok( false, "Died on test #" + (config.assertions.length + 1) + ": " + e.message ); + // else next test will carry the responsibility + saveGlobal(); + } + }); + synchronize(function() { + try { + checkPollution(); + lifecycle.teardown.call(testEnvironment); + } catch(e) { + QUnit.ok( false, "Teardown failed on " + name + ": " + e.message ); + } + }); + synchronize(function() { + try { + reset(); + } catch(e) { + fail("reset() failed, following Test " + name + ", exception and reset fn follows", e, reset); + } + + if(config.expected && config.expected != config.assertions.length) { + QUnit.ok( false, "Expected " + config.expected + " assertions, but " + config.assertions.length + " were run" ); + } + + var good = 0, bad = 0; + var ol = $("

        ").hide(); + config.stats.all += config.assertions.length; + for ( var i = 0; i < config.assertions.length; i++ ) { + var assertion = config.assertions[i]; + $("
      1. ").addClass(assertion.result ? "pass" : "fail").text(assertion.message || "(no message)").appendTo(ol); + assertion.result ? good++ : bad++; + } + config.stats.bad += bad; + + var b = $("").html(name + " (" + bad + ", " + good + ", " + config.assertions.length + ")") + .click(function(){ + $(this).next().toggle(); + }) + .dblclick(function(event) { + var target = $(event.target).filter("strong").clone(); + if ( target.length ) { + target.children().remove(); + location.href = location.href.match(/^(.+?)(\?.*)?$/)[1] + "?" + encodeURIComponent($.trim(target.text())); + } + }); + + $("
      2. ").addClass(bad ? "fail" : "pass").append(b).append(ol).appendTo("#tests"); + + if(bad) { + $("#filter-pass").attr("disabled", null); + $("#filter-missing").attr("disabled", null); + } + }); +} + +function fail(message, exception, callback) { + if( typeof console != "undefined" && console.error && console.warn ) { + console.error(message); + console.error(exception); + console.warn(callback.toString()); + } else if (window.opera && opera.postError) { + opera.postError(message, exception, callback.toString); + } +} + +// call on start of module test to prepend name to all tests +function module(name, lifecycle) { + config.currentModule = name; + config.moduleLifecycle = lifecycle; +} + +/** + * Specify the number of expected assertions to gurantee that failed test (no assertions are run at all) don't slip through. + */ +function expect(asserts) { + config.expected = asserts; +} + +/** + * Resets the test setup. Useful for tests that modify the DOM. + */ +function reset() { + $("#main").html( config.fixture ); + $.event.global = {}; + $.ajaxSettings = $.extend({}, config.ajaxSettings); +} + +/** + * Asserts true. + * @example ok( $("a").size() > 5, "There must be at least 5 anchors" ); + */ +function ok(a, msg) { + QUnit.log(a, msg); + + config.assertions.push({ + result: !!a, + message: msg + }); +} + +/** + * Asserts that two arrays are the same + */ +function isSet(a, b, msg) { + function serialArray( a ) { + var r = []; + + if ( a && a.length ) + for ( var i = 0; i < a.length; i++ ) { + var str = a[i].nodeName; + if ( str ) { + str = str.toLowerCase(); + if ( a[i].id ) + str += "#" + a[i].id; + } else + str = a[i]; + r.push( str ); + } + + return "[ " + r.join(", ") + " ]"; + } + var ret = true; + if ( a && b && a.length != undefined && a.length == b.length ) { + for ( var i = 0; i < a.length; i++ ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + QUnit.ok( ret, !ret ? (msg + " expected: " + serialArray(b) + " result: " + serialArray(a)) : msg ); +} + +/** + * Asserts that two objects are equivalent + */ +function isObj(a, b, msg) { + var ret = true; + + if ( a && b ) { + for ( var i in a ) + if ( a[i] != b[i] ) + ret = false; + + for ( i in b ) + if ( a[i] != b[i] ) + ret = false; + } else + ret = false; + + QUnit.ok( ret, msg ); +} + +/** + * Returns an array of elements with the given IDs, eg. + * @example q("main", "foo", "bar") + * @result [
        , , ] + */ +function q() { + var r = []; + for ( var i = 0; i < arguments.length; i++ ) + r.push( document.getElementById( arguments[i] ) ); + return r; +} + +/** + * Asserts that a select matches the given IDs + * @example t("Check for something", "//[a]", ["foo", "baar"]); + * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' + */ +function t(a,b,c) { + var f = $(b); + var s = ""; + for ( var i = 0; i < f.length; i++ ) + s += (s && ",") + '"' + f[i].id + '"'; + isSet(f, q.apply(q,c), a + " (" + b + ")"); +} + +/** + * Add random number to url to stop IE from caching + * + * @example url("data/test.html") + * @result "data/test.html?10538358428943" + * + * @example url("data/test.php?foo=bar") + * @result "data/test.php?foo=bar&10538358345554" + */ +function url(value) { + return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); +} + +/** + * Checks that the first two arguments are equal, with an optional message. + * Prints out both actual and expected values. + * + * Prefered to ok( actual == expected, message ) + * + * @example equals( $.format("Received {0} bytes.", 2), "Received 2 bytes." ); + * + * @param Object actual + * @param Object expected + * @param String message (optional) + */ +function equals(actual, expected, message) { + push(expected == actual, actual, expected, message); +} + +function push(result, actual, expected, message) { + message = message || (result ? "okay" : "failed"); + QUnit.ok( result, result ? message + ": " + expected : message + ", expected: " + jsDump.parse(expected) + " result: " + jsDump.parse(actual) ); +} + +/** + * Trigger an event on an element. + * + * @example triggerEvent( document.body, "click" ); + * + * @param DOMElement elem + * @param String type + */ +function triggerEvent( elem, type, event ) { + if ( $.browser.mozilla || $.browser.opera ) { + event = document.createEvent("MouseEvents"); + event.initMouseEvent(type, true, true, elem.ownerDocument.defaultView, + 0, 0, 0, 0, 0, false, false, false, false, 0, null); + elem.dispatchEvent( event ); + } else if ( $.browser.msie ) { + elem.fireEvent("on"+type); + } +} + +})(jQuery); + +/** + * jsDump + * Copyright (c) 2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com + * Licensed under BSD (http://www.opensource.org/licenses/bsd-license.php) + * Date: 5/15/2008 + * @projectDescription Advanced and extensible data dumping for Javascript. + * @version 1.0.0 + * @author Ariel Flesler + * @link {http://flesler.blogspot.com/2008/05/jsdump-pretty-dump-of-any-javascript.html} + */ +(function(){ + function quote( str ){ + return '"' + str.toString().replace(/"/g, '\\"') + '"'; + }; + function literal( o ){ + return o + ''; + }; + function join( pre, arr, post ){ + var s = jsDump.separator(), + base = jsDump.indent(), + inner = jsDump.indent(1); + if( arr.join ) + arr = arr.join( ',' + s + inner ); + if( !arr ) + return pre + post; + return [ pre, inner + arr, base + post ].join(s); + }; + function array( arr ){ + var i = arr.length, ret = Array(i); + this.up(); + while( i-- ) + ret[i] = this.parse( arr[i] ); + this.down(); + return join( '[', ret, ']' ); + }; + + var reName = /^function (\w+)/; + + var jsDump = window.jsDump = { + parse:function( obj, type ){//type is used mostly internally, you can fix a (custom)type in advance + var parser = this.parsers[ type || this.typeOf(obj) ]; + type = typeof parser; + + return type == 'function' ? parser.call( this, obj ) : + type == 'string' ? parser : + this.parsers.error; + }, + typeOf:function( obj ){ + var type = typeof obj, + f = 'function';//we'll use it 3 times, save it + return type != 'object' && type != f ? type : + !obj ? 'null' : + obj.exec ? 'regexp' :// some browsers (FF) consider regexps functions + obj.getHours ? 'date' : + obj.scrollBy ? 'window' : + obj.nodeName == '#document' ? 'document' : + obj.nodeName ? 'node' : + obj.item ? 'nodelist' : // Safari reports nodelists as functions + obj.callee ? 'arguments' : + obj.call || obj.constructor != Array && //an array would also fall on this hack + (obj+'').indexOf(f) != -1 ? f : //IE reports functions like alert, as objects + 'length' in obj ? 'array' : + type; + }, + separator:function(){ + return this.multiline ? this.HTML ? '
        ' : '\n' : this.HTML ? ' ' : ' '; + }, + indent:function( extra ){// extra can be a number, shortcut for increasing-calling-decreasing + if( !this.multiline ) + return ''; + var chr = this.indentChar; + if( this.HTML ) + chr = chr.replace(/\t/g,' ').replace(/ /g,' '); + return Array( this._depth_ + (extra||0) ).join(chr); + }, + up:function( a ){ + this._depth_ += a || 1; + }, + down:function( a ){ + this._depth_ -= a || 1; + }, + setParser:function( name, parser ){ + this.parsers[name] = parser; + }, + // The next 3 are exposed so you can use them + quote:quote, + literal:literal, + join:join, + // + _depth_: 1, + // This is the list of parsers, to modify them, use jsDump.setParser + parsers:{ + window: '[Window]', + document: '[Document]', + error:'[ERROR]', //when no parser is found, shouldn't happen + unknown: '[Unknown]', + 'null':'null', + undefined:'undefined', + 'function':function( fn ){ + var ret = 'function', + name = 'name' in fn ? fn.name : (reName.exec(fn)||[])[1];//functions never have name in IE + if( name ) + ret += ' ' + name; + ret += '('; + + ret = [ ret, this.parse( fn, 'functionArgs' ), '){'].join(''); + return join( ret, this.parse(fn,'functionCode'), '}' ); + }, + array: array, + nodelist: array, + arguments: array, + object:function( map ){ + var ret = [ ]; + this.up(); + for( var key in map ) + ret.push( this.parse(key,'key') + ': ' + this.parse(map[key]) ); + this.down(); + return join( '{', ret, '}' ); + }, + node:function( node ){ + var open = this.HTML ? '<' : '<', + close = this.HTML ? '>' : '>'; + + var tag = node.nodeName.toLowerCase(), + ret = open + tag; + + for( var a in this.DOMAttrs ){ + var val = node[this.DOMAttrs[a]]; + if( val ) + ret += ' ' + a + '=' + this.parse( val, 'attribute' ); + } + return ret + close + open + '/' + tag + close; + }, + functionArgs:function( fn ){//function calls it internally, it's the arguments part of the function + var l = fn.length; + if( !l ) return ''; + + var args = Array(l); + while( l-- ) + args[l] = String.fromCharCode(97+l);//97 is 'a' + return ' ' + args.join(', ') + ' '; + }, + key:quote, //object calls it internally, the key part of an item in a map + functionCode:'[code]', //function calls it internally, it's the content of the function + attribute:quote, //node calls it internally, it's an html attribute value + string:quote, + date:quote, + regexp:literal, //regex + number:literal, + 'boolean':literal + }, + DOMAttrs:{//attributes to dump from nodes, name=>realName + id:'id', + name:'name', + 'class':'className' + }, + HTML:false,//if true, entities are escaped ( <, >, \t, space and \n ) + indentChar:' ',//indentation unit + multiline:true //if true, items in a collection, are separated by a \n, else just a space. + }; + +})(); diff --git a/lib/qunit/testsuite.css b/lib/qunit/testsuite.css new file mode 100755 index 0000000..dbfc43a --- /dev/null +++ b/lib/qunit/testsuite.css @@ -0,0 +1,120 @@ +body, div, h1 { font-family: 'trebuchet ms', verdana, arial; margin: 0; padding: 0 } +body {font-size: 10pt; } +h1 { padding: 15px; font-size: large; background-color: #06b; color: white; } +h1 a { color: white; } +h2 { padding: 10px; background-color: #eee; color: black; margin: 0; font-size: small; font-weight: normal } + +.pass { color: green; } +.fail { color: red; } +p.result { margin-left: 1em; } + +#banner { height: 2em; border-bottom: 1px solid white; } +h2.pass { background-color: green; } +h2.fail { background-color: red; } + +div.testrunner-toolbar { background: #eee; border-top: 1px solid black; padding: 10px; } + +ol#tests > li > strong { cursor:pointer; } + +div#fx-tests h4 { + background: red; +} + +div#fx-tests h4.pass { + background: green; +} + +div#fx-tests div.box { + background: red url(data/cow.jpg) no-repeat; + overflow: hidden; + border: 2px solid #000; +} + +div#fx-tests div.overflow { + overflow: visible; +} + +div.inline { + display: inline; +} + +div.autoheight { + height: auto; +} + +div.autowidth { + width: auto; +} + +div.autoopacity { + opacity: auto; +} + +div.largewidth { + width: 100px; +} + +div.largeheight { + height: 100px; +} + +div.largeopacity { + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); +} + +div.medwidth { + width: 50px; +} + +div.medheight { + height: 50px; +} + +div.medopacity { + opacity: 0.5; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); +} + +div.nowidth { + width: 0px; +} + +div.noheight { + height: 0px; +} + +div.noopacity { + opacity: 0; + filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); +} + +div.hidden { + display: none; +} + +div#fx-tests div.widewidth { + background-repeat: repeat-x; +} + +div#fx-tests div.wideheight { + background-repeat: repeat-y; +} + +div#fx-tests div.widewidth.wideheight { + background-repeat: repeat; +} + +div#fx-tests div.noback { + background-image: none; +} + +div.chain, div.chain div { width: 100px; height: 20px; position: relative; float: left; } +div.chain div { position: absolute; top: 0px; left: 0px; } + +div.chain.test { background: red; } +div.chain.test div { background: green; } + +div.chain.out { background: green; } +div.chain.out div { background: red; display: none; } + +div#show-tests * { display: none; } diff --git a/spec/pavlov.specs.html b/spec/pavlov.specs.html new file mode 100755 index 0000000..4915689 --- /dev/null +++ b/spec/pavlov.specs.html @@ -0,0 +1,19 @@ + + + + + + + + + + + + +

        + +

        +
          +
          + + \ No newline at end of file diff --git a/spec/pavlov.specs.js b/spec/pavlov.specs.js new file mode 100755 index 0000000..8c18caa --- /dev/null +++ b/spec/pavlov.specs.js @@ -0,0 +1,670 @@ +var standardQUnitTestRan = false; + +module("standard QUnit module"); + +test("standard QUnit Test should still run alongside QUnit.specify", function() { + expect(1); + standardQUnitTestRan = true; + ok(standardQUnitTestRan); +}); + + +QUnit.specify("Pavlov", function() { + + describe("a QUnit.specify()", function() { + it("should set the page title to the spec name", function() { + // temporarily mock the jQuery.fn.html() + // to track that it was called and with what arg + var originalHtmlMethod = $.fn.html; + var htmlArg = null; + try { + $.fn.html = function(text) { + htmlArg = text; + }; + QUnit.specify("Pavlov", function(){}); + } finally{ + $.fn.html = originalHtmlMethod; + } + assert(htmlArg).isEqualTo("Pavlov"); + }); + + it("should set the document title to spec name + ' Specifications'", function() { + // temporarily mock jQuery.fn.attr to track + // the usage of it + var originalAttr = $.fn.attr; + try{ + var passedName = null; + var passedVal = null; + $.fn.attr = function(name, val) { + passedName = name; + passedVal = val; + }; + QUnit.specify("Pavlov", function(){}); + } finally { + $.fn.attr = originalAttr; + } + assert(passedName).isEqualTo("title"); + assert(passedVal).isEqualTo("Pavlov Specifications"); + }); + + it("should run the spec lambda", function() { + // implicitly true by virtue of having executed + assert.pass(); + }); + + it("should run the resulting flattened qunit tests", function() { + // implicitly true by virtue of having executed + assert.pass(); + }); + + it("should not pollute the global namespace", function() { + $.each("describe,it,wait,assert,before,after,given".split(','), function() { + assert(window[String(this)]).isUndefined(); + }); + }); + + it("should be able to run alongside standard QUnit modules and tests", function() { + assert(standardQUnitTestRan).isTrue(); + }); + }); + + describe("a describe()", function() { + var variableDefinedInDescribe = "y"; + var beforeCalls = []; + var afterCalls = []; + + var beforeCallCount = 0; + before(function() { + beforeCallCount++; + beforeCalls.push('x'); + }); + + var afterCallCount = 0; + after(function() { + afterCallCount++; + afterCalls.push('y'); + }); + + it("should execute lambda", function() { + // implicitly true by virtue of this running + assert.pass(); + }); + + it("should execute before() before each it()", function() { + assert(beforeCallCount).equals(2); + assert(afterCallCount).equals(1); + }); + + it("should execute after() after each it()", function() { + assert(beforeCallCount).equals(3); + assert(afterCallCount).equals(2); + }); + + describe("with a nested describe()", function() { + var variableDefinedInNestedDescribe = "x"; + + before(function() { + beforeCalls.push('a'); + }); + + after(function() { + afterCalls.push('b'); + }); + + it("should execute all before()s from outside-in", function() { + assert(beforeCalls).isSameAs(['x', 'x', 'x', 'x', 'x', 'a']); + assert(afterCalls).isSameAs(['y', 'y', 'y', 'y']); + }); + + it("should execute all after()s from inside-out", function() { + assert(beforeCalls).isSameAs(['x', 'x', 'x', 'x', 'x', 'a', 'x', 'a']); + assert(afterCalls).isSameAs(['y', 'y', 'y', 'y', 'b', 'y']); + }); + + it("should have access to own describe scope", function() { + assert(variableDefinedInNestedDescribe).isDefined(); + }); + + it("should have access to parent describe scope", function() { + assert(variableDefinedInDescribe).isDefined(); + }); + }); + + it("should have access to describe scope", function() { + assert(variableDefinedInDescribe).isDefined(); + }); + }); + + describe("an it()", function() { + it("should generate and run a test", function() { + ok(true); // implicitly true by virtue of this running + }); + + describe("when not passed a test lambda", function(){ + + it("should generate a failing (todo) test when not passed a lambda", function(){ + var originalIt = it; + var args; + try{ + // mock up an it + // when passed single arg, let Pavlov do it's job (to test it) + // when passed 2 args, intercept and capture the response to + // keep Pavlov from doing its job + // later, will verify the correct behavior happened with 1 arg. + it = function() { + if(arguments.length == 2) { + args = $.makeArray(arguments); + } else { + originalIt.apply(this,arguments); + } + }; + + // run the method under test + it("no lambda"); + + var todoGeneratingFn = args[1]; + + var originalFail = assert.fail; + var failMessage = null; + try + { + assert.fail = function(message) { + failMessage = message; + }; + todoGeneratingFn(); + } finally { + assert.fail = originalFail; + } + + } finally { + it = originalIt; + } + assert(args[0]).equals("no lambda"); + assert(args.length).equals(2); + assert(failMessage).equals("Not Implemented"); + }); + + }); + + describe("after a given()", function() { + + var singleArgGivenCount = 0; + + given(1, 2, 3). + it("should test for each of given()'s args when passed flat args", function(x) { + assert(x).equals(singleArgGivenCount + 1); + singleArgGivenCount++; + }); + + var multiArgGivenCount = 0; + + given([1, 2, 3], [4, 5, 6], [7, 8, 9]). + it("should test for each of given()'s args when passed array arguments", function(x, y, z) { + assert(x).equals(multiArgGivenCount * 3 + 1, "some message"); + assert(y).equals(multiArgGivenCount * 3 + 2); + assert(z).equals(multiArgGivenCount * 3 + 3); + multiArgGivenCount++; + }); + }); + + describe("with a wait()", function() { + + it("should stop(), run a setTimeout() for duration, then execute lambda and start()", function() { + var original = { + stop: stop, + start: start, + setTimeout: setTimeout + }; + var calls = []; + var setTimeoutMs = 0; + var waitLambdaCalled = false; + + try{ + // mock timing functions to capture their calls from wait() + stop = function() { calls.push('stop'); }; + start = function() { calls.push('start'); }; + setTimeout = function(fn, ms) { + calls.push('settimeout'); + setTimeoutMs = ms; + fn(); + }; + + // call wait + wait(40, function(){ + calls.push('waitlambda'); + }); + + } finally { + // undo mocking + stop = original.stop; + start = original.start; + setTimeout = original.setTimeout; + } + + // check if calls to mocked fn's occurred correctly + assert(calls).isSameAs(['stop','settimeout','waitlambda','start']); + assert(setTimeoutMs).equals(40); + }); + + }); + }); + + + + describe("assertions", function() { + + /* quick and dirty mocking of native qunit functions + * temporarily replaces a method in window namespace with one + * that just gathers and returns the values of passed arguments + * undoes mocking after scope completes + */ + var mockQunitAssertion = function(method, scope){ + var originalMethod = window[method]; + var args = []; + try { + window[method] = function(){ + args = $.makeArray(arguments); + }; + scope(); + } finally { + window[method] = originalMethod; + } + return args; + }; + + describe("equals()", function() { + + it("should pass arguments to qunit's equals()", function() { + var passedArgs = mockQunitAssertion('equals', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(4).equals(2, "some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([4,2,"some message"]); + }); + + }); + + describe("isEqualTo()", function() { + + it("should pass arguments to qunit's equals()", function() { + var passedArgs = mockQunitAssertion('equals', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(4).isEqualTo(2, "some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([4,2,"some message"]); + }); + + }); + + describe("isNotEqualTo()", function(){ + + it("should pass true to qunit's ok() when actual !== expected", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(4).isNotEqualTo(2, "some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"some message"]); + }); + + it("should pass false to qunit's ok() when actual === expected", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(2).isNotEqualTo(2, "some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"some message"]); + }); + + }); + + describe("isSameAs()", function() { + + it("should pass arguments to qunit's same()", function() { + var passedArgs = mockQunitAssertion('same', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(4).isSameAs(2, "some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([4,2,"some message"]); + }); + + }); + + describe("isNotSameAs()", function(){ + + var originalEquiv; + var equivActual; + var equivExpected; + + + before(function(){ + originalEquiv = QUnit.equiv; + equivActual = null; + equivExpected = null; + }); + + it("should pass true when !QUnit.equiv of arguments is true to qunit's ok()", function() { + try { + QUnit.equiv = function(actual, expected) { + equivActual = actual; + equivExpected = expected; + return false; + }; + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(4).isNotSameAs(2, "some message"); + }); + } finally { + QUnit.equiv = originalEquiv; + } + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"some message"]); + assert(equivActual).equals(4); + assert(equivExpected).equals(2); + }); + + it("should pass false when !QUnit.equiv of arguments is false to qunit's ok()", function() { + try { + QUnit.equiv = function(actual, expected) { + equivActual = actual; + equivExpected = expected; + return true; + }; + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(4).isNotSameAs(2, "some message"); + }); + } finally { + QUnit.equiv = originalEquiv; + } + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"some message"]); + assert(equivActual).equals(4); + assert(equivExpected).equals(2); + }); + + }); + + describe("isTrue()", function() { + + it("should pass argument to qunit's ok()", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(true).isTrue("some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"some message"]); + }); + + }); + + describe("isFalse()", function(){ + + it("should pass true to qunit's ok() when expr is false", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(false).isFalse("some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"some message"]); + }); + + it("should pass false to qunit's ok() when expr is true", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(true).isFalse("some message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"some message"]); + }); + }); + + describe("isNull()", function() { + + it("should pass true to qunit' ok when actual === null", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(null).isNull("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + }); + + it("should pass false to qunit' ok when actual !== null", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(0).isNull("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + }); + + }); + + describe("isNotNull()", function(){ + + it("should pass true to qunit's ok when actual !== null", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(0).isNotNull("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + }); + + it("should pass false to qunit's ok when actual === null", function() { + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(null).isNotNull("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + }); + + }); + + describe("isDefined()", function() { + + it("should pass true to qunit's ok when typeof(argument) !== 'undefined'", function() { + var x = "something"; + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(x).isDefined("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + }); + + it("should pass false to qunit's ok when typeof(argument) === 'undefined'", function() { + var x; + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(x).isDefined("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + }); + + }); + + describe("isUndefined()", function(){ + + it("should pass true to qunit()'s ok when typeof(argument) === 'undefined'", function() { + var x; + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(x).isUndefined("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + }); + + it("should pass false to qunit()'s ok when typeof(argument) !== 'undefined'", function() { + var x = 1; + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(x).isUndefined("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + }); + + }); + + + describe("pass()", function(){ + + it("should pass true to qunit's ok()", function(){ + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert().pass("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + }); + + it("should also be called from assert.pass()", function(){ + + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert.pass("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + + }); + + }); + + describe("fail()", function(){ + + it("should pass false to qunit's ok()", function(){ + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert().fail("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + }); + + it("should also be called from assert.false()", function(){ + + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert.fail("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + + }); + + }); + + describe("throwsException()", function(){ + + it("should pass true to qunit's ok() when function throws exception", function(){ + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(function(){ + // should throw undefined exceptions + var totalPrice = unitPrice * quantity; + }).throwsException("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([true,"message"]); + }); + + it("should pass false to qunit's ok() when function does not throw exception", function(){ + var passedArgs = mockQunitAssertion('ok', function(){ + // run spec assertion while underlying qunit assertion is mocked + assert(function(){ + var unitPrice = 10; + var quantity = 4; + var totalPrice = unitPrice * quantity; + }).throwsException("message"); + }); + + // verify correct arguments would have been passed to qunit + assert(passedArgs).isSameAs([false,"message"]); + }); + + }); + + describe("custom assertions", function(){ + + it("should be able to be added via QUnit.specify.extendAssertions with 3 arg asserts", function(){ + var gtArgs, ltArgs; + QUnit.specify.extendAssertions({ + isGreaterThan: function(actual, expected, message) { + gtArgs = $.makeArray(arguments); + }, + isLessThan: function(actual, expected, message) { + ltArgs = $.makeArray(arguments); + } + }); + + assert(4).isGreaterThan(2,"some message"); + assert(2).isLessThan(4,"some message"); + + assert(gtArgs).isSameAs([4,2,"some message"]); + assert(ltArgs).isSameAs([2,4,"some message"]); + }); + + it("should be able to be added via QUnit.specify.extendAssertions with 2 arg asserts", function(){ + var purpleArgs, yellowArgs; + QUnit.specify.extendAssertions({ + isPurple: function(actual, message) { + purpleArgs = $.makeArray(arguments); + }, + isYellow: function(actual, message) { + yellowArgs = $.makeArray(arguments); + } + }); + + assert(4).isPurple("some message"); + assert(2).isYellow("some message"); + + assert(purpleArgs).isSameAs([4,"some message"]); + assert(yellowArgs).isSameAs([2,"some message"]); + }); + + }); + }); +}); + +var secondStandardQUnitTest = false; + +module("second standard QUnit module"); + +test("second standard QUnit Test should still run alongside Pavlov", function() { + expect(1); + secondStandardQUnitTest = true; + ok(secondStandardQUnitTest); +}); + diff --git a/src/header.js b/src/header.js new file mode 100755 index 0000000..fa7c40a --- /dev/null +++ b/src/header.js @@ -0,0 +1,10 @@ +/** + * Pavlov - Behavioral API over QUnit + * + * http://michaelmonteleone.net/projects/pavlov + * http://github.com/mmonteleone/pavlov + * + * Copyright (c) 2009 Michael Monteleone + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + */ \ No newline at end of file diff --git a/src/pavlov.js b/src/pavlov.js new file mode 100755 index 0000000..4eb3b3d --- /dev/null +++ b/src/pavlov.js @@ -0,0 +1,463 @@ +/** + * Pavlov - Behavioral API over QUnit + * + * http://michaelmonteleone.net/projects/pavlov + * http://github.com/mmonteleone/pavlov + * + * Copyright (c) 2009 Michael Monteleone + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + */ +(function($){ + // capture reference to global scope + var globalScope = this; + + // ==================== + // = Example Building = + // ==================== + + var examples = []; + var currentExample; + + /** + * Example Class + * Represents an instance of an example (a describe) + * contains references to parent and nested examples + * exposes methods for returning combined lists of before, after, and names + * @constructor + * @param {example} parent example to append self as child to (optional) + */ + function example(parent) { + // private + + if(parent) { + // if there's a parent, append self as nested example + parent.children.push(this); + } else { + // otherwise, add this as a new root example + examples.push(this); + } + + var thisExample = this; + + /** + * Rolls up list of current and ancestors values for given prop name + * @param {String} prop Name of property to roll up + * @returns array of values corresponding to prop name + */ + var rollup = function(prop) { + var items = []; + var node = thisExample; + while(node !== null) { + items.push(node[prop]); + node = node.parent; + } + return items; + }; + + // public + + // parent example + this.parent = parent ? parent : null; + // nested examples + this.children = []; + // name of this description + this.name = ''; + // function to happen before all contained specs + this.before = function() {}; + // function to happen after all contained specs + this.after = function() {}; + // array of it() tests + this.specs = []; + + /** + * rolls up this and ancestor's before functions + * @returns arrayt of functions + */ + this.befores = function(){ + return rollup('before').reverse(); + }; + /** + * Rolls up this and ancestor's after functions + * @returns array of functions + */ + this.afters = function(){ + return rollup('after'); + }; + /** + * Rolls up this and ancestor's description names, joined + * @returns string of joined description names + */ + this.names = function(){ + return rollup('name').reverse().join(', '); + }; + } + + + + // ============== + // = Assertions = + // ============== + + /** + * Collection of default-bundled assertion implementations + */ + var assertions = { + equals: function(actual, expected, message) { + equals(actual, expected, message); + }, + isEqualTo: function(actual, expected, message) { + equals(actual, expected, message); + }, + isNotEqualTo: function(actual, expected, message) { + ok(actual !== expected, message); + }, + isSameAs: function(actual, expected, message) { + same(actual, expected, message); + }, + isNotSameAs: function(actual, expected, message) { + ok(!QUnit.equiv(actual, expected), message); + }, + isTrue: function(actual, message) { + ok(actual, message); + }, + isFalse: function(actual, message) { + ok(!actual, message); + }, + isNull: function(actual, message) { + ok(actual === null, message); + }, + isNotNull: function(actual, message) { + ok(actual !== null, message); + }, + isDefined: function(actual, message) { + ok(typeof(actual) !== 'undefined', message); + }, + isUndefined: function(actual, message) { + ok(typeof(actual) === 'undefined', message); + }, + pass: function(actual, message) { + ok(true, message); + }, + fail: function(actual, message) { + ok(!true, message); + }, + throwsException: function(actual, message) { + try{ + actual(); + ok(!true, message); + } catch(e) { + ok(true, message); + } + } + }; + + /** + * AssertionHandler + * represents instance of an assertion regarding a particular + * actual value, and provides an api around asserting that value + * against any of the bundled assertion handlers and custom ones. + * @constructor + * @param {Object} value A test-produced value to assert against + */ + var assertHandler = function(value) { + this.value = value; + }; + /** + * Appends assertion methods to the assertHandler prototype + * For each provided assertion implementation, adds an identically named + * assertion function to assertionHandler prototype which can run impl + * @param {Object} asserts Object containing assertion implementations + */ + var addAssertions = function(asserts) { + $.each(asserts, function(name, fn){ + assertHandler.prototype[name] = function() { + // implement this handler against backend + // by pre-pending assertHandler's current value to args + var args = $.makeArray(arguments); + args.unshift(this.value); + fn.apply(this, args); + }; + }); + }; + // pre-add all the default bundled assertions + addAssertions(assertions); + + + + // ===================== + // = Pavlov Public API = + // ===================== + + + /** + * Object containing methods to be made available as public API + */ + var api = { + /** + * Initiates a new Example context + * @param {String} description Name of what's being "described" + * @param {Function} fn Function containing description (before, after, specs, nested examples) + */ + describe: function(description, fn) { + // capture reference to current example before construction + var originalExample = currentExample; + try{ + // create new current example for construction + currentExample = new example(currentExample); + currentExample.name = description; + fn(); + } finally { + // restore original reference after construction + currentExample = originalExample; + } + }, + + /** + * Sets a function to occur before all contained specs and nested examples' specs + * @param {Function} fn Function to be executed + */ + before: function(fn) { + currentExample.before = fn; + }, + + /** + * Sets a function to occur after all contained tests and nested examples' tests + * @param {Function} fn Function to be executed + */ + after: function(fn) { + currentExample.after = fn; + }, + + /** + * Creates a spec (test) to occur within an example + * When not passed fn, creates a spec-stubbing fn which asserts fail "Not Implemented" + * @param {String} specification Description of what "it" "should do" + * @param {Function} fn Function containing a test to assert that it does indeed do it (optional) + */ + it: function(specification, fn) { + thisApi = this; + if(fn) { + currentExample.specs.push([specification, fn]); + } else { + // if not passed an implementation, create an implementation that simply asserts fail + thisApi.it(specification, function(){thisApi.assert.fail('Not Implemented');}); + } + }, + + /** + * Generates a row spec for each argument passed, applying + * each argument to a new call against the spec + * @returns an object with an it() function for defining + * function to be called for each of given's arguments + * @param {Array} arguments either list of values or list of arrays of values + */ + given: function() { + var args = arguments; + var thisIt = this.it; + + return { + /** + * Defines a row spec (test) which is applied against each + * of the given's arguments. + */ + it: function(specification, fn) { + $.each(args, function(){ + var arg = this; + thisIt("given " + arg + ", " + specification, function(){ + fn.apply(this, $.isArray(arg) ? arg : [arg]); + }); + }); + } + }; + }, + + /** + * Assert a value against any of the bundled or custom assertions + * @param {Object} value A value to be asserted + * @returns an assertHandler instance to fluently perform an assertion with + */ + assert: function(value) { + return new assertHandler(value); + }, + + /** + * specifies test runner to synchronously wait + * @param {Number} ms Milliseconds to wait + * @param {Function} fn Function to execute after ms has + * passed before resuming + */ + wait: function(ms, fn) { + stop(); + QUnit.specify.globalObject.setTimeout(function(){ + fn(); + start(); + }, ms); + } + }; + + // extend api's assert function for easier syntax for blank pass and fail + $.extend(api.assert, { + /** + * Shortcuts assert().pass() with assert.pass() + * @param {String} message Assertion message (optional) + */ + pass: function(message){ + (new assertHandler()).pass(message); + }, + /** + * Shortcuts assert().fail() with assert.fail() + * @param {String} message Assertion message (optional) + */ + fail: function(message){ + (new assertHandler()).fail(message); + } + }); + + /** + * Extends a function's scope + * applies the extra scope to the function returns un-run new version of fn + * inspired by Yehuda Katz's metaprogramming Screw.Unit + * different in that new function can still accept all parameters original function could + * @param {Function} fn Target function for extending + * @param {Object} thisArg Object for the function's "this" to refer + * @param {Object} extraScope object whose members will be added to fn's scope + * @returns Modified version of original function with extra scope. Can still + * accept parameters of original function + */ + var extendScope = function(fn, thisArg, extraScope) { + + // get a string of the fn's parameters + var params = fn.toString().match(/\(([^\)]*)\)/)[1]; + // get a string of fn's body + var source = fn.toString().match(/^[^\{]*\{((.*\n*)*)\}/m)[1]; + + // create a new function with same parameters and + // body wrapped in a with(extraScope){ } + fn = new Function( + "extraScope" + (params ? ", " + params : ""), + "with(extraScope){" + source + "}"); + + // returns a fn wrapper which takes passed args, + // pre-pends extraScope arg, and applies to modified fn + return function(){ + var args = [extraScope]; + $.each(arguments,function(){ + args.push(this); + }); + fn.apply(thisArg, args); + }; + }; + + /** + * Top-level Specify method. Declares a new QUnit.specify context + * @param {String} name Name of what's being specified + * @param {Function} fn Function containing exmaples and specs + */ + var specify = function(name, fn) { + examples = []; + currentExample = null; + + // set the test suite title + $(function(){ + $('h1').html(name); + $(document).attr('title', name + " Specifications"); + }); + + if(QUnit.specify.globalApi) { + // if set to extend global api, + // extend global api and run example builder + $.extend(globalScope, api); + fn(); + } else { + // otherwise, extend example builder's scope with api + // and run example builder + extendScope(fn, this, api)(); + } + + // compile examples into flat qunit statements + var qunitStatements = compile(examples); + + // run qunit tests + $.each(qunitStatements, function(){ this(); }); + }; + + + + + // ========================================== + // = Example-to-QUnit Statement Compilation = + // ========================================== + + /** + * Compiles nested set of examples into flat array of QUnit statements + * @param {Array} examples Array of possibly nested Example instances + * @returns array of QUnit statements each wrapped in an anonymous fn + */ + var compile = function(examples) { + var statements = []; + + /** + * Comples a single example and its children into QUnit statements + * @param {Example} example Single example instance + * possibly with nested instances + */ + var compileDescription = function(example) { + + // get before and after rollups + var befores = example.befores(); + var afters = example.afters(); + + // create a module with setup and teardown + // that executes all current befores/afters + statements.push(function(){ + module(example.names(), { + setup: function(){ + $.each(befores, function(){ this(); }); + }, + teardown: function(){ + $.each(afters, function(){ this(); }); + } + }); + }); + + // create a test for each spec/"it" in the example + $.each(example.specs, function(){ + var spec = this; + statements.push(function(){ + test(spec[0],spec[1]); + }); + }); + + // recurse through example's nested examples + $.each(example.children, function() { + compileDescription(this); + }); + }; + + + // compile all root examples + $.each(examples, function() { + compileDescription(this, statements); + }); + + return statements; + }; + + + + // ===================== + // = Expose Public API = + // ===================== + + // extend QUnit + QUnit.specify = specify; + // add global settings onto QUnit.specify + $.extend(specify, { + globalApi: false, // when true, adds api to global scope + extendAssertions: addAssertions, // function for adding custom assertions + globalObject: window // injectable global containing setTimeout and pals + }); + +})(jQuery); +