@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class ProjectRemarkupRuleTestCase extends PhabricatorTestCase {
4
5 public function testProjectObjectRemarkup() {
6 $cases = array(
7 'I like #ducks.' => array(
8 'embed' => array(),
9 'ref' => array(
10 array(
11 'offset' => 8,
12 'id' => 'ducks',
13 ),
14 ),
15 ),
16 'We should make a post on #blog.example.com tomorrow.' => array(
17 'embed' => array(),
18 'ref' => array(
19 array(
20 'offset' => 26,
21 'id' => 'blog.example.com',
22 ),
23 ),
24 ),
25 'We should make a post on #blog.example.com.' => array(
26 'embed' => array(),
27 'ref' => array(
28 array(
29 'offset' => 26,
30 'id' => 'blog.example.com',
31 ),
32 ),
33 ),
34 '#123' => array(
35 'embed' => array(),
36 'ref' => array(
37 array(
38 'offset' => 1,
39 'id' => '123',
40 ),
41 ),
42 ),
43 '#2x4' => array(
44 'embed' => array(),
45 'ref' => array(
46 array(
47 'offset' => 1,
48 'id' => '2x4',
49 ),
50 ),
51 ),
52 '#security#123' => array(
53 'embed' => array(),
54 'ref' => array(
55 array(
56 'offset' => 1,
57 'id' => 'security',
58 'tail' => '123',
59 ),
60 ),
61 ),
62
63 // Don't match a terminal parenthesis. This fixes these constructs in
64 // natural language.
65 'There is some documentation (see #guides).' => array(
66 'embed' => array(),
67 'ref' => array(
68 array(
69 'offset' => 34,
70 'id' => 'guides',
71 ),
72 ),
73 ),
74
75 // Don't match internal parentheses either. This makes the terminal
76 // parenthesis behavior less arbitrary (otherwise, we match open
77 // parentheses but not closing parentheses, which is surprising).
78 '#a(b)c' => array(
79 'embed' => array(),
80 'ref' => array(
81 array(
82 'offset' => 1,
83 'id' => 'a',
84 ),
85 ),
86 ),
87
88 '#s3' => array(
89 'embed' => array(),
90 'ref' => array(
91 array(
92 'offset' => 1,
93 'id' => 's3',
94 ),
95 ),
96 ),
97
98 'Is this #urgent?' => array(
99 'embed' => array(),
100 'ref' => array(
101 array(
102 'offset' => 9,
103 'id' => 'urgent',
104 ),
105 ),
106 ),
107
108 'This is "#urgent".' => array(
109 'embed' => array(),
110 'ref' => array(
111 array(
112 'offset' => 10,
113 'id' => 'urgent',
114 ),
115 ),
116 ),
117
118 "This is '#urgent'." => array(
119 'embed' => array(),
120 'ref' => array(
121 array(
122 'offset' => 10,
123 'id' => 'urgent',
124 ),
125 ),
126 ),
127
128 '**#orbital**' => array(
129 'embed' => array(),
130 'ref' => array(
131 array(
132 'offset' => 3,
133 'id' => 'orbital',
134 ),
135 ),
136 ),
137
138 // This test case failed in an old version of the regex
139 '#js-draw' => array(
140 'embed' => array(),
141 'ref' => array(
142 array(
143 'offset' => 1,
144 'id' => 'js-draw',
145 ),
146 ),
147 ),
148 // Don't match leading dots for consistency with trailing ones
149 '#.js' => array(
150 'embed' => array(),
151 'ref' => array(),
152 ),
153 );
154
155 foreach ($cases as $input => $expect) {
156 $rule = new ProjectRemarkupRule();
157 $matches = $rule->extractReferences($input);
158 $this->assertEqual($expect, $matches, $input);
159 }
160 }
161
162}