1// Copyright 2015 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4'use strict';
5
6var assert = {
7  equal: function(first, second) {
8    if (first !== second) {
9      throw new Error('Assertion error: ' + JSON.stringify(first) +
10          ' !== ' + JSON.stringify(second));
11    }
12  }
13};
14
15function runTests() {
16
17  var test_os_client = {
18    currentWorkingDirectory: '/a/b',
19    exists: function(fileName) {
20      return fileName === '/a/b/file_exists.html';
21    }
22  };
23
24  var path_utils = new PathUtils(test_os_client);
25  assert.equal(path_utils.join('a', 'b'), 'a/b');
26  assert.equal(path_utils.join('/a', 'b'), '/a/b');
27  assert.equal(path_utils.join('/a/', 'b/'), '/a/b/');
28  assert.equal(path_utils.join('/a', '/b/'), '/b/');
29  assert.equal(path_utils.join('/a', './b/'), '/a/./b/');
30  assert.equal(path_utils.join('/a/', './b/'), '/a/./b/');
31  assert.equal(path_utils.join('../', 'b'), '../b');
32  assert.equal(path_utils.join('../', 'b/'), '../b/');
33  assert.equal(path_utils.join('a', 'b'), 'a/b');
34
35  assert.equal(path_utils.absPath('c'), '/a/b/c');
36  assert.equal(path_utils.absPath('./c'), '/a/b/c');
37  assert.equal(path_utils.absPath('./c/d'), '/a/b/c/d');
38
39  assert.equal(path_utils.relPath('/a/b/c', '/a/b'), 'c');
40
41  assert.equal(path_utils.relPath('/a/b/c/', '/a/b/c/'), '.');
42  assert.equal(path_utils.relPath('/a/b/c', '/a/b/c/'), '.');
43  assert.equal(path_utils.relPath('/a/b/c/', '/a/b/c'), '.');
44  assert.equal(path_utils.relPath('/a/b/c', '/a/b/c'), '.');
45
46  assert.equal(path_utils.relPath('/a/b/c', '/a'), 'b/c');
47  assert.equal(path_utils.relPath('/a/b/c', '/a/'), 'b/c');
48
49  assert.equal(path_utils.relPath('/a/b/c', '/b/c/'), '../../a/b/c');
50  assert.equal(path_utils.relPath('/a/b/c', '/b/c'), '../../a/b/c');
51  assert.equal(path_utils.relPath('/a/b/c/', '/b/c/'), '../../a/b/c');
52  assert.equal(path_utils.relPath('/a/b/c/', '/b/c'), '../../a/b/c');
53
54
55  assert.equal(path_utils.exists('/a/b/file_exists.html'), true);
56  assert.equal(path_utils.exists('file_exists.html'), true);
57  assert.equal(path_utils.exists('./file_exists.html'), true);
58  assert.equal(path_utils.exists('/a/file_does_not_exists.html'), false);
59}
60