Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding tests for array as a single agrument and url formatting

  • Loading branch information...
commit e6ee64093b01693b20803d1be64a9facdb5d8294 1 parent b78332b
@chadbaudoin authored
Showing with 30 additions and 0 deletions.
  1. +30 −0 test/tests.js
View
30 test/tests.js
@@ -2,6 +2,7 @@ test("Make sure format exists in the prototype", function() {
ok( String.prototype.format !== undefined, "format is in the prototype");
});
+//argument tests
test("Test single argument formatting", function() {
ok("Hello %s".format("world") === "Hello world", "Single string argument works correctly");
ok("Hello %s".format(3) === "Hello 3", "Single numeric argument works correctly");
@@ -23,8 +24,37 @@ test("Test functional argument formatting", function() {
ok("Peter %s".format(function(){return "Piper";}) === "Peter Piper", "Functional argument works");
});
+//object tests
test("Test object argument formatting", function() {
ok("Hello %name%".format({name:"Emmitt"}) === "Hello Emmitt", "Single object argument works correclty");
ok("Hello %name% i am %age% years old".format({name:"Emmitt", age:3}) === "Hello Emmitt i am 3 years old", "Single object with multiple arguments works correclty");
ok("I am age %age% and my name is %name%".format({name:"Emmitt", age:3}) === "I am age 3 and my name is Emmitt", "Single object out of order params");
+});
+
+test("Test object argument in a url", function(){
+ ok("http://www.google.com/q=%search%".format({search:"Hello+World"}) === "http://www.google.com/q=Hello+World", "Object as paramater works in url");
+ ok("%protocol%//www.%domain%.com%path%".format({protocol:"https:", domain:"locationinsight", path:"/hello/world"}) === "https://www.locationinsight.com/hello/world", "Object with multiple entries as paramater works in url");
+});
+
+test("Test mutilple arguments in a url", function(){
+ ok("http://www.google.com/q=%s".format("Hello+World") === "http://www.google.com/q=Hello+World", "Single argument works in url");
+ ok("%s//www.%s.com%s".format("https:", "locationinsight", "/hello/world") === "https://www.locationinsight.com/hello/world", "Multiple arguments work in url");
+});
+
+//array tests
+test("Test single array argument formatting", function() {
+ ok("Hello %s".format(["world"]) === "Hello world", "Single string in array argument works correctly");
+ ok("Hello %s".format([3]) === "Hello 3", "Single numeric in array argument works correctly");
+ ok("Undefined %s".format([undefined]) === "Undefined ", "Single undefined in array argument works correctly");
+ ok("Hello %s".format([null]) === "Hello ", "Single null in array argument works correctly");
+ ok("Hello %s".format([]) === "Hello ", "empty array works correctly");
+});
+
+test("Test single array argument formatting", function() {
+ ok("Peter %s picked a %s of pickled %s".format(["Piper", "peck", "peppers"]) === "Peter Piper picked a peck of pickled peppers", "Multiple string arguments in array works correctly");
+ ok("Peter %s picked a %s of pickled %s".format([0, 1, 2]) === "Peter 0 picked a 1 of pickled 2", "Multiple numeric arguments in array works correctly");
+ ok("Peter %s picked a %s of pickled %s".format(["Piper", 1, "peppers"]) === "Peter Piper picked a 1 of pickled peppers", "Multiple mixed string and numeric arguments in array works correctly");
+ ok("Peter %s picked a %s of pickled %s".format(["Piper", 1]) === "Peter Piper picked a 1 of pickled ", "Wrong number of arguments in array works ok");
+ ok("Peter %s picked a %s of pickled %s".format(["Piper", "peck", undefined]) === "Peter Piper picked a peck of pickled ", "undefined with real arguments in array works ok");
+ ok("Peter %s picked a %s of pickled %s".format(["Piper", "peck", null]) === "Peter Piper picked a peck of pickled ", "null with real arguments in array works ok");
});
Please sign in to comment.
Something went wrong with that request. Please try again.