File: test-relpath.lua

package info (click to toggle)
lua-penlight 1.0.2%2Bhtmldoc-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,860 kB
  • sloc: makefile: 7
file content (21 lines) | stat: -rw-r--r-- 383 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
require 'pl'
relpath = path.relpath

path = '/a/b/c'

function slash (p)
    return (p:gsub('\\','/'))
end

function try (p,r)
    test.asserteq(slash(relpath(p,path)),r)
end

try('/a/b/c/one.lua','one.lua')
try('/a/b/c/bonzo/two.lua','bonzo/two.lua')
try('/a/b/three.lua','../three.lua')
try('/a/four.lua','../../four.lua')
try('one.lua','one.lua')
try('../two.lua','../two.lua')