forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDocumentationSamplesTest.java
More file actions
48 lines (40 loc) · 2.08 KB
/
DocumentationSamplesTest.java
File metadata and controls
48 lines (40 loc) · 2.08 KB
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
package com.github.copilot.sdk;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
class DocumentationSamplesTest {
private static final Pattern CREATE_SESSION_WITHOUT_PERMISSION = Pattern
.compile("createSession\\(\\s*new SessionConfig\\(\\)(?!\\.setOnPermissionRequest\\()", Pattern.DOTALL);
private static final Pattern RESUME_CONFIG_WITHOUT_PERMISSION = Pattern.compile(
"new ResumeSessionConfig\\(\\)(?!\\.setOnPermissionRequest\\()", Pattern.DOTALL);
private static final Pattern REMOVED_RESUME_OVERLOAD = Pattern
.compile("resumeSession\\([^,\\n\\)]*\\)\\.get\\(\\)");
@Test
void docsAndJbangSamplesUseRequiredPermissionHandler() throws IOException {
for (Path path : documentationFiles()) {
String content = Files.readString(path);
assertFalse(CREATE_SESSION_WITHOUT_PERMISSION.matcher(content).find(),
() -> path + " contains createSession sample without setOnPermissionRequest");
assertFalse(RESUME_CONFIG_WITHOUT_PERMISSION.matcher(content).find(),
() -> path + " contains ResumeSessionConfig sample without setOnPermissionRequest");
assertFalse(REMOVED_RESUME_OVERLOAD.matcher(content).find(),
() -> path + " contains removed resumeSession(String) overload");
}
}
private static List<Path> documentationFiles() throws IOException {
Path root = Path.of("").toAbsolutePath();
List<Path> files = new ArrayList<>();
files.add(root.resolve("README.md"));
files.add(root.resolve("jbang-example.java"));
try (Stream<Path> markdownFiles = Files.walk(root.resolve("src/site/markdown"))) {
markdownFiles.filter(Files::isRegularFile).filter(path -> path.toString().endsWith(".md")).forEach(files::add);
}
return files;
}
}