Download: a.zip
\n" + + "\n\n"; + assertEquals( + "---\nlayout: default\n---\nDownload: a.zip
\n", + EisopSiteGenerator.themeShippedPage(html)); + } + + @Test + void themeShippedPageWithoutBodyTagsKeepsEverything() { + assertEquals( + "---\nlayout: default\n---\ntext
\n", + EisopSiteGenerator.themeShippedPage("text
")); + } + + @Test + void themeShippedPageKeepsTheVersionMarker() { + // The release scripts of the Checker Framework read the current version from this marker. + String marker = + "checker-framework-1.2.3.zip" + + ""; + String themed = + EisopSiteGenerator.themeShippedPage( + "" + marker + ""); + assertTrue(themed.contains(marker), themed); + } + + @Test + void templatesArePackaged() throws IOException { + String cf = EisopSiteGenerator.readTemplate("cf-template.md"); + assertTrue(cf.contains("$LatestCheckerFrameworkReleaseZip")); + assertTrue(cf.contains("$LatestAnnotationFileUtilitiesReleaseDownloadLink")); + String afu = EisopSiteGenerator.readTemplate("/afu-template.md"); + assertTrue(afu.contains("$LatestAnnotationFileUtilitiesReleaseZip")); + } + + @Test + void missingTemplateIsAnError() { + assertThrows(IOException.class, () -> EisopSiteGenerator.readTemplate("no-such.md")); + } + + @Test + void afuPlaceholdersAreFilledOnEveryReleasePage(@TempDir Path cfDir) throws IOException { + String page = + "[$LatestAnnotationFileUtilitiesReleaseZip]" + + "($LatestAnnotationFileUtilitiesReleaseDownloadLink)" + + " ($LatestAnnotationFileUtilitiesReleaseDate)\n"; + String filled = "[afu-1.zip](/afu/afu-1.zip) (May 1, 2026)\n"; + Path top = write(cfDir.resolve("index.md"), page); + Path release = write(cfDir.resolve("checker-framework-1/index.md"), page); + Path other = write(cfDir.resolve("checker-framework-1/other.md"), page); + + for (int run = 0; run < 2; run++) { + // The second run checks that the substitution is idempotent. + EisopSiteGenerator.substituteAfuPlaceholders( + cfDir.toFile(), "afu-1.zip", "/afu/afu-1.zip", "May 1, 2026"); + assertEquals(filled, read(top)); + assertEquals(filled, read(release)); + assertEquals(page, read(other)); + } + } + + @Test + void afuPlaceholdersToleratesMissingPages(@TempDir Path cfDir) throws IOException { + Files.createDirectories(cfDir.resolve("checker-framework-1")); + EisopSiteGenerator.substituteAfuPlaceholders( + cfDir.toFile(), "afu-1.zip", "/afu/afu-1.zip", "May 1, 2026"); + EisopSiteGenerator.substituteAfuPlaceholders( + new File(cfDir.toFile(), "missing"), "afu-1.zip", "/afu/afu-1.zip", "May 1, 2026"); + } + + private static Path write(Path file, String content) throws IOException { + Files.createDirectories(file.getParent()); + return Files.writeString(file, content, StandardCharsets.UTF_8); + } + + private static String read(Path file) throws IOException { + return Files.readString(file, StandardCharsets.UTF_8); + } +}