|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +require('chai').should(); |
| 4 | +const { sep } = require('path'); |
| 5 | +const join = require('../lib/join_path'); |
| 6 | + |
| 7 | +describe('joinPath', () => { |
| 8 | + it('one path', () => { |
| 9 | + const content = 'foo/bar'; |
| 10 | + join(content).should.eql('foo' + sep + 'bar'); |
| 11 | + }); |
| 12 | + |
| 13 | + it('no argument', () => { |
| 14 | + join().should.eql('.'); |
| 15 | + }); |
| 16 | + |
| 17 | + it('zero-length string', () => { |
| 18 | + join('').should.eql('.'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('two paths', () => { |
| 22 | + join('foo', 'bar').should.eql('foo' + sep + 'bar'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('one path - custom separator', () => { |
| 26 | + const custom = '\\'; |
| 27 | + join('foo/bar', { sep: custom }).should.eql('foo' + custom + 'bar'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('two paths - custom separator', () => { |
| 31 | + const custom = '\\'; |
| 32 | + join('foo', 'bar', { sep: custom }).should.eql('foo' + custom + 'bar'); |
| 33 | + }); |
| 34 | + |
| 35 | + it('deduplicate separators', () => { |
| 36 | + join('foo/', '/bar').should.eql('foo' + sep + 'bar'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('starting and ending slashes', () => { |
| 40 | + join('/foo/', '/bar/').should.eql(sep + 'foo' + sep + 'bar' + sep); |
| 41 | + }); |
| 42 | + |
| 43 | + it('mixed slashes', () => { |
| 44 | + join('foo/', '\\bar').should.eql('foo' + sep + 'bar'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('mixed and >2 slashes', () => { |
| 48 | + join('foo////', '\\\\bar').should.eql('foo' + sep + 'bar'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('mixed and >2 slashes - custom separator', () => { |
| 52 | + const custom = '\\'; |
| 53 | + join('foo////', '\\\\bar', { sep: custom }).should.eql('foo' + custom + 'bar'); |
| 54 | + }); |
| 55 | + |
| 56 | + it('three paths', () => { |
| 57 | + join('foo', 'bar', 'baz').should.eql('foo' + sep + 'bar' + sep + 'baz'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('three paths - custom separator', () => { |
| 61 | + const custom = '\\'; |
| 62 | + join('foo', 'bar', 'baz', { sep: custom }).should.eql('foo' + custom + 'bar' + custom + 'baz'); |
| 63 | + }); |
| 64 | +}); |
0 commit comments