Remove state from test and added more adapters
This commit is contained in:
parent
95eeb90ccd
commit
0c4040b9d3
|
@ -31,4 +31,15 @@ public interface FourCornerZion7AlphaOmega extends FourCornerZion7Candlelier {
|
|||
void strobeDocumentAlpha();
|
||||
|
||||
void strobeDocumentOmega();
|
||||
|
||||
interface Adapter extends FourCornerZion7AlphaOmega, FourCornerZion7Candlelier.Adapter {
|
||||
|
||||
@Override
|
||||
default void strobeDocumentAlpha() {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void strobeDocumentOmega() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
|||
/// @version 1.0 Jan 09, 2025
|
||||
public class FourCornerZionStenoLexer {
|
||||
|
||||
private final static FourCornerZion7AlphaOmega CLEAN_BIBLE = new FourCornerZion7AlphaOmega.Adapter() {};
|
||||
private final static FourCornerZionStenoLexerFire CLEAN_FIRE = new FourCornerZionStenoLexerFire.Adapter() {};
|
||||
private final static FourCornerZionStenoLexerSmoke CLEAN_SMOKE = new FourCornerZionStenoLexerSmoke.Adapter() {};
|
||||
private final boolean handlerEscape;
|
||||
private final FourCornerZion7Candlelier handler;
|
||||
private final FourCornerZion7AlphaOmega handlerDocument;
|
||||
|
@ -49,8 +52,8 @@ public class FourCornerZionStenoLexer {
|
|||
private Integer cakePoint = null;
|
||||
private int currLine = 0;
|
||||
private int currCol = 0;
|
||||
private FourCornerZionStenoLexerSmoke smokeSignals;
|
||||
private FourCornerZionStenoLexerFire fireSignals;
|
||||
private FourCornerZionStenoLexerSmoke smokeSignals = CLEAN_SMOKE;
|
||||
private FourCornerZionStenoLexerFire fireSignals = CLEAN_FIRE;
|
||||
|
||||
public FourCornerZionStenoLexer(FourCornerZion7Candlelier handler) {
|
||||
this(handler, true);
|
||||
|
@ -62,7 +65,7 @@ public class FourCornerZionStenoLexer {
|
|||
if (handler instanceof FourCornerZion7AlphaOmega) {
|
||||
this.handlerDocument = FourCornerZion7AlphaOmega.class.cast(handler);
|
||||
} else {
|
||||
this.handlerDocument = null;
|
||||
this.handlerDocument = CLEAN_BIBLE;
|
||||
}
|
||||
if (handler instanceof FourCornerZion7SalahSequence) {
|
||||
this.handlerSalahSequence = FourCornerZion7SalahSequence.class.cast(handler);
|
||||
|
@ -105,12 +108,12 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
|
||||
public FourCornerZionStenoLexer withSmokeSignals(FourCornerZionStenoLexerSmoke smokeSignals) {
|
||||
this.smokeSignals = smokeSignals;
|
||||
this.smokeSignals = Objects.requireNonNull(smokeSignals);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FourCornerZionStenoLexer withFireSignals(FourCornerZionStenoLexerFire fireSignals) {
|
||||
this.fireSignals = fireSignals;
|
||||
this.fireSignals = Objects.requireNonNull(fireSignals);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -139,19 +142,15 @@ public class FourCornerZionStenoLexer {
|
|||
Iterator<Integer> input = Objects.requireNonNull(points);
|
||||
readLevel++; // first puts on one, we allow level deep
|
||||
if (readLevel > 2) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnRecursive(currLine, currCol);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (readLevel == 1) {
|
||||
this.cakePoint = null; // allow reuse of lexer
|
||||
this.currLine = 0;
|
||||
this.currCol = 0;
|
||||
if (handlerDocument != null) {
|
||||
cakePoint = null; // allow reuse of lexer
|
||||
currLine = 0;
|
||||
currCol = 0;
|
||||
handlerDocument.strobeDocumentAlpha();
|
||||
}
|
||||
}
|
||||
while (input.hasNext()) {
|
||||
if (safeNext(input).isEOF()) {
|
||||
break;
|
||||
|
@ -163,11 +162,9 @@ public class FourCornerZionStenoLexer {
|
|||
if (run.isEOF()) {
|
||||
break;
|
||||
}
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnUnsupported(currLine, currCol, cakePoint);
|
||||
}
|
||||
}
|
||||
if (handlerDocument != null && readLevel == 1) {
|
||||
if (readLevel == 1) {
|
||||
handlerDocument.strobeDocumentOmega();
|
||||
}
|
||||
readLevel--;
|
||||
|
@ -193,9 +190,7 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
cakePoint = input.next();
|
||||
currCol++;
|
||||
if (fireSignals != null) {
|
||||
fireSignals.fireStateColumn(currCol);
|
||||
}
|
||||
return ScanResult.DONE;
|
||||
}
|
||||
|
||||
|
@ -310,7 +305,6 @@ public class FourCornerZionStenoLexer {
|
|||
errorZeroSparks = false;
|
||||
errorUnusedSparks = false;
|
||||
}
|
||||
if (smokeSignals != null) {
|
||||
if (errorZeroSparks) {
|
||||
smokeSignals.burnNCR1632ZeroSparks(currLine, currCol);
|
||||
} else if (errorUnusedSparks) {
|
||||
|
@ -318,7 +312,6 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class StenoScannerUNI21 implements StenoScanner {
|
||||
|
||||
|
@ -350,7 +343,7 @@ public class FourCornerZionStenoLexer {
|
|||
result.add(codePoint);
|
||||
errorUnusedBigIndian = false;
|
||||
}
|
||||
if (smokeSignals != null && errorUnusedBigIndian) {
|
||||
if (errorUnusedBigIndian) {
|
||||
smokeSignals.burnUNI21UnusedBigIndian(currLine, currCol);
|
||||
}
|
||||
handler.strobeUnicode(result);
|
||||
|
@ -386,11 +379,9 @@ public class FourCornerZionStenoLexer {
|
|||
if (FCDotCDC1604DashP6._NEWLINE.ordinal() == muffinPoint) {
|
||||
currLine++;
|
||||
currCol = 0;
|
||||
if (fireSignals != null) {
|
||||
fireSignals.fireStateLine(currLine);
|
||||
fireSignals.fireStateColumn(currCol);
|
||||
}
|
||||
}
|
||||
// Handle 8 and 18 bit direct cake points
|
||||
if (FourCornerDotCake.FC_APL0127_P7A.contains(muffinPoint)) {
|
||||
handler.strobeWords(FourCornerDotCake.FC_APL0127_P7A, List.of(muffinPoint - FourCornerDotCake.FC_APL0127_P7A.getStart()));
|
||||
|
@ -417,9 +408,7 @@ public class FourCornerZionStenoLexer {
|
|||
continue;
|
||||
}
|
||||
if (FourCornerDotCake.__MIND_THE_GAP.contains(muffinPoint)) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnUnsupported(currLine, currCol, cakePoint);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -478,9 +467,7 @@ public class FourCornerZionStenoLexer {
|
|||
numberMode = null; // out of range, thus stop
|
||||
decMode = readEscape6(cdc, cdcPoint);
|
||||
if (decMode == null) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (decMode == FCDotDEC0127DashPX0.ESC68_PIE || decMode == FCDotDEC0127DashPX0.ESC68_NCR) {
|
||||
|
@ -555,9 +542,7 @@ public class FourCornerZionStenoLexer {
|
|||
if (numberMode == null) {
|
||||
Optional<FourCornerDotCake> slice = FourCornerDotCake.valueFromCakePoint(cdcPoint);
|
||||
if (slice.isEmpty()) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnUnsupported(currLine, currCol, cdcPoint);
|
||||
}
|
||||
return;
|
||||
}
|
||||
handler.strobeWords(slice.get(), List.of(cdcPoint));
|
||||
|
@ -584,9 +569,7 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
if (salahMode.equals(decMode)) {
|
||||
if (salahMode.name().startsWith("__")) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnInvalidSalah(currLine, currCol);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
List<List<Integer>> args = new ArrayList<>();
|
||||
|
@ -634,18 +617,14 @@ public class FourCornerZionStenoLexer {
|
|||
while (input.hasNext()) {
|
||||
int cdcPoint = input.next();
|
||||
if (cdcPoint == FCDotCDC1604DashP6._NUL.ordinal()) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnInvalidSalah(currLine, currCol);
|
||||
}
|
||||
result.clear();
|
||||
return ScanResult.NEXT; // _NUL not allowed salah
|
||||
}
|
||||
if (FCDotCDC1604DashP6.isEscape6(cdcPoint) || FourCornerDotCake.FC_DEC0127_PX0.contains(cdcPoint)) {
|
||||
FCDotDEC0127DashPX0 embedESC = readEscape6(input, cdcPoint);
|
||||
if (embedESC == null) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
||||
}
|
||||
result.clear();
|
||||
return ScanResult.NEXT;
|
||||
}
|
||||
|
@ -662,9 +641,7 @@ public class FourCornerZionStenoLexer {
|
|||
continue; // Next argument
|
||||
}
|
||||
if (!embedESC.isEmbeddable()) {
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnInvalidEscape(currLine, currCol, cdcPoint);
|
||||
}
|
||||
result.clear();
|
||||
return ScanResult.NEXT;
|
||||
}
|
||||
|
@ -674,9 +651,7 @@ public class FourCornerZionStenoLexer {
|
|||
}
|
||||
argu.add(cdcPoint);
|
||||
}
|
||||
if (smokeSignals != null) {
|
||||
smokeSignals.burnInvalidSalah(currLine, currCol);
|
||||
}
|
||||
result.clear();
|
||||
return ScanResult.NEXT;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,18 @@ package org.x4o.o2o.fc18.zion7;
|
|||
/// @version 1.0 Jan 13, 2025
|
||||
public interface FourCornerZionStenoLexerFire {
|
||||
|
||||
void fireStateLine(int line);
|
||||
|
||||
void fireStateColumn(int column);
|
||||
|
||||
interface Adapter extends FourCornerZionStenoLexerFire {
|
||||
|
||||
@Override
|
||||
default void fireStateLine(int line) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void fireStateColumn(int column) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,27 +41,25 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
|||
*/
|
||||
public class LexerNCRTest {
|
||||
|
||||
final TestSmokeReader SMOKE_READER = new TestSmokeReader();
|
||||
|
||||
@Test
|
||||
public void testNCRInvalid() throws Exception {
|
||||
TestSmokeReader smokeReader = new TestSmokeReader();
|
||||
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
||||
lexer.withSmokeSignals(SMOKE_READER);
|
||||
lexer.withSmokeSignals(smokeReader);
|
||||
List<Integer> cdc = new ArrayList<>();
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 1);
|
||||
|
||||
SMOKE_READER.reset();
|
||||
lexer.read(cdc);
|
||||
Assertions.assertEquals(-1, SMOKE_READER.errorNCRUnusedSparks);
|
||||
Assertions.assertEquals(0, SMOKE_READER.errorNCRZeroSparks);
|
||||
Assertions.assertEquals(-1, smokeReader.errorNCRUnusedSparks);
|
||||
Assertions.assertEquals(0, smokeReader.errorNCRZeroSparks);
|
||||
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XN.getStart() - 1 + 123); // NXX_123
|
||||
cdc.add(FourCornerDotCake.FC_NCR1632_XD.getStart() + (512*63) + 2);
|
||||
|
||||
SMOKE_READER.reset();
|
||||
smokeReader.reset();
|
||||
lexer.read(cdc);
|
||||
Assertions.assertEquals(0, SMOKE_READER.errorNCRUnusedSparks);
|
||||
Assertions.assertEquals(-1, SMOKE_READER.errorNCRZeroSparks);
|
||||
Assertions.assertEquals(0, smokeReader.errorNCRUnusedSparks);
|
||||
Assertions.assertEquals(-1, smokeReader.errorNCRZeroSparks);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -28,10 +28,6 @@ import java.util.List;
|
|||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.x4o.o2o.fc18.FourCornerDotCake;
|
||||
import org.x4o.o2o.fc18.FourCornerUnicodeDisplay;
|
||||
import org.x4o.o2o.fc18.FourCornerX06BaklavaPoints;
|
||||
import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6;
|
||||
import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
||||
|
||||
/**
|
||||
* Tests four corner lexer parts.
|
||||
|
@ -41,18 +37,17 @@ import org.x4o.o2o.fc18.zero33.FCDotDEC0127DashPX0;
|
|||
*/
|
||||
public class LexerUNI21Test {
|
||||
|
||||
final TestSmokeReader SMOKE_READER = new TestSmokeReader();
|
||||
|
||||
@Test
|
||||
public void testUNI21Invalid() throws Exception {
|
||||
TestSmokeReader smokeReader = new TestSmokeReader();
|
||||
FourCornerZionStenoLexer lexer = new FourCornerZionStenoLexer(new FourCornerZion7Candlelier.Adapter() {}, true);
|
||||
lexer.withSmokeSignals(SMOKE_READER);
|
||||
lexer.withSmokeSignals(smokeReader);
|
||||
List<Integer> cdc = new ArrayList<>();
|
||||
cdc.add(FourCornerDotCake.FC_UNI2K_22.getStart() + 123);
|
||||
|
||||
SMOKE_READER.reset();
|
||||
Assertions.assertEquals(-1, SMOKE_READER.errorUNI21UnusedBigIndian);
|
||||
smokeReader.reset();
|
||||
Assertions.assertEquals(-1, smokeReader.errorUNI21UnusedBigIndian);
|
||||
lexer.read(cdc);
|
||||
Assertions.assertEquals(0, SMOKE_READER.errorUNI21UnusedBigIndian);
|
||||
Assertions.assertEquals(0, smokeReader.errorUNI21UnusedBigIndian);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue