changeset 2743:7bfe80df6772

merge main
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Tue, 21 Aug 2007 15:47:56 +0200
parents 0f16bcbc0344 (current diff) c6b5c2d813b6 (diff)
children e931f45fec3a
files MoinMoin/_tests/test_wikiutil.py MoinMoin/wikiutil.py
diffstat 2 files changed, 29 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/_tests/test_wikiutil.py	Tue Aug 21 14:53:12 2007 +0200
+++ b/MoinMoin/_tests/test_wikiutil.py	Tue Aug 21 15:47:56 2007 +0200
@@ -712,4 +712,25 @@
         encoded = wikiutil.anchor_name_from_text(text)
         assert expected == encoded
 
+class TestRelativeTools:
+    def test_abs_pagename(self):
+        tests = [
+            # test                      expected output
+            # CHILD_PREFIX
+            (('MainPage', '/SubPage1'), 'MainPage/SubPage1'),
+            (('MainPage', '/SubPage1/SubPage2'), 'MainPage/SubPage1/SubPage2'),
+            (('MainPage/SubPage1', '/SubPage2/SubPage3'), 'MainPage/SubPage1/SubPage2/SubPage3'),
+            (('', '/OtherMainPage'), 'OtherMainPage'), # strange
+            # PARENT_PREFIX
+            (('MainPage/SubPage', '../SisterPage'), 'MainPage/SisterPage'),
+            (('MainPage/SubPage1/SubPage2', '../SisterPage'), 'MainPage/SubPage1/SisterPage'),
+            (('MainPage/SubPage1/SubPage2', '../../SisterPage'), 'MainPage/SisterPage'),
+            (('MainPage', '../SisterPage'), 'SisterPage'), # strange
+        ]
+        for test, expected in tests:
+            yield self._check_abs_pagename, test, expected
+
+    def _check_abs_pagename(self, test, expected):
+        assert expected == wikiutil.AbsPageName(None, *test)
+
 coverage_modules = ['MoinMoin.wikiutil']
--- a/MoinMoin/wikiutil.py	Tue Aug 21 14:53:12 2007 +0200
+++ b/MoinMoin/wikiutil.py	Tue Aug 21 15:47:56 2007 +0200
@@ -844,9 +844,15 @@
     @return: the absolute page name
     """
     if pagename.startswith(PARENT_PREFIX):
-        pagename = '/'.join([x for x in context.split('/')[:-1] + [pagename[PARENT_PREFIX_LEN:]] if x])
+        while context and pagename.startswith(PARENT_PREFIX):
+            context = '/'.join(context.split('/')[:-1])
+            pagename = pagename[PARENT_PREFIX_LEN:]
+        pagename = '/'.join(filter(None, [ context, pagename, ]))
     elif pagename.startswith(CHILD_PREFIX):
-        pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
+        if context:
+            pagename = context + '/' + pagename[CHILD_PREFIX_LEN:]
+        else:
+            pagename = pagename[CHILD_PREFIX_LEN:]
     return pagename
 
 def pagelinkmarkup(pagename):