Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding tests for array as a single agrument and url formatting

  • Loading branch information...
commit e6ee64093b01693b20803d1be64a9facdb5d8294 1 parent b78332b
Chad Baudoin authored

Showing 1 changed file with 30 additions and 0 deletions. Show diff stats Hide diff stats

  1. +30 0 test/tests.js
30 test/tests.js
@@ -2,6 +2,7 @@ test("Make sure format exists in the prototype", function() {
2 2 ok( String.prototype.format !== undefined, "format is in the prototype");
3 3 });
4 4
  5 +//argument tests
5 6 test("Test single argument formatting", function() {
6 7 ok("Hello %s".format("world") === "Hello world", "Single string argument works correctly");
7 8 ok("Hello %s".format(3) === "Hello 3", "Single numeric argument works correctly");
@@ -23,8 +24,37 @@ test("Test functional argument formatting", function() {
23 24 ok("Peter %s".format(function(){return "Piper";}) === "Peter Piper", "Functional argument works");
24 25 });
25 26
  27 +//object tests
26 28 test("Test object argument formatting", function() {
27 29 ok("Hello %name%".format({name:"Emmitt"}) === "Hello Emmitt", "Single object argument works correclty");
28 30 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");
29 31 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");
  32 +});
  33 +
  34 +test("Test object argument in a url", function(){
  35 + ok("http://www.google.com/q=%search%".format({search:"Hello+World"}) === "http://www.google.com/q=Hello+World", "Object as paramater works in url");
  36 + 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");
  37 +});
  38 +
  39 +test("Test mutilple arguments in a url", function(){
  40 + ok("http://www.google.com/q=%s".format("Hello+World") === "http://www.google.com/q=Hello+World", "Single argument works in url");
  41 + ok("%s//www.%s.com%s".format("https:", "locationinsight", "/hello/world") === "https://www.locationinsight.com/hello/world", "Multiple arguments work in url");
  42 +});
  43 +
  44 +//array tests
  45 +test("Test single array argument formatting", function() {
  46 + ok("Hello %s".format(["world"]) === "Hello world", "Single string in array argument works correctly");
  47 + ok("Hello %s".format([3]) === "Hello 3", "Single numeric in array argument works correctly");
  48 + ok("Undefined %s".format([undefined]) === "Undefined ", "Single undefined in array argument works correctly");
  49 + ok("Hello %s".format([null]) === "Hello ", "Single null in array argument works correctly");
  50 + ok("Hello %s".format([]) === "Hello ", "empty array works correctly");
  51 +});
  52 +
  53 +test("Test single array argument formatting", function() {
  54 + 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");
  55 + 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");
  56 + 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");
  57 + 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");
  58 + 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");
  59 + 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");
30 60 });

0 comments on commit e6ee640

Please sign in to comment.
Something went wrong with that request. Please try again.