Skip to content

Commit 6d1690b

Browse files
committed
fix examples
¯\_(ツ)_/¯
1 parent 7a39423 commit 6d1690b

File tree

3 files changed

+40
-14
lines changed

3 files changed

+40
-14
lines changed

composer.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/hh-apidoc-extensions/PageSections/Examples.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,20 @@
1818
final class Examples extends PageSection {
1919
<<__Override>>
2020
public function getMarkdown(): ?string {
21-
$path = LocalConfig::ROOT.'/api-examples/';
2221
if ($this->parent !== null) {
23-
$path .= 'class.'.$this->parent->getName().'/';
22+
$subdirectory = 'class.'.$this->parent->getName().'/';
2423
} else {
25-
$path .= 'function';
24+
$subdirectory = 'function.';
2625
}
27-
$path .= Str\replace(
28-
$this->definition->getName(),
29-
"\\",
30-
'.',
26+
$subdirectory .= $this->definition->getName();
27+
28+
$path = Str\format(
29+
'%s/api-examples/%s',
30+
LocalConfig::ROOT,
31+
Str\replace($subdirectory, '\\', '.'),
3132
);
3233

33-
$examples = Vec\concat(\glob($path.'/*.php'), \glob($path.'/*.php'))
34+
$examples = Vec\concat(\glob($path.'/*.md'), \glob($path.'/*.php'))
3435
|> Vec\map($$, $file ==> \pathinfo($file, \PATHINFO_FILENAME))
3536
|> keyset($$);
3637

tests/APIPagesTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
APIDefinitionType,
77
APINavData,
88
APIProduct,
9+
LocalConfig,
910
NavDataNode,
1011
URLBuilder,
1112
};
1213

13-
use namespace HH\Lib\Vec;
14+
use namespace HH\Lib\{Str, Vec};
1415
use function Facebook\FBExpect\expect;
1516
use type Facebook\HackTest\{DataProvider, TestGroup};
1617

@@ -143,4 +144,28 @@ public function getDoNotDocument(): vec<(string, APIDefinitionType)> {
143144
\sprintf('"%s" should not be documented', $name),
144145
);
145146
}
147+
148+
public function getPagesWithExamples(): vec<vec<string>> {
149+
$root = LocalConfig::ROOT.'/api-examples';
150+
$urls = keyset[];
151+
foreach (\glob($root.'/class.*/*') as $dir) {
152+
if (!\is_dir($dir)) {
153+
continue;
154+
}
155+
$urls[] = Str\replace($dir, $root.'/class.', 'class/');
156+
}
157+
foreach (\glob($root.'/function.*') as $dir) {
158+
$urls[] = Str\replace($dir, $root.'/function.', 'function/');
159+
}
160+
return Vec\map($urls, $url ==> vec['/hack/reference/'.$url.'/']);
161+
}
162+
163+
<<DataProvider('getPagesWithExamples')>>
164+
public async function testExamples(string $url): Awaitable<void> {
165+
list($response, $body) = await PageLoader::getPageAsync($url);
166+
expect($response->getStatusCode())
167+
->toBeSame(200, 'Examples provided for non-existent page %s.', $url);
168+
expect(Str\contains($body, '<a href="#examples">'))
169+
->toBeTrue('Missing examples at %s.', $url);
170+
}
146171
}

0 commit comments

Comments
 (0)