Bug 783676 - Export OS.Path (companion test suite). r=taras
authorDavid Rajchenbach-Teller <dteller@mozilla.com>
Fri, 24 Aug 2012 16:18:16 -0400
changeset 105378 e1700d9065d832c1fb179ff6fa6c37f0189d34b4
parent 105377 f6ec0707def6e9348e563e84b2945fc74bdfc921
child 105379 ed93b381d52ae402e79295cd342cf65bb87f21d0
push id55
push usershu@rfrn.org
push dateThu, 30 Aug 2012 01:33:09 +0000
reviewerstaras
bugs783676
milestone17.0a1
Bug 783676 - Export OS.Path (companion test suite). r=taras
toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
--- a/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
+++ b/toolkit/components/osfile/tests/mochi/worker_test_osfile_front.js
@@ -21,16 +21,17 @@ self.onmessage = function onmessage_star
     test_open_non_existing_file();
     test_copy_existing_file();
     test_read_write_file();
     test_position();
     test_move_file();
     test_iter_dir();
     test_mkdir();
     test_info();
+    test_path();
   } catch (x) {
     log("Catching error: " + x);
     log("Stack: " + x.stack);
     log("Source: " + x.toSource());
     ok(false, x.toString() + "\n" + x.stack);
   }
   finish();
 };
@@ -516,8 +517,28 @@ function test_mkdir()
     OS.File.stat(dirName);
     ok(false, "test_mkdir: Directory was not removed");
   } catch (x) {
     ok(x instanceof OS.File.Error && x.becauseNoSuchFile, "test_mkdir: Directory was removed");
   }
 
   ok(true, "test_mkdir: Complete");
 }
+
+// Note that most of the features of path are tested in
+// worker_test_osfile_{unix, win}.js
+function test_path()
+{
+  ok(true, "test_path: starting");
+  let abcd = OS.Path.join("a", "b", "c", "d");
+  is(OS.Path.basename(abcd), "d", "basename of a/b/c/d");
+
+  let abc = OS.Path.join("a", "b", "c");
+  is(OS.Path.dirname(abcd), abc, "dirname of a/b/c/d");
+
+  let abdotsc = OS.Path.join("a", "b", "..", "c");
+  is(OS.Path.normalize(abdotsc), OS.Path.join("a", "c"), "normalize a/b/../c");
+
+  let adotsdotsdots = OS.Path.join("a", "..", "..", "..");
+  is(OS.Path.normalize(adotsdotsdots), OS.Path.join("..", ".."), "normalize a/../../..");
+
+  ok(true, "test_path: Complete");
+}