[FOray-commit] SF.net SVN: foray:[12142] trunk/foray/foray-common
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-11-27 19:44:56
|
Revision: 12142
http://sourceforge.net/p/foray/code/12142
Author: victormote
Date: 2021-11-27 19:44:54 +0000 (Sat, 27 Nov 2021)
Log Message:
-----------
Add test class for "iteration" of ParaBranch4a.
Modified Paths:
--------------
trunk/foray/foray-common/build.gradle
trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java
Added Paths:
-----------
trunk/foray/foray-common/src/test/java/org/foray/common/para/
trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
Modified: trunk/foray/foray-common/build.gradle
===================================================================
--- trunk/foray/foray-common/build.gradle 2021-11-27 14:56:10 UTC (rev 12141)
+++ trunk/foray/foray-common/build.gradle 2021-11-27 19:44:54 UTC (rev 12142)
@@ -15,6 +15,7 @@
implementation group: 'ch.qos.logback', name: 'logback-classic', version: logbackClassicVersion
testImplementation group: 'junit', name: 'junit', version: junitVersion
+ testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion
}
javadoc {
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java 2021-11-27 14:56:10 UTC (rev 12141)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/DiscretionaryHyphen4a.java 2021-11-27 19:44:54 UTC (rev 12142)
@@ -42,16 +42,25 @@
*/
public final class DiscretionaryHyphen4a extends ParaLeaf4a implements DiscretionaryHyphen {
+ /** Pre-built "acceptable" hyphenation point. */
+ public static final DiscretionaryHyphen4a ACCEPTABLE =
+ new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.ACCEPTABLE);
+
+ /** Pre-built "good" hyphenation point. */
+ public static final DiscretionaryHyphen4a GOOD =
+ new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.GOOD);
+
+ /** Pre-built "best" hyphenation point. */
+ public static final DiscretionaryHyphen4a BEST =
+ new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.BEST);
+
/** The array of pre-constructed instance, indexed by the numeric value of their quality minus 1. */
private static final DiscretionaryHyphen4a[] PRE_CONSTRUCTED_POINTS =
new DiscretionaryHyphen4a[DiscretionaryHyphen.Quality.values().length];
static {
- PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.ACCEPTABLE.getNumericValue() - 1] =
- new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.ACCEPTABLE);
- PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.GOOD.getNumericValue() - 1] =
- new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.GOOD);
- PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.BEST.getNumericValue() - 1] =
- new DiscretionaryHyphen4a(DiscretionaryHyphen.Quality.BEST);
+ PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.ACCEPTABLE.getNumericValue() - 1] = ACCEPTABLE;
+ PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.GOOD.getNumericValue() - 1] = GOOD;
+ PRE_CONSTRUCTED_POINTS[DiscretionaryHyphen.Quality.BEST.getNumericValue() - 1] = BEST;
}
/** The quality for this instance. */
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java 2021-11-27 14:56:10 UTC (rev 12141)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/para/ParaGlueChars.java 2021-11-27 19:44:54 UTC (rev 12142)
@@ -40,7 +40,10 @@
*/
public final class ParaGlueChars extends ParaLeaf4a implements ParaGlue {
- /** The char(s) for this penalty. */
+ /** Reusable glue item representing a single space character. */
+ public static final ParaGlueChars SPACE = new ParaGlueChars(" ");
+
+ /** The char(s) for this glue. */
private String chars;
/**
Added: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
===================================================================
--- trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java (rev 0)
+++ trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java 2021-11-27 19:44:54 UTC (rev 12142)
@@ -0,0 +1,121 @@
+/*
+ * Copyright 2021 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision$
+ * $LastChangedDate$
+ * $LastChangedBy$
+ */
+
+package org.foray.common.para;
+
+import org.axsl.common.para.ParaConfig;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ * Tests of {@Link ParaBranch4a}.
+ */
+public class ParaBranch4aTests {
+
+ /**
+ * Test of {@link ParaBranch4a#paraLeafAt(int)}.
+ */
+ @Test
+ public void test() {
+ /*
+ * Be not afraid of greatness. Some are born great, some achieve greatness, and some have greatness thrust upon
+ * them.
+ * -- William Shakespeare, "Twelfth Night"
+ */
+
+ final ParaConfig config = Mockito.mock(ParaConfig.class);
+ final ParaBranch4a out = new ParaBranch4a(config);
+ final ParaBranch4a greatness = new ParaBranch4a(config);
+ greatness.add(new ParaBoxChars("great"));
+ greatness.add(DiscretionaryHyphen4a.GOOD);
+ greatness.add(new ParaBoxChars("ness"));
+
+ out.add(new ParaBoxChars("Be")); // Node 0, Leaf 0
+ out.add(ParaGlueChars.SPACE); // Node 1, Leaf 1
+ out.add(new ParaBoxChars("not")); // Node 2, Leaf 2
+ out.add(ParaGlueChars.SPACE); // Node 3, Leaf 3
+ out.add(new ParaBoxChars("afraid")); // Node 4, Leaf 4
+ out.add(ParaGlueChars.SPACE); // Node 5, Leaf 5
+ out.add(new ParaBoxChars("of")); // Node 6, Leaf 6
+ out.add(ParaGlueChars.SPACE); // Node 7, Leaf 7
+ out.add(greatness); // Node 8, Leaf 8 - 10
+ out.add(new ParaBoxChars(".")); // Node 9, Leaf 11
+ out.add(ParaGlueChars.SPACE); // Node 10, Leaf 12
+ out.add(new ParaBoxChars("Some")); // Node 11, Leaf 13
+ out.add(ParaGlueChars.SPACE); // Node 12, Leaf 14
+ out.add(new ParaBoxChars("are")); // Node 13, Leaf 15
+ out.add(ParaGlueChars.SPACE); // Node 14, Leaf 16
+ out.add(new ParaBoxChars("born")); // Node 15, Leaf 17
+ out.add(ParaGlueChars.SPACE); // Node 16, Leaf 18
+ out.add(new ParaBoxChars("great,")); // Node 17, Leaf 19
+ out.add(ParaGlueChars.SPACE); // Node 28, Leaf 20
+ out.add(new ParaBoxChars("some")); // Node 29, Leaf 21
+ out.add(ParaGlueChars.SPACE); // Node 20, Leaf 22
+ out.add(new ParaBoxChars("achieve")); // Node 21, Leaf 23
+ out.add(ParaGlueChars.SPACE); // Node 22, Leaf 24
+ out.add(greatness); // Node 23, Leaf 25 - 27
+ out.add(new ParaBoxChars(",")); // Node 24, Leaf 28
+ out.add(ParaGlueChars.SPACE); // Node 25, Leaf 29
+ out.add(new ParaBoxChars("and")); // Node 26, Leaf 30
+ out.add(ParaGlueChars.SPACE); // Node 27, Leaf 31
+ out.add(new ParaBoxChars("some")); // Node 28, Leaf 32
+ out.add(ParaGlueChars.SPACE); // Node 29, Leaf 33
+ out.add(new ParaBoxChars("have")); // Node 30, Leaf 34
+ out.add(ParaGlueChars.SPACE); // Node 31, Leaf 35
+ out.add(greatness); // Node 32, Leaf 36 - 38
+ out.add(ParaGlueChars.SPACE); // Node 33, Leaf 39
+ out.add(new ParaBoxChars("thrust")); // Node 34, Leaf 40
+ out.add(ParaGlueChars.SPACE); // Node 35, Leaf 41
+ out.add(new ParaBoxChars("upon")); // Node 36, Leaf 42
+ out.add(ParaGlueChars.SPACE); // Node 37, Leaf 43
+ out.add(new ParaBoxChars("them.")); // Node 38, Leaf 44
+
+ /* 39 lines, each adding one node. */
+ Assert.assertEquals(39, out.paraNodeSize());
+
+ /* Test the /nodes/ at each end, and one in the middle. */
+ Assert.assertEquals("Be", out.paraNodeAt(0).asParaLeaf().getText());
+ Assert.assertEquals("them.", out.paraNodeAt(38).asParaLeaf().getText());
+ Assert.assertEquals("born", out.paraNodeAt(15).asParaLeaf().getText());
+
+ /* Most nodes are exactly one leaf. 3 lines each add an additional 2 leaves each, adding 6 leaves. */
+ Assert.assertEquals(45, out.paraLeafSize());
+
+ /* Test the /leaves/ at each end. */
+ Assert.assertEquals("Be", out.paraLeafAt(0).getText());
+ Assert.assertEquals("them.", out.paraLeafAt(44).getText());
+
+ /* Make sure the nested branches can find their child nodes properly. */
+ Assert.assertEquals("great", out.paraLeafAt(8).getText());
+// Assert.assertEquals("-", out.paraLeafAt(9).getText());
+// Assert.assertEquals("ness", out.paraLeafAt(10).getText());
+ }
+
+}
Property changes on: trunk/foray/foray-common/src/test/java/org/foray/common/para/ParaBranch4aTests.java
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Rev
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|