@@ -101,4 +101,95 @@ def test_is_external_link(self):
101101 self .assertEqual (False , is_external_link ('ahttp://a' ))
102102 self .assertEqual (False , is_external_link (' http://a' ))
103103
104-
104+ class TestPlaceholderLinks (unittest .TestCase ):
105+ def test_is_ranges_placeholder (self ):
106+ match = [
107+ 'http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
108+ 'http://en.cppreference.com/w/cpp/ranges-placeholder/iterator/Incrementable' ,
109+ 'http://en.cppreference.com/w/cpp/ranges-algorithm-placeholder/all_any_none_of' ,
110+ 'http://en.cppreference.com/w/cpp/ranges-iterator-placeholder/dangling' ,
111+ 'http://en.cppreference.com/w/cpp/ranges-utility-placeholder/swap' ,
112+ ]
113+ for target in match :
114+ self .assertTrue (is_ranges_placeholder (target ),
115+ msg = "Should match '{}'" .format (target ))
116+
117+ target = target .replace ("http://" , "https://" )
118+ self .assertTrue (is_ranges_placeholder (target ),
119+ msg = "Should match '{}'" .format (target ))
120+
121+ nomatch = [
122+ 'http://en.cppreference.com/w/cpp/ranges--placeholder/swap' ,
123+ 'https://en.cppreference.com/w/cpp/ranges--placeholder/swap' ,
124+ 'http://www.mediawiki.org/' ,
125+ 'http://en.cppreference.com/w/Cppreference:About' ,
126+ 'http://en.wikipedia.org/wiki/Normal_distribution' ,
127+ 'https://www.mediawiki.org/' ,
128+ 'https://en.cppreference.com/w/Cppreference:About' ,
129+ 'https://en.wikipedia.org/wiki/Normal_distribution' ,
130+ 'w/cpp.html' ,
131+ 'w/cpp/language/expressions.html' ,
132+ '../utility/functional/is_placeholder.html' ,
133+ 'utility/functional/placeholders.html' ,
134+ 'w/cpp/experimental/ranges.html' ,
135+ ]
136+ for target in nomatch :
137+ self .assertFalse (is_ranges_placeholder (target ),
138+ msg = "Should not match '{}'" .format (target ))
139+
140+ def test_transform_ranges_placeholder (self ):
141+ entries = [
142+ # (target, file, expected)
143+ ('http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
144+ 'output/reference/en/cpp/concepts/ConvertibleTo.html' ,
145+ 'Assignable.html' ),
146+
147+ ('http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
148+ 'output/reference/en/cpp/concepts/long/path/ConvertibleTo.html' ,
149+ '../../Assignable.html' ),
150+
151+ ('http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
152+ 'output/reference/en/cpp/other/path/ConvertibleTo.html' ,
153+ '../../concepts/Assignable.html' ),
154+
155+ ('http://en.cppreference.com/w/cpp/ranges-algorithm-placeholder/all_any_none_of' ,
156+ 'output/reference/en/cpp/concepts/ConvertibleTo.html' ,
157+ '../algorithm/ranges/all_any_none_of.html' ),
158+
159+ ('http://en.cppreference.com/w/cpp/ranges-algorithm-placeholder/all_any_none_of' ,
160+ 'output/reference/en/cpp/algorithm/ConvertibleTo.html' ,
161+ 'ranges/all_any_none_of.html' ),
162+
163+ ('http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
164+ 'output/reference/en/cpp/experimental/ranges/concepts/View.html' ,
165+ 'Assignable.html' ),
166+
167+ ('http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
168+ 'output/reference/en/cpp/experimental/ranges/View.html' ,
169+ 'concepts/Assignable.html' ),
170+
171+ ('http://en.cppreference.com/w/cpp/ranges-placeholder/concepts/Assignable' ,
172+ 'output/reference/en/cpp/experimental/ranges/range/View.html' ,
173+ '../concepts/Assignable.html' ),
174+
175+ ('http://en.cppreference.com/w/cpp/ranges-algorithm-placeholder/all_any_none_of' ,
176+ 'output/reference/en/cpp/experimental/ranges/View.html' ,
177+ 'algorithm/all_any_none_of.html' ),
178+
179+ ('http://en.cppreference.com/w/cpp/ranges-algorithm-placeholder/all_any_none_of' ,
180+ 'output/reference/en/cpp/experimental/ranges/range/View.html' ,
181+ '../algorithm/all_any_none_of.html' ),
182+ ]
183+
184+ # transform_ranges_placeholder(target, file, root)
185+ # target: the placeholder link
186+ # file: path of the file that contains the link
187+ # root: path to the site root (where '/' should link to)
188+ root = "output/reference"
189+ for target , file , expected in entries :
190+ self .assertEqual (expected , transform_ranges_placeholder (target , file , root ),
191+ msg = "target='{}', file='{}', root='{}'" .format (target , file , root ))
192+
193+ target = target .replace ('http://' , 'https://' )
194+ self .assertEqual (expected , transform_ranges_placeholder (target , file , root ),
195+ msg = "target='{}', file='{}', root='{}'" .format (target , file , root ))
0 commit comments