-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#17 Ensure all TOC entries will be read
Added integrity tests for chapters, general and conventions section Signed-off-by: Nikifor Fedorov <[email protected]>
- Loading branch information
1 parent
447f44d
commit 411b47e
Showing
4 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
...gm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ChaptersIntegrityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TocChapter> 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")); | ||
} | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/ConventionsIntegrityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
|
||
} |
51 changes: 51 additions & 0 deletions
51
...t.rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/Cxx14IntegrityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...rgm.cxxdraft.tests/src/ru/arsysop/loft/rgm/cxxdraft/tests/cxx14/GeneralIntegrityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
|
||
} |