define([
    'bitbucket/internal/model/path'
], function(
    Path
) {

    'use strict';

    module('model-path');

    test('ctor', function() {
        deepEqual(new Path(['a', 'b', 'c']).getComponents(), ['a', 'b', 'c'], "Path has correct components when created from components.");
        deepEqual(new Path(new Path(['a', 'b', 'c'])).getComponents(), ['a', 'b', 'c'], "Path has correct components when created from another Path.");
        deepEqual(new Path({ components : ['a', 'b', 'c']}).getComponents(), ['a', 'b', 'c'], "Path has correct components when created from a JSON path.");
        deepEqual(new Path('a/b/c').getComponents(), ['a', 'b', 'c'], "Path has correct components when created from a string.");
        deepEqual(new Path('/a/b/c').getComponents(), ['a', 'b', 'c'], "Path has correct components when created from a string.");
        deepEqual(new Path('a/b/c/').getComponents(), ['a', 'b', 'c'], "Path has correct components when created from a string.");
        deepEqual(new Path('/a/b/c/').getComponents(), ['a', 'b', 'c'], "Path has correct components when created from a string.");
        deepEqual(new Path('/').getComponents(), [], "Path has correct components when created from a string.");
        deepEqual(new Path('').getComponents(), [], "Path has correct components when created from a string.");
    });

    test('fromParentAndName', function() {
        var parent = new Path('a/b');
        deepEqual(Path.fromParentAndName(parent, 'c').getComponents(), ['a', 'b', 'c'], "Path has correct components when created from parent and name.");

    });

    test('getName', function() {
        strictEqual(new Path('a/b/c').getName(), "c", "Path returns correct name.");
        strictEqual(new Path('').getName(), null, "Path returns correct name for root.");

    });

    test('getExtension', function() {
        strictEqual(new Path('a/b/c.d').getExtension(), "d", "Path returns correct extension.");
        strictEqual(new Path('a/b').getExtension(), '', "Path returns correct name for path and name.");
        strictEqual(new Path('e').getExtension(), '', "Path returns correct name for single name.");
        strictEqual(new Path('').getExtension(), '', "Path returns correct name for root.");

    });

    test('getParent', function() {
        deepEqual(new Path('a/b/c').getParent().getComponents(), ['a', 'b'], "Path returns correct name.");
        deepEqual(new Path('a').getParent().getComponents(), [], "Path returns correct name.");
        deepEqual(new Path('').getParent(), null, "Path returns correct name for root.");

    });

    function assertIsSameDirectory(pathA, pathB, isSame, message) {
        equal(pathA.isSameDirectory(pathB), isSame, message);
        equal(pathB.isSameDirectory(pathA), isSame, message);
    }

    test('isSameDirectory', function() {

        var controlPath = new Path(['a', 'b', 'c', 'd', 'e']);
        var path2 = new Path(['a', 'b', 'c', 'd', 'not e']);
        var path3 = new Path(['a', 'b', 'c', 'd']);
        var path4 = new Path(['a', 'b', 'c', 'd', 'e', 'f']);
        var path5 = new Path(['e', 'd', 'c', 'b', 'a']);

        assertIsSameDirectory(controlPath, path2, true, "Paths 1 and 2 are children in the same directory.");

        assertIsSameDirectory(controlPath, path3, false, "Paths 1 and 3 are not children in the same directory.");
        assertIsSameDirectory(controlPath, path4, false, "Paths 1 and 4 are not children in the same directory.");
        assertIsSameDirectory(controlPath, path5, false, "Paths 1 and 5 are not children in the same directory.");

    });
});
