From 411b47ece334b772f672f5af0f21f2f1d3a8614d Mon Sep 17 00:00:00 2001 From: Nikifor Fedorov Date: Sun, 2 Jan 2022 22:03:27 +0300 Subject: [PATCH] #17 Ensure all TOC entries will be read Added integrity tests for chapters, general and conventions section Signed-off-by: Nikifor Fedorov --- .../tests/cxx14/ChaptersIntegrityTest.java | 39 ++++++++++++++ .../tests/cxx14/ConventionsIntegrityTest.java | 42 +++++++++++++++ .../tests/cxx14/Cxx14IntegrityTest.java | 51 +++++++++++++++++++ .../tests/cxx14/GeneralIntegrityTest.java | 42 +++++++++++++++ 4 files changed, 174 insertions(+) create mode 100644 tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ChaptersIntegrityTest.java create mode 100644 tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ConventionsIntegrityTest.java create mode 100644 tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/Cxx14IntegrityTest.java create mode 100644 tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/GeneralIntegrityTest.java diff --git a/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ChaptersIntegrityTest.java b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ChaptersIntegrityTest.java new file mode 100644 index 000000000..228fc9e29 --- /dev/null +++ b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ChaptersIntegrityTest.java @@ -0,0 +1,39 @@ +package ru.arsysop.loft.rgm.cxxdraft.tests.cxx14; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.eclipse.emf.common.util.EList; +import org.junit.Test; + +import ru.arsysop.loft.rgm.model.api.TocChapter; + +@SuppressWarnings("nls") +public final class ChaptersIntegrityTest extends Cxx14IntegrityTest { + + @Test + public void testChapters() { + EList chapters = document.getToc().getChapters(); + int visualizations = 2; + int numbered = 30; + int annexes = 5; + int indexes = 3; + int size = visualizations + numbered + annexes + indexes; + assertEquals(size, chapters.size()); + for (int i = visualizations; i < visualizations + numbered; i++) { + TocChapter chapter = chapters.get(i); + assertEquals(String.valueOf(i - 1), chapter.getNumber()); + } + for (int i = visualizations + numbered; i < visualizations + numbered + annexes; i++) { + TocChapter chapter = chapters.get(i); + String number = chapter.getNumber(); + assertTrue(number.startsWith("Annex")); + } + for (int i = size - indexes; i < size; i++) { + TocChapter chapter = chapters.get(i); + String name = chapter.getName().toLowerCase(); + assertTrue(name.contains("index")); + } + } + +} diff --git a/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ConventionsIntegrityTest.java b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ConventionsIntegrityTest.java new file mode 100644 index 000000000..571ae5ec9 --- /dev/null +++ b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ConventionsIntegrityTest.java @@ -0,0 +1,42 @@ +package ru.arsysop.loft.rgm.cxxdraft.tests.cxx14; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import ru.arsysop.loft.rgm.model.api.TocChapter; + +public class ConventionsIntegrityTest extends Cxx14IntegrityTest { + + private final TocChapter conventions = document.getToc().getChapters().get(3); + + @Test + public final void name() { + assertEquals("Lexical conventions", conventions.getName()); //$NON-NLS-1$ + } + + @Test + public final void count() { + int subchapters = 14; + assertEquals(subchapters, conventions.getChapters().size()); // $NON-NLS-1$ + for (int i = 0; i < subchapters; i++) { + TocChapter chapter = conventions.getChapters().get(i); + assertEquals(chapter(2, i + 1), chapter.getNumber()); + assertNotNull(chapter.getName()); + assertNotNull(chapter.getPart()); + } + } + + @Test + public final void literals() { + int paragraphs = 8; + for (int i = 0; i < paragraphs; i++) { + TocChapter paragraph = conventions.getChapters().get(13).getChapters().get(i); + assertEquals(paragraph(2, 14, i + 1), paragraph.getNumber()); + assertNotNull(paragraph.getName()); + assertNotNull(paragraph.getPart()); + } + } + +} diff --git a/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/Cxx14IntegrityTest.java b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/Cxx14IntegrityTest.java new file mode 100644 index 000000000..810fc9363 --- /dev/null +++ b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/Cxx14IntegrityTest.java @@ -0,0 +1,51 @@ +package ru.arsysop.loft.rgm.cxxdraft.tests.cxx14; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.junit.BeforeClass; + +import ru.arsysop.loft.rgm.cxxdraft.ResolutionContext; +import ru.arsysop.loft.rgm.cxxdraft.base.PublishedHtml; +import ru.arsysop.loft.rgm.cxxdraft.base.SimpleResolutionContext; +import ru.arsysop.loft.rgm.internal.cxxdraft.TocStructure; +import ru.arsysop.loft.rgm.model.api.Document; +import ru.arsysop.loft.rgm.model.meta.RgmFactory; + +public abstract class Cxx14IntegrityTest { + + protected static final Document document = RgmFactory.eINSTANCE.createDocument(); + + private static final String URL = "https://timsong-cpp.github.io/cppwp/n4140/"; //$NON-NLS-1$ + private static final ResolutionContext context = new SimpleResolutionContext(URL, document); + + @BeforeClass + public static void performParsing() throws CoreException { + document.setToc(RgmFactory.eINSTANCE.createToc()); + new PublishedHtml(// + context.location(document.getToc()), // + new TocStructure(document.getToc(), context)// + ).run(new NullProgressMonitor()); + } + + protected String chapter(int chapter, int subchapter) { + return new StringBuilder() // + .append(chapter).append(".") //$NON-NLS-1$ + .append(subchapter).toString(); + } + + protected String paragraph(int chapter, int subchapter, int paragraph) { + return new StringBuilder() // + .append(chapter).append(".") //$NON-NLS-1$ + .append(subchapter).append(".") //$NON-NLS-1$ + .append(paragraph).toString(); + } + + protected String subparagraph(int chapter, int subchapter, int paragraph, int subparagraph) { + return new StringBuilder() // + .append(chapter).append(".") //$NON-NLS-1$ + .append(subchapter).append(".") //$NON-NLS-1$ + .append(paragraph).append(".") //$NON-NLS-1$ + .append(subparagraph).toString(); + } + +} diff --git a/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/GeneralIntegrityTest.java b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/GeneralIntegrityTest.java new file mode 100644 index 000000000..05b27efe5 --- /dev/null +++ b/tests/ru.arsysop.loft.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/GeneralIntegrityTest.java @@ -0,0 +1,42 @@ +package ru.arsysop.loft.rgm.cxxdraft.tests.cxx14; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +import ru.arsysop.loft.rgm.model.api.TocChapter; + +public final class GeneralIntegrityTest extends Cxx14IntegrityTest { + + private final TocChapter general = document.getToc().getChapters().get(2); + + @Test + public final void name() { + assertEquals("General", general.getName()); //$NON-NLS-1$ + } + + @Test + public final void count() { + int subchapters = 11; + assertEquals(subchapters, general.getChapters().size()); // $NON-NLS-1$ + for (int i = 0; i < subchapters; i++) { + TocChapter chapter = general.getChapters().get(i); + assertEquals(chapter(1, i + 1), chapter.getNumber()); + assertNotNull(chapter.getName()); + assertNotNull(chapter.getPart()); + } + } + + @Test + public final void terms() { + int paragraphs = 26; + for (int i = 0; i < paragraphs; i++) { + TocChapter paragraph = general.getChapters().get(2).getChapters().get(i); + assertEquals(paragraph(1, 3, i + 1), paragraph.getNumber()); + assertNotNull(paragraph.getName()); + assertNotNull(paragraph.getPart()); + } + } + +}