import test from 'ava'
import commonPathPrefix from '.'

test('returns an empty string if there is no common prefix', t => {
  t.is(commonPathPrefix(['foo', 'bar'], '/'), '')
})

test('returns the longest common prefix', t => {
  t.is(commonPathPrefix(['/foo/bar/baz/qux', '/foo/bar/baz/quux'], '/'), '/foo/bar/baz/')
})

test('supports relative paths', t => {
  t.is(commonPathPrefix(['./foo/bar/baz/qux', './foo/bar/baz/quux'], '/'), './foo/bar/baz/')
})

test('the file separator may be a prefix', t => {
  t.is(commonPathPrefix(['/foo/bar', '/baz/qux'], '/'), '/')
})

test('the file separator is determined by the first occurence of / or \\ in the first path', t => {
  t.is(commonPathPrefix(['/foo/bar', '/baz/qux']), '/')
  t.is(commonPathPrefix(['./foo/bar', './baz/qux']), './')
  t.is(commonPathPrefix(['foo/bar/baz', 'foo/bar/qux']), 'foo/bar/')

  t.is(commonPathPrefix(['\\foo\\bar', '\\baz\\qux']), '\\')
  t.is(commonPathPrefix(['.\\foo\\bar', '.\\baz\\qux']), '.\\')
  t.is(commonPathPrefix(['foo\\bar\\baz', 'foo\\bar\\qux']), 'foo\\bar\\')

  t.is(commonPathPrefix(['/foo/bar', '\\baz\\qux']), '')
  t.is(commonPathPrefix(['foo', '\\baz\\qux']), '')
})

test('the file separator can be specified', t => {
  t.is(commonPathPrefix(['/foo/bar', '/baz/qux'], '\\'), '')
  t.is(commonPathPrefix(['\\foo\\bar', '\\baz\\qux'], '/'), '')
  t.is(commonPathPrefix(['foo$bar$baz', 'foo$bar$qux'], '$'), 'foo$bar$')
})

test('the file separator can be a multi-byte string', t => {
  t.is(commonPathPrefix(['foo👼bar👼baz', 'foo👼bar👼qux'], '👼'), 'foo👼bar👼')
})

@@ -156,21 +156,16 @@
 , 'bar'%5D
-, '/'
 ), '')%0A%7D
@@ -277,29 +277,24 @@
 r/baz/quux'%5D
-, '/'
 ), '/foo/bar
@@ -407,29 +407,24 @@
 r/baz/quux'%5D
-, '/'
 ), './foo/ba
@@ -436,62 +436,8 @@
 /')%0A
-%7D)%0A%0Atest('the file separator may be a prefix', t =%3E %7B%0A
   t.
@@ -454,36 +454,31 @@
 athPrefix(%5B'
-/
 foo/bar
-', '
 /baz/qux'%5D, 
@@ -474,26 +474,52 @@
 baz/qux'
-%5D
 , '
-/'), '
+foo/bar/baz/quux'%5D), 'foo/bar/baz
 /')%0A%7D)%0A%0A
@@ -704,398 +704,77 @@
 x(%5B'
-./foo/bar', './baz/qux'%5D), './')%0A  t.is(commonPathPrefix(%5B'foo/bar/baz', 'foo/bar/qux'%5D), 'foo/bar/')%0A%0A  t.is(commonPathPrefix(%5B'%5C%5Cfoo%5C%5Cbar', '%5C%5Cbaz%5C%5Cqux'%5D), '%5C%5C')%0A  t.is(commonPathPrefix(%5B'.%5C%5Cfoo%5C%5Cbar', '.%5C%5Cbaz%5C%5Cqux'%5D), '.%5C%5C')%0A  t.is(commonPathPrefix(%5B'foo%5C%5Cbar%5C%5Cbaz', 'foo%5C%5Cbar%5C%5Cqux'%5D), 'foo%5C%5Cbar%5C%5C')%0A%0A  t.is(commonPathPrefix(%5B'/foo/bar', '%5C%5Cbaz%5C%5Cqux'%5D), '')%0A  t.is(commonPathPrefix(%5B'foo
+%5C%5Cfoo%5C%5Cbar', '%5C%5Cbaz%5C%5Cqux'%5D), '%5C%5C')%0A  t.is(commonPathPrefix(%5B'/foo/bar
 ', '

Remove unnecessary tests and assertions