@@ -701,7 +701,7 @@ Replaced "Off for All Web Pages" with "Clear Activation List"
- Register or Log in to add tags
+ Register or Log in to add tags
@@ -730,7 +730,7 @@ Replaced "Off for All Web Pages" with "Clear Activation List"
-
+
Related Collections
@@ -824,7 +824,7 @@ Replaced "Off for All Web Pages" with "Clear Activation List"
diff --git a/README b/README
index 2eb7f18..537f319 100644
--- a/README
+++ b/README
@@ -1,18 +1,18 @@
=============================
-Test Driving JavaScript Book
+Test Driving JavaScript Book
=============================
-
-This is the source code and actual book in open office formate (.odt), Test Driving JavaScript (aka TD JavaScript). It is licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license. http://creativecommons.org/licenses/by-sa/3.0/us/
-
+
+This is the source code and actual book in open office formate (.odt), Test Driving JavaScript (aka TD JavaScript). It is licensed under the Creative Commons Attribution-Non Commercial-Share Alike 3.0 license. http://creativecommons.org/licenses/by-sa/3.0/us/
+
Contributors
=====================
I am interested in contributors that may have relevant experience, information, that I am not already supplying. For example, here are some possible topics/chapters that would probably improve the book:
- IE specific debugging via the IE8 JavaScript debugger would be a great addition.
- Integration with a continuous integration system.
-Note that the goal of the book is to be short and sweet so contributions will need to be to the point. Given that the main document is currently using Open Office, I'd ask that contributions come in that form. I still need to research merging a .odt document, so I'm still unsure of how to go about patches/contributions (in that regard). Please email me if you're serious about contributing.
+Note that the goal of the book is to be short and sweet so contributions will need to be to the point. Given that the main document is currently using Open Office, I'd ask that contributions come in that form. I still need to research merging a .odt document, so I'm still unsure of how to go about patches/contributions (in that regard). Please email me if you're serious about contributing.
Errata
=====================
If you find any technical mistakes and/or parts of the book that are in need of correction,
-please email me at roblevintennis at gmail dot com to inform me.
+please email me at roblevintennis at gmail dot com to inform me.
diff --git a/TDD JavaScript.odt b/TDD JavaScript.odt
index 38c746f..50f7798 100644
Binary files a/TDD JavaScript.odt and b/TDD JavaScript.odt differ
diff --git a/code/5_min_drill/README.rdoc b/code/5_min_drill/README.rdoc
index 2cd053a..4a4f290 100644
--- a/code/5_min_drill/README.rdoc
+++ b/code/5_min_drill/README.rdoc
@@ -3,7 +3,7 @@
Description
-== License
+== License
(The MIT License)
diff --git a/code/5_min_drill/lib/test_js_itself.js b/code/5_min_drill/lib/test_js_itself.js
index 0752103..508ab70 100644
--- a/code/5_min_drill/lib/test_js_itself.js
+++ b/code/5_min_drill/lib/test_js_itself.js
@@ -3,12 +3,12 @@ JSTest.prototype = {
constructor: JSTest,
switchTest : function(c) {
switch(c) {
- case 0:
+ case 0:
return "zero";
break;
case 1:
return "one";
- break;
+ break;
case "no break case":
// do nothing...testing fall through
case "next case":
diff --git a/code/5_min_drill/spec/spec.test_js_itself.js b/code/5_min_drill/spec/spec.test_js_itself.js
index 0f78167..d110501 100644
--- a/code/5_min_drill/spec/spec.test_js_itself.js
+++ b/code/5_min_drill/spec/spec.test_js_itself.js
@@ -1,11 +1,11 @@
describe 'TestJsItself'
- before_each
- jsTest = new JSTest
+ before_each
+ jsTest = new JSTest
arr = jsTest.arrayTest()
- end
+ end
describe '.switchTest()'
it 'should return corresponding case primitive int as a string'
- jsTest.switchTest(1).should.eql "one"
+ jsTest.switchTest(1).should.eql "one"
end
it 'should fall through to next case when omitting a break'
jsTest.switchTest("no break case").should.eql "next case"
@@ -16,7 +16,7 @@ describe 'TestJsItself'
(typeof arr == 'object').should.eql true
end
it 'should use zero based indexing'
- arr[1].should.eql 2
+ arr[1].should.eql 2
end
end
end
diff --git a/code/binary_tree/bin_tree/README.rdoc b/code/binary_tree/bin_tree/README.rdoc
index 2cd053a..4a4f290 100644
--- a/code/binary_tree/bin_tree/README.rdoc
+++ b/code/binary_tree/bin_tree/README.rdoc
@@ -3,7 +3,7 @@
Description
-== License
+== License
(The MIT License)
diff --git a/code/binary_tree/bin_tree/lib/yourlib.core.js b/code/binary_tree/bin_tree/lib/yourlib.core.js
index ac3ea3c..2ece2ec 100644
--- a/code/binary_tree/bin_tree/lib/yourlib.core.js
+++ b/code/binary_tree/bin_tree/lib/yourlib.core.js
@@ -10,7 +10,7 @@ function BSTree(n) {
this.root = n;
};
BSTree.prototype = {
- // Essentially have to go past node it should be connected to
+ // Essentially have to go past node it should be connected to
// looking for undefined, so we always need pointer to parent node
addNode: function(node) {
var current = this.root;
@@ -45,10 +45,10 @@ BSTree.prototype = {
}
}
}
- return null;
+ return null;
},
// Builds an "in order" array of the list's nodes (eg [1,2,3,4...])
- traverseInOrder: function(inOrdArray, cNode) {
+ traverseInOrder: function(inOrdArray, cNode) {
if(cNode !== undefined) {
this.traverseInOrder(inOrdArray, cNode.left);
inOrdArray.push(cNode);
diff --git a/code/binary_tree/bin_tree/spec/spec.core.js b/code/binary_tree/bin_tree/spec/spec.core.js
index 2569634..b2bffdd 100644
--- a/code/binary_tree/bin_tree/spec/spec.core.js
+++ b/code/binary_tree/bin_tree/spec/spec.core.js
@@ -1,7 +1,7 @@
/*
-------------------------- Binary Search Tree -------------------------
+------------------------- Binary Search Tree -------------------------
-NOTE: This is about the simplest Binary Search Tree we could make. It does NOT implement deletion
+NOTE: This is about the simplest Binary Search Tree we could make. It does NOT implement deletion
which is rather complex. However, Zakas has a series of articles online (part II does the deletiation part):
http://www.nczonline.net/blog/2009/06/16/computer-science-in-javascript-binary-search-tree-part-2/
http://www.nczonline.net/blog/2009/06/09/computer-science-in-javascript-binary-search-tree-part-1/
@@ -40,7 +40,7 @@ the root. If we assume the root is Level 0, its children will be Level 1, its gr
will be Level 2, and so on.
-- Keys: We’ve seen that one data item in an object is usually designated a key value. This
-value is used to search for the item or perform other operations on it.
+value is used to search for the item or perform other operations on it.
-- Binary Trees: If every node in a tree can have at most two children, the tree is called a binary
tree.
@@ -64,10 +64,10 @@ describe 'Binary Search Tree'
tree = new BSTree(root)
tree.addNode(leftChild)
tree.addNode(rightChild)
- end
+ end
it 'should create a node2 with left and right nodes'
// Node should be as initialized data, left/right null
- node2.data.should.be 222
+ node2.data.should.be 222
node2['left'].should.be_null
node2['right'].should.be_null
// After assignment, left/right should be as assigned
@@ -104,8 +104,8 @@ describe 'Binary Search Tree'
tree.find(10).id.should.equal 10
tree.find(16).id.should.equal 16
tree.find(17).id.should.equal 17
- tree.find(888).should.be_null
- tree.find('abc').should.be_null
+ tree.find(888).should.be_null
+ tree.find('abc').should.be_null
end
it 'should add and find nodes even if negative numbers'
var negNode = new Node(-10)
@@ -115,7 +115,7 @@ describe 'Binary Search Tree'
it 'should traverse in order and return in order array'
var llGrandChild = new Node(5,5)
tree.addNode(llGrandChild)
- var inOrderArray = tree.traverseInOrder([], root)
+ var inOrderArray = tree.traverseInOrder([], root)
inOrderArray[0].id.should.equal llGrandChild.id
inOrderArray[1].id.should.equal leftChild.id
inOrderArray[2].id.should.equal root.id
diff --git a/code/gotchas/README.rdoc b/code/gotchas/README.rdoc
index 2cd053a..4a4f290 100644
--- a/code/gotchas/README.rdoc
+++ b/code/gotchas/README.rdoc
@@ -3,7 +3,7 @@
Description
-== License
+== License
(The MIT License)
diff --git a/code/gotchas/lib/gotchas.js b/code/gotchas/lib/gotchas.js
index a56ae4c..9859096 100644
--- a/code/gotchas/lib/gotchas.js
+++ b/code/gotchas/lib/gotchas.js
@@ -17,8 +17,8 @@ var privileged_singleton = function() {
var obj = SomeObject;
obj.publicVar = 'this is public';
obj.publicFunc = function() {
- var message = 'publicFunc is privileged, and hereby allows you to see private var: ' +
- privateVar + ', as well as see the return value of privateFunc: ' + privateFunc();
+ var message = 'publicFunc is privileged, and hereby allows you to see private var: ' +
+ privateVar + ', as well as see the return value of privateFunc: ' + privateFunc();
return message;
};
return obj;
diff --git a/code/gotchas/spec/spec.gotchas.js b/code/gotchas/spec/spec.gotchas.js
index 163c3db..a9b321e 100644
--- a/code/gotchas/spec/spec.gotchas.js
+++ b/code/gotchas/spec/spec.gotchas.js
@@ -1,20 +1,20 @@
describe 'JavaScript Gotchas'
before
- gotchas = new Gotchas
+ gotchas = new Gotchas
end
describe 'parseInt Weirdness'
- it 'should ignore any non-integer characters and discard anything after first non-integer'
+ it 'should ignore any non-integer characters and discard anything after first non-integer'
gotchas.callParseInt('82I_AM_IGNORED_1234', 10).should.eql 82
gotchas.callParseInt('82#$I_AM_IGNORED_1234', 10).should.eql 82
gotchas.callParseInt('1010_binary_too!_1234', 2).should.eql 10
end
- it 'should return zero for 08 and 09'
+ it 'should return zero for 08 and 09'
gotchas.callParseInt('08', undefined).should.eql 0
gotchas.callParseInt('09', undefined).should.eql 0
gotchas.callParseInt('09').should.eql 0
gotchas.callParseInt('09000', undefined).should.eql 0
gotchas.callParseInt('090jibberish00', undefined).should.eql 0
- gotchas.callParseInt('08', 10).should.eql 8
+ gotchas.callParseInt('08', 10).should.eql 8
end
end
describe '== type coercion example from Crockford Good Parts'
@@ -60,8 +60,8 @@ describe 'JavaScript Gotchas'
describe 'Priveleged Singleton Pattern (also called Module Pattern)'
it 'should create a singleton with private members'
- privileged_singleton.privateVar.should.be_undefined
- privileged_singleton.privateFun.should.be_undefined
+ privileged_singleton.privateVar.should.be_undefined
+ privileged_singleton.privateFun.should.be_undefined
privileged_singleton.publicFunc().should.match /publicFunc is.*this is private.*top secret/i
privileged_singleton.publicVar.should.eql 'this is public'
privileged_singleton.foo.should.eql 'foo'
diff --git a/code/javascript_gods.js b/code/javascript_gods.js
index 1599b37..2aa4a64 100644
--- a/code/javascript_gods.js
+++ b/code/javascript_gods.js
@@ -18,16 +18,16 @@ var TDJS = (function() {
}
Person.prototype.getName = function() { return this.name; }
Person.prototype.setName = function(name) { this.name = name; }
- Person.prototype.greet = function() {
- alert("Hi, my name is " + this.name);
+ Person.prototype.greet = function() {
+ alert("Hi, my name is " + this.name);
alert("Let us pay tribute to: \n" +
"Inventor of JavaScript: " + privateJSHeroes.jsCreator + "\n" +
"Inventor of FireBug: " + privateJSHeroes.firebugCreator + "\n" +
"Inventor of JQuery: " + privateJSHeroes.jqueryGuy + "\n" +
- "Yahoo Home Page & author of Professional JavaScript for Web Developers: " +
+ "Yahoo Home Page & author of Professional JavaScript for Web Developers: " +
privateJSHeroes.yahooUIGuy + "\n" +
"JavaScript: The Good Parts: " + privateJSHeroes.yahooOG + "\n" +
- "(and my apologies to all the other JavaScript greats not listed!)\n");
+ "(and my apologies to all the other JavaScript greats not listed!)\n");
}
return {
Person : Person
diff --git a/code/js_build/Rakefile b/code/js_build/Rakefile
index e849a05..cc547a4 100644
--- a/code/js_build/Rakefile
+++ b/code/js_build/Rakefile
@@ -1,7 +1,7 @@
-require 'tempfile'
+require 'tempfile'
namespace :js do
-
+
# ---------- EDIT THESE PROPERTIES! --------- #
RHINO_JAR_PATH = "rhino/js.jar"
JSLINT_PATH = "jslint/jslint.js"
@@ -47,14 +47,14 @@ namespace :js do
puts
end
end
-
+
desc "Minify JavaScript by concatenating files, then apply YUI Compressor to amalgamation file"
task :min => [:lint] do
concat_file = Tempfile.new("temp_file.js", Dir.getwd )
jsfiles = File.join("**", "*.js") # ** makes it recursive
Dir.glob(jsfiles).reject{|path| path =~ /#{Regexp.quote(JS_EXCLUDE)}/ }.each do |js|
- open(js) do |f|
- concat_file.write(f.read)
+ open(js) do |f|
+ concat_file.write(f.read)
end
end
concat_file.rewind
@@ -64,5 +64,5 @@ namespace :js do
puts "Minified JavaScript - resulting file: #{AMALGAMATION_FILE}"
puts "---------------------------------------------"
puts
- end
+ end
end
diff --git a/code/js_build/another_test/four.js b/code/js_build/another_test/four.js
index 4f62a6e..b72d1d1 100644
--- a/code/js_build/another_test/four.js
+++ b/code/js_build/another_test/four.js
@@ -1,2 +1,2 @@
/*jslint browser: true, nomen: false, glovar: false, rhino: true, eqeqeq: true, white: false */
-var person = { name: "Rob" };
+var person = { name: "Rob" };
diff --git a/code/js_build/three.js b/code/js_build/three.js
index 1b128af..e2524a8 100644
--- a/code/js_build/three.js
+++ b/code/js_build/three.js
@@ -4,4 +4,4 @@ var three = {
alert("I be three!");
},
bar: 'bar-three'
-};
+};
diff --git a/code/jslint_rhino_test/mytest.js b/code/jslint_rhino_test/mytest.js
index e32ea30..dcffd92 100644
--- a/code/jslint_rhino_test/mytest.js
+++ b/code/jslint_rhino_test/mytest.js
@@ -4,7 +4,7 @@ var person = {
foo: function() {
alert("OMG...BOOOORRRRING!!!!");
}// , // See if JSLint sees this?
-};
+};
var pickyBrackets =
{
picky: "Doug likes brackets in K&R style"
diff --git a/code/jspec_test/cart/README.rdoc b/code/jspec_test/cart/README.rdoc
index 2cd053a..4a4f290 100644
--- a/code/jspec_test/cart/README.rdoc
+++ b/code/jspec_test/cart/README.rdoc
@@ -3,7 +3,7 @@
Description
-== License
+== License
(The MIT License)
diff --git a/code/objects/README.rdoc b/code/objects/README.rdoc
index 2cd053a..4a4f290 100644
--- a/code/objects/README.rdoc
+++ b/code/objects/README.rdoc
@@ -3,7 +3,7 @@
Description
-== License
+== License
(The MIT License)
diff --git a/code/objects/lib/js_inheritance.js b/code/objects/lib/js_inheritance.js
index b040801..2258eed 100644
--- a/code/objects/lib/js_inheritance.js
+++ b/code/objects/lib/js_inheritance.js
@@ -45,7 +45,7 @@ var helper = { // Thanks to Bob Vince for reminding me NOT to clobber Objec
inherit: function(p) {
NewObj = function(){};
NewObj.prototype = p;
- return new NewObj();
+ return new NewObj();
},
inheritPrototype: function(subType, superType) {
var prototype = helper.inherit(superType.prototype);
@@ -56,16 +56,16 @@ var helper = { // Thanks to Bob Vince for reminding me NOT to clobber Objec
function SubType(name, age) {
Parent.call(this, name);
- this.age = age;
+ this.age = age;
};
//Child.prototype = new Parent(); // Gets replaced by:
-helper.inheritPrototype(SubType, Parent);
+helper.inheritPrototype(SubType, Parent);
SubType.prototype.getAge = function() {
return this.age;
};
// Functional - Durable Pattern
-function super_func(blueprint) {
+function super_func(blueprint) {
var obj = {};
obj.getName = function() { return blueprint.name; };
obj.getAge = function() { return blueprint.age; };
@@ -77,5 +77,5 @@ function sub_func(blueprint) {
blueprint.name = blueprint.name || "Crockford's Place";
supr = super_func(blueprint);
supr.coolAugment = function() { return "I give a fresh new perspective on things!" };
- return supr;
+ return supr;
};
diff --git a/code/objects/spec/spec.js_inheritance.js b/code/objects/spec/spec.js_inheritance.js
index 3c1fcc3..a6dfbe8 100644
--- a/code/objects/spec/spec.js_inheritance.js
+++ b/code/objects/spec/spec.js_inheritance.js
@@ -2,24 +2,24 @@ describe 'JavaScript Inheritance Tests'
before_each
animal = new Animal("Onyx")
dog = new Dog("Sebastian", "Lab")
-
+
person = { password : 'secret', toString : function(){ return '' } }
- stub(person, 'toString').and_return('Original toString method!')
+ stub(person, 'toString').and_return('Original toString method!')
end
describe 'Pseudoclassical Inheritance Creation'
it 'should create parent and child object using pseudoclassical inheritance'
animal.constructor.should.eql Animal
// dog.constructor.should.eql Dog // Nope: expected Animal to eql Dog
- dog.constructor.should.eql Animal
- animal.should.be_a Animal
+ dog.constructor.should.eql Animal
+ animal.should.be_a Animal
dog.should.be_a Animal
// dog.should.be_a Dog // Nope! We severed the original prototype pointer and now point to Animal!
dog.should.be_an_instance_of Animal
- dog.should.be_an_instance_of Dog
+ dog.should.be_an_instance_of Dog
(animal instanceof Dog).should.be_false
end
it 'should behave such that child inherits methods and instance variables defined in parent'
- animal.whoAmI().should.match /I am Onyx.*/
+ animal.whoAmI().should.match /I am Onyx.*/
dog.whoAmI().should.match /Sebastian.*/
animal.should.respond_to 'whoAmI'
dog.should.respond_to 'whoAmI'
@@ -33,17 +33,17 @@ describe 'JavaScript Inheritance Tests'
// animal.should.respond_to 'bark' // Of course not!
end
it 'should behave such that reference variables on the parent are "staticy" to all child instances'
- dog.arr.should.eql([1,2,3])
+ dog.arr.should.eql([1,2,3])
dog.arr.push(4)
- dog.arr.should.eql([1,2,3,4])
+ dog.arr.should.eql([1,2,3,4])
spike = new Dog("Spike", "Pitbull")
- spike.arr.should.eql([1,2,3,4])
+ spike.arr.should.eql([1,2,3,4])
spike.arr.push(5)
rover = new Dog("Rover", "German Sheppard")
spike.arr.should.eql([1,2,3,4,5])
rover.arr.should.eql([1,2,3,4,5])
dog.arr.should.eql([1,2,3,4,5])
- end
+ end
end
describe 'Combination Inheritance Solves Static Prototype Properties Issue'
@@ -80,39 +80,39 @@ describe 'JavaScript Inheritance Tests'
charlie.arr.should.eql([1,2,3])
charlie.arr.push(999)
charlie.arr.should.eql([1,2,3,999])
- sub.arr.should.eql([1,2,3])
+ sub.arr.should.eql([1,2,3])
sub.should.be_an_instance_of SubType
charlie.should.be_an_instance_of SubType
- (sub instanceof SubType).should.eql true
- (sub instanceof Parent).should.eql true
+ (sub instanceof SubType).should.eql true
+ (sub instanceof Parent).should.eql true
end
end
-
+
describe 'Functional Durable Inheritance'
it 'should hide private variables'
sup = new super_func( {name: "Superfly Douglas", age: 39, foo: "foo", bar: "bar"} )
sup.getName().should.eql 'Superfly Douglas'
sup.name.should.be_undefined
- sup.getAge().should.eql 39
+ sup.getAge().should.eql 39
sup.age.should.be_undefined
sup.getFoo().should.eql 'foo'
sup.foo.should.be_undefined
end
-
+
it 'should create a descendent object that inherits properties while maintaining privacy'
sub = new sub_func( {name: "Submarine", age: 1, foo: "food", bar: "barfly"} )
sub.getName().should.eql 'Submarine'
sub.name.should.be_undefined
- sub.getAge().should.eql 1
+ sub.getAge().should.eql 1
sub.age.should.be_undefined
sub.getFoo().should.eql 'food'
- sub.foo.should.be_undefined
+ sub.foo.should.be_undefined
sub.getBar().should.eql 'barfly'
- sub.bar.should.be_undefined
+ sub.bar.should.be_undefined
sub.coolAugment().should.match /.*fresh new perspective.*/
//sub.should.be_an_instance_of super_func NOPE!
//sub.should.be_an_instance_of sub_func NOPE!
- sub.should.be_an_instance_of Object
+ sub.should.be_an_instance_of Object
end
end
diff --git a/code/objects/spec/spec.js_obj_creation.js b/code/objects/spec/spec.js_obj_creation.js
index 904e75c..996689f 100644
--- a/code/objects/spec/spec.js_obj_creation.js
+++ b/code/objects/spec/spec.js_obj_creation.js
@@ -11,29 +11,29 @@ describe 'ObjectCreation'
it 'should add prototype property which should be available to all instances'
obj1.foo.should.eql 'foo property'
obj2.foo.should.eql 'foo property'
- obj1.bar().should.eql 'me is bar method'
- obj2.bar().should.eql 'me is bar method'
- end
+ obj1.bar().should.eql 'me is bar method'
+ obj2.bar().should.eql 'me is bar method'
+ end
end
describe 'Overriding Prototype Properties'
it 'should update a prototype property but only affect that same instance'
obj1.foo = "new version of foo"
obj1.foo.should.eql "new version of foo"
obj2.foo.should.eql "foo property"
- end
+ end
end
describe 'Updated Prototype Props are really shadowed'
it 'should return to showing original prototype value after deleting the shadow'
obj1.foo = "new version of foo"
obj1.foo.should.eql "new version of foo"
delete obj1.foo;
- obj1.foo.should.eql "foo property"
+ obj1.foo.should.eql "foo property"
// Test on methods too
obj1.bar = function() { return "me is NEW bar method!"; }
- obj1.bar().should.eql 'me is NEW bar method!'
+ obj1.bar().should.eql 'me is NEW bar method!'
delete obj1.bar;
- obj1.bar().should.eql 'me is bar method'
- end
+ obj1.bar().should.eql 'me is bar method'
+ end
end
describe 'Prototype Literals'
@@ -53,17 +53,17 @@ describe 'ObjectCreation'
Thing.prototype = {
foo : 'foo'
};
- ('foo' in beforeProto).should.eql false
+ ('foo' in beforeProto).should.eql false
var afterProto = new Thing();
- ('foo' in afterProto).should.eql true
+ ('foo' in afterProto).should.eql true
end
end
-
+
describe 'Prototype Issue - Static-Like Behavior ONLY for Reference Types'
it 'should share state on prototype non-method properties'
var instance1 = new Issues()
var instance2 = new Issues()
-
+
// Reference types are essentially static
instance1.arr.push('cuatro')
(instance1.arr === instance2.arr).should.eql true
@@ -74,8 +74,8 @@ describe 'ObjectCreation'
// OMG, primitives hide their state just fine!
instance1.x = 9
- instance1.x.should.eql 9
- instance2.x.should.eql 1
+ instance1.x.should.eql 9
+ instance2.x.should.eql 1
end
end
end
diff --git a/code/objects/spec/spec.js_objects.js b/code/objects/spec/spec.js_objects.js
index 10ed83d..57c4b5f 100644
--- a/code/objects/spec/spec.js_objects.js
+++ b/code/objects/spec/spec.js_objects.js
@@ -18,9 +18,9 @@ describe 'JSObjects'
it 'should reference original object and reflect any changes made to original'
o = jso.objLiteralCreate();
var copy = o;
- copy.name.should.eql 'Rob'
+ copy.name.should.eql 'Rob'
o.name = 'Charlie'
- copy.name.should.eql 'Charlie'
+ copy.name.should.eql 'Charlie'
end
end
diff --git a/code/qunit_test.html b/code/qunit_test.html
index ee18a70..f65f1f7 100644
--- a/code/qunit_test.html
+++ b/code/qunit_test.html
@@ -1,4 +1,4 @@
-
@@ -9,7 +9,7 @@
-
+
QUnit example
diff --git a/code/singly_linked/README.rdoc b/code/singly_linked/README.rdoc
index 2cd053a..4a4f290 100644
--- a/code/singly_linked/README.rdoc
+++ b/code/singly_linked/README.rdoc
@@ -3,7 +3,7 @@
Description
-== License
+== License
(The MIT License)
diff --git a/code/singly_linked/lib/yourlib.core.js b/code/singly_linked/lib/yourlib.core.js
index 9b884a3..712008f 100644
--- a/code/singly_linked/lib/yourlib.core.js
+++ b/code/singly_linked/lib/yourlib.core.js
@@ -34,7 +34,7 @@ SinglyLinkedList.prototype = {
if(current.id === id) { // If found match
if(current === this.head) { // If first link in list
this.head = this.head.next;
- } else {
+ } else {
previous.next = current.next;
}
this.length--;
@@ -56,7 +56,7 @@ SinglyLinkedList.prototype = {
}
return null;
},
- isEmpty: function() {
+ isEmpty: function() {
return (this.head === null) ? true : false;
},
@@ -67,7 +67,7 @@ SinglyLinkedList.prototype = {
// Set current to head - loop list to get size
var current = this.head;
- var size = 1;
+ var size = 1;
while(current.next !== null) {
size++;
current = current.next;
@@ -87,6 +87,6 @@ function isANumber(n) {
if(typeof n === 'number' && isFinite(n)) {
return true;
} else {
- return false;
+ return false;
}
-};
+};
diff --git a/code/singly_linked/spec/spec.core.js b/code/singly_linked/spec/spec.core.js
index bb72e30..ef3ce16 100644
--- a/code/singly_linked/spec/spec.core.js
+++ b/code/singly_linked/spec/spec.core.js
@@ -1,5 +1,5 @@
// ----- Singly Linked List ----
-// We are not going to rename the spec.core.js and yourlib.core.js in
+// We are not going to rename the spec.core.js and yourlib.core.js in
// efforts to save time.
describe 'Singly Linked List'
before_each
@@ -16,7 +16,7 @@ describe 'Singly Linked List'
it 'should create first node with next pointing to null'
node = new LinkNode(1)
node.toString().should.eql "LinkNode id: 1"
- node.next.should.be_null
+ node.next.should.be_null
node.id.should.eql 1
end
it 'should create linked list with zero elements & a head member pointing to null.'
@@ -24,7 +24,7 @@ describe 'Singly Linked List'
list.head.should.be_null
end
end
-
+
describe 'List insertion'
it 'should insert node as new head of list, and have its next point to old head.'
list.insertBeginning(firstNode)
@@ -45,7 +45,7 @@ describe 'Singly Linked List'
end
end
-
+
describe 'Link node removal'
it 'should return false when list is empty and we try to remove'
removed = list.remove(2)
@@ -61,8 +61,8 @@ describe 'Singly Linked List'
list.insertBeginning(secondNode)
list.insertBeginning(new LinkNode(3))
list.remove(2).should.eql true
- list.length.should.eql 2
- list.remove(999).should.eql false
+ list.length.should.eql 2
+ list.remove(999).should.eql false
/* Insure we in fact removed link */
list.traverse().should.eql([3,1])
end
@@ -81,15 +81,15 @@ describe 'Singly Linked List'
list.find(999).should.be null
list.find('junk').should.be null
end
- it 'should return null if list is empty'
+ it 'should return null if list is empty'
list.find(firstNode.id).should.be null
list.find(secondNode.id).should.be null
list.find("garbage").should.be null
end
end
-
+
describe 'Find Nth-to-last element.'
-
+
it 'should find Nth-to-last if list at least N elements, otherwise return null'
list.insertBeginning(firstNode)
list.insertBeginning(secondNode)
@@ -98,17 +98,17 @@ describe 'Singly Linked List'
end
it 'should return null if list is empty or less than N'
// List is empty but we try to find N
- list.findNthToLast(2).should.be null
+ list.findNthToLast(2).should.be null
list.insertBeginning(firstNode)
list.insertBeginning(secondNode)
// List is 2 elements. Lets make N == 3
- list.findNthToLast(3).should.be null
+ list.findNthToLast(3).should.be null
end
it 'should return null if n argument is not a number'
list.insertBeginning(firstNode)
- list.findNthToLast('abc').should.be null
- list.findNthToLast({one:1,two:2}).should.be null
- list.findNthToLast([1]).should.be null
- end
+ list.findNthToLast('abc').should.be null
+ list.findNthToLast({one:1,two:2}).should.be null
+ list.findNthToLast([1]).should.be null
+ end
end
end
diff --git a/code/yui_compressor/mytest.js b/code/yui_compressor/mytest.js
index e32ea30..dcffd92 100644
--- a/code/yui_compressor/mytest.js
+++ b/code/yui_compressor/mytest.js
@@ -4,7 +4,7 @@ var person = {
foo: function() {
alert("OMG...BOOOORRRRING!!!!");
}// , // See if JSLint sees this?
-};
+};
var pickyBrackets =
{
picky: "Doug likes brackets in K&R style"
diff --git a/code/yui_compressor/nested.js b/code/yui_compressor/nested.js
index 1affcf3..c149a25 100644
--- a/code/yui_compressor/nested.js
+++ b/code/yui_compressor/nested.js
@@ -7,4 +7,4 @@ var person = {
var nestedFunc = 'nest function value';
})();
}
-};
+};
diff --git a/code/yui_test.js b/code/yui_test.js
index 998d6dc..06d9386 100644
--- a/code/yui_test.js
+++ b/code/yui_test.js
@@ -2,7 +2,7 @@
var nameAgeTest = new YAHOO.tool.TestCase({
name: "Test Name and Age",
-
+
setUp : function () {
this.data = { name : "Rob", age : 39 };
},
@@ -17,13 +17,13 @@ var nameAgeTest = new YAHOO.tool.TestCase({
testAge: function () {
YAHOO.util.Assert.areEqual(39, this.data.age, "Age should be 39");
- }
+ }
});
// Simple test case 2
var fooNumTest = new YAHOO.tool.TestCase({
name: "Test Foo Num",
-
+
setUp : function () {
this.data = { foo : "FOO", num : 123 };
},
@@ -38,7 +38,7 @@ var fooNumTest = new YAHOO.tool.TestCase({
testBar: function () {
YAHOO.util.Assert.areEqual(123, this.data.num, "num should be 123");
- }
+ }
});
// Create a test suite and add the two test cases from above
diff --git a/code/yui_test3.js b/code/yui_test3.js
index 0502378..8ea1500 100644
--- a/code/yui_test3.js
+++ b/code/yui_test3.js
@@ -7,15 +7,15 @@
YUI({combine: true, timeout: 10000}).use("node", "console", "test",function (Y) {
Y.namespace("tddjs.test");
-
+
Y.tddjs.test.DataTestCase = new Y.Test.Case({
-
+
name : "YUI 3 Tests",
-
+
//---------------------------------------------------------------------
// setUp and tearDown methods - optional
//---------------------------------------------------------------------
-
+
/*
* Sets up data that is needed by each test.
*/
@@ -26,100 +26,100 @@ YUI({combine: true, timeout: 10000}).use("node", "console", "test",function (Y)
beta: true
};
},
-
+
/*
* Cleans up everything that was created by setUp().
*/
tearDown : function () {
delete this.data;
},
-
+
//---------------------------------------------------------------------
// Test methods - names must begin with "test"
//---------------------------------------------------------------------
-
+
testName : function () {
var Assert = Y.Assert;
-
+
Assert.isObject(this.data);
Assert.isString(this.data.name);
- Assert.areEqual("test", this.data.name);
+ Assert.areEqual("test", this.data.name);
},
-
+
testYear : function () {
var Assert = Y.Assert;
-
+
Assert.isObject(this.data);
Assert.isNumber(this.data.year);
- Assert.areEqual(2007, this.data.year);
+ Assert.areEqual(2007, this.data.year);
},
-
+
testBeta : function () {
var Assert = Y.Assert;
-
+
Assert.isObject(this.data);
Assert.isBoolean(this.data.beta);
Assert.isTrue(this.data.beta);
}
-
+
});
-
+
Y.tddjs.test.ArrayTestCase = new Y.Test.Case({
-
+
//name of the test case - if not provided, one is auto-generated
name : "Array Tests",
-
+
//---------------------------------------------------------------------
// setUp and tearDown methods - optional
//---------------------------------------------------------------------
-
+
/*
* Sets up data that is needed by each test.
*/
setUp : function () {
this.data = [0,1,2,3,4]
},
-
+
/*
* Cleans up everything that was created by setUp().
*/
tearDown : function () {
delete this.data;
},
-
+
//---------------------------------------------------------------------
// Test methods - names must begin with "test"
//---------------------------------------------------------------------
-
+
testPop : function () {
var Assert = Y.Assert;
-
+
var value = this.data.pop();
-
+
Assert.areEqual(4, this.data.length);
- Assert.areEqual(4, value);
- },
-
+ Assert.areEqual(4, value);
+ },
+
testPush : function () {
var Assert = Y.Assert;
-
+
this.data.push(5);
-
+
Assert.areEqual(6, this.data.length);
- Assert.areEqual(5, this.data[5]);
+ Assert.areEqual(5, this.data[5]);
},
-
+
testSplice : function () {
var Assert = Y.Assert;
-
+
this.data.splice(2, 1, 6, 7);
-
+
Assert.areEqual(6, this.data.length);
- Assert.areEqual(6, this.data[2]);
- Assert.areEqual(7, this.data[3]);
+ Assert.areEqual(6, this.data[2]);
+ Assert.areEqual(7, this.data[3]);
}
-
- });
+
+ });
Y.tddjs.test.ExampleSuite = new Y.Test.Suite("Example Suite");
Y.tddjs.test.ExampleSuite.add(Y.tddjs.test.DataTestCase);
@@ -130,9 +130,9 @@ YUI({combine: true, timeout: 10000}).use("node", "console", "test",function (Y)
newestOnTop : false,
style: 'block' // to anchor in the example content
});
-
+
r.render('#testLogger');
-
+
Y.Test.Runner.add(Y.tddjs.test.ExampleSuite);
//run the tests
diff --git a/code/yui_test_setup.js b/code/yui_test_setup.js
index 27d66dd..b09f84a 100644
--- a/code/yui_test_setup.js
+++ b/code/yui_test_setup.js
@@ -2,14 +2,14 @@
var nameAgeTest = new YAHOO.tool.TestCase({
name: "Test Name and Age",
-
+
setUp : function () {
console.log("setUp called...");
this.data = { name : "Rob", age : 39 };
},
tearDown : function () {
- console.log("tearDown called...");
+ console.log("tearDown called...");
delete this.data;
},
@@ -19,7 +19,7 @@ var nameAgeTest = new YAHOO.tool.TestCase({
testAge: function () {
YAHOO.util.Assert.areEqual(39, this.data.age, "Age should be 39");
- },
+ },
testTrue: function () {
return true;
@@ -33,7 +33,7 @@ var nameAgeTest = new YAHOO.tool.TestCase({
var fooNumTest = new YAHOO.tool.TestCase({
name: "Test Foo Num",
-
+
setUp : function () {
this.data = { foo : "FOO", num : 123 };
},
@@ -48,7 +48,7 @@ var fooNumTest = new YAHOO.tool.TestCase({
testBar: function () {
YAHOO.util.Assert.areEqual(123, this.data.num, "num should be 123");
- }
+ }
});
// Create a test suite and add the two test cases from above
diff --git a/jsunit/jsunit.properties.sample b/jsunit/jsunit.properties.sample
index b97504d..e92dd37 100755
--- a/jsunit/jsunit.properties.sample
+++ b/jsunit/jsunit.properties.sample
@@ -32,4 +32,3 @@
#url is the URL (HTTP or file protocol) to open in the browser. For a JsUnit Server, this is a mandatory property for a test run if the server is not passed the 'url' parameter. For example: 'file:///c:/jsunit/testRunner.html?testPage=c:/jsunit/tests/jsUnitTestSuite.html'
url=
-
\ No newline at end of file