'use strict';

const path = require('path');
const test = require('supertape');
const mockRequire = require('mock-require');
const {winToWeb} = require('..');

const {stopAll, reRequire} = mockRequire;

test('mellow: webToWin', (t) => {
    const {platform} = process;
    
    Object.defineProperty(process, 'platform', {
        value: 'win32',
    });
    
    mockRequire('path', path.win32);
    
    const {webToWin} = reRequire('..');
    const result = webToWin('/c/windows', '');
    const expected = 'c:\\windows';
    
    Object.defineProperty(process, 'platform', {
        value: platform,
    });
    
    stopAll();
    
    t.equal(result, expected);
    t.end();
});

test('mellow: webToWin: /', (t) => {
    const {platform} = process;
    
    Object.defineProperty(process, 'platform', {
        value: 'win32',
    });
    
    mockRequire('path', path.win32);
    
    const {webToWin} = reRequire('..');
    const result = webToWin('/', '');
    const expected = '/';
    
    Object.defineProperty(process, 'platform', {
        value: platform,
    });
    
    stopAll();
    
    t.equal(result, expected);
    t.end();
});

test('mellow: winToWeb', (t) => {
    const {platform} = process;
    
    Object.defineProperty(process, 'platform', {
        value: 'win32',
    });
    
    mockRequire('path', path.win32);
    
    const result = winToWeb('c:\\windows', '');
    const expected = '/c/windows';
    
    Object.defineProperty(process, 'platform', {
        value: platform,
    });
    
    stopAll();
    
    t.equal(result, expected);
    t.end();
});

test('mellow: webToWin: linux', (t) => {
    const {webToWin} = reRequire('..');
    const result = webToWin('/c/windows', '');
    const expected = '/c/windows';
    
    t.equal(result, expected);
    t.end();
});

test('mellow: winToWeb: linux', (t) => {
    const result = winToWeb('/home/user', '');
    const expected = '/home/user';
    
    stopAll();
    
    t.equal(result, expected);
    t.end();
});

test('mellow: winToWeb: linux: no root', (t) => {
    const result = winToWeb('/home/user');
    const expected = '/home/user';
    
    stopAll();
    
    t.equal(result, expected);
    t.end();
});

test('mellow: webToWin: root and root not /', (t) => {
    const {webToWin} = reRequire('..');
    const result = webToWin('/windows', '/c/');
    const expected = '/c/windows';
    
    t.equal(result, expected);
    t.end();
});

@@ -1581,32 +1581,480 @@
   t.end();%0A%7D);%0A%0A
+test('mellow: winToWeb: no root', (t) =%3E %7B%0A    const %7Bplatform%7D = process;%0A    %0A    Object.defineProperty(process, 'platform', %7B%0A        value: 'win32',%0A    %7D);%0A    %0A    mockRequire('path', path.win32);%0A    %0A    const result = winToWeb('c:%5C%5Cwindows');%0A    const expected = '/c/windows';%0A    %0A    Object.defineProperty(process, 'platform', %7B%0A        value: platform,%0A    %7D);%0A    %0A    stopAll();%0A    %0A    t.equal(result, expected);%0A    t.end();%0A%7D);%0A%0A
 test('mellow: we
@@ -2864,28 +2864,29 @@
 expected);%0A    t.end();%0A%7D);%0A
+%0A

test(mellow) no root