forked from llvm/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorSlugTestCase.php
98 lines (89 loc) · 2.73 KB
/
PhabricatorSlugTestCase.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
final class PhabricatorSlugTestCase extends PhabricatorTestCase {
public function testSlugNormalization() {
$slugs = array(
'' => '/',
'/' => '/',
'//' => '/',
'&&&' => '_/',
'/derp/' => 'derp/',
'derp' => 'derp/',
'derp//derp' => 'derp/derp/',
'DERP//DERP' => 'derp/derp/',
'a B c' => 'a_b_c/',
'-1~2.3abcd' => '-1~2.3abcd/',
"T\x00O\x00D\x00O" => 't_o_d_o/',
'x#%&+=\\?<> y' => 'x_y/',
"\xE2\x98\x83" => "\xE2\x98\x83/",
'..' => 'dotdot/',
'../' => 'dotdot/',
'/../' => 'dotdot/',
'a/b' => 'a/b/',
'a//b' => 'a/b/',
'a/../b/' => 'a/dotdot/b/',
'/../a' => 'dotdot/a/',
'../a' => 'dotdot/a/',
'a/..' => 'a/dotdot/',
'a/../' => 'a/dotdot/',
'a?' => 'a/',
'??' => '_/',
'a/?' => 'a/_/',
'??/a/??' => '_/a/_/',
'a/??/c' => 'a/_/c/',
'a/?b/c' => 'a/b/c/',
'a/b?/c' => 'a/b/c/',
'a - b' => 'a_-_b/',
'a[b]' => 'a_b/',
'ab!' => 'ab!/',
);
foreach ($slugs as $slug => $normal) {
$this->assertEqual(
$normal,
PhabricatorSlug::normalize($slug),
pht("Normalization of '%s'", $slug));
}
}
public function testProjectSlugs() {
$slugs = array(
'a:b' => 'a_b',
'a!b' => 'a_b',
'a - b' => 'a_-_b',
'' => '',
'Demonology: HSA (Hexes, Signs, Alchemy)' =>
'demonology_hsa_hexes_signs_alchemy',
);
foreach ($slugs as $slug => $normal) {
$this->assertEqual(
$normal,
PhabricatorSlug::normalizeProjectSlug($slug),
pht('Hashtag normalization of "%s"', $slug));
}
}
public function testSlugAncestry() {
$slugs = array(
'/' => array(),
'pokemon/' => array('/'),
'pokemon/squirtle/' => array('/', 'pokemon/'),
);
foreach ($slugs as $slug => $ancestry) {
$this->assertEqual(
$ancestry,
PhabricatorSlug::getAncestry($slug),
pht("Ancestry of '%s'", $slug));
}
}
public function testSlugDepth() {
$slugs = array(
'/' => 0,
'a/' => 1,
'a/b/' => 2,
'a////b/' => 2,
);
foreach ($slugs as $slug => $depth) {
$this->assertEqual(
$depth,
PhabricatorSlug::getDepth($slug),
pht("Depth of '%s'", $slug));
}
}
}