From bac0041239bcff259d9e846e55def6a8448e7e81 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 7 Jan 2025 19:29:50 +0100 Subject: [PATCH] Added X08 and X18 display in unicode --- .../o2o/fc18/FourCornerUnicodeDisplay.java | 75 +++++++--- .../x4o/o2o/fc18/FourCornerUnicodeImport.java | 122 ++++++++++------ .../x4o/o2o/fc18/pie9c/FCDotPIE9CDash10.java | 20 +-- .../o2o/fc18/zero33/FCDotCDC1604DashP6.java | 5 +- .../fc18/FourCornerUnicodeDisplayTest.java | 10 +- .../o2o/fc18/FourCornerUnicodeImportTest.java | 132 +++++++++++++++--- 6 files changed, 273 insertions(+), 91 deletions(-) diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java index 3f50254..21f3479 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplay.java @@ -98,14 +98,42 @@ public class FourCornerUnicodeDisplay { return buf.toString(); } - public String renderFromP6(List chars) { - return buildString(v -> renderFromP6(chars, v)); + public String renderFromX06(List chars) { + return buildString(v -> renderFromX06(chars, v)); } - public void renderFromP6(List chars, StringBuilder buf) { + public void renderFromX06(List chars, StringBuilder buf) { List charPoints = new ArrayList<>(chars.size()); - for (FourCornerX06BaklavaPoints baklava : chars) { - for (int v : baklava.baklavaPoints()) { + for (FourCornerX06BaklavaPoints oven : chars) { + for (int v : oven.baklavaPoints()) { + charPoints.add(v); + } + } + renderFromInt18(charPoints, buf); + } + + public String renderFromX08(List chars) { + return buildString(v -> renderFromX08(chars, v)); + } + + public void renderFromX08(List chars, StringBuilder buf) { + List charPoints = new ArrayList<>(chars.size()); + for (FourCornerX08MuffinPoints oven : chars) { + for (int v : oven.muffinPoints()) { + charPoints.add(v); + } + } + renderFromInt18(charPoints, buf); + } + + public String renderFromX18(List chars) { + return buildString(v -> renderFromX18(chars, v)); + } + + public void renderFromX18(List chars, StringBuilder buf) { + List charPoints = new ArrayList<>(chars.size()); + for (FourCornerX18CakePoints oven : chars) { + for (int v : oven.cakePoints()) { charPoints.add(v); } } @@ -133,9 +161,23 @@ public class FourCornerUnicodeDisplay { boolean prevWord = false; while (cdc.hasNext()) { Integer cdcPoint = cdc.next(); - if (FCDotCDC1604DashP6.__ESC6.ordinal() == cdcPoint) { + if (cdcPoint >= FourCornerDotCake.FC_DEC1604_P7.getStart() && cdcPoint <= FourCornerDotCake.FC_DEC1604_P7.getStop()) { + Integer decPoint = cdcPoint - FourCornerDotCake.FC_DEC1604_P7.getLength(); + FCDotDEC1604DashP7 decCode = FCDotDEC1604DashP7.indexOf(decPoint); numberMode = null; // out of range, thus stop - Integer handled = handleEscape6(cdc, buf); + Integer handled = handleEscape6(decCode, cdc, buf); + if (handled == null) { + continue; + } + cdcPoint = handled; // out of range, is back to normal + } + if (FCDotCDC1604DashP6.__ESC6.ordinal() == cdcPoint) { + if (!cdc.hasNext()) { + break; + } + FCDotDEC1604DashP7 decCode = FCDotDEC1604DashP7.indexOf(cdc.next()); + numberMode = null; // out of range, thus stop + Integer handled = handleEscape6(decCode, cdc, buf); if (handled == null) { continue; } @@ -212,14 +254,12 @@ public class FourCornerUnicodeDisplay { } } - private Integer handleEscape6(Iterator cdc, StringBuilder buf) { - if (!cdc.hasNext()) { - return null; + private Integer handleEscape6(FCDotDEC1604DashP7 decCode, Iterator cdc, StringBuilder buf) { + if (renderHiddenControls) { + buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); } - FCDotDEC1604DashP7 decCode = FCDotDEC1604DashP7.indexOf(cdc.next()); if (FCDotDEC1604DashP7.__NUL_DEC.equals(decCode)) { if (renderHiddenControls) { - buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotDEC1604DashP7.__NUL_DEC.ordinal())); } return null; @@ -229,7 +269,6 @@ public class FourCornerUnicodeDisplay { return null; } if (renderHiddenControls) { - buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotDEC1604DashP7.__ESC6_APL.ordinal())); } FCDotAPL1604DashP8L aplCode = FCDotAPL1604DashP8L.indexOf(cdc.next()); @@ -241,7 +280,6 @@ public class FourCornerUnicodeDisplay { return null; } if (renderHiddenControls) { - buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotDEC1604DashP7.__ESC6_BYD.ordinal())); } FCDotBYD1604DashP8H bydCode = FCDotBYD1604DashP8H.indexOf(cdc.next()); @@ -250,7 +288,6 @@ public class FourCornerUnicodeDisplay { } if (FCDotDEC1604DashP7.__ESC_STOP.equals(decCode)) { if (renderHiddenControls) { - buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotDEC1604DashP7.__ESC_STOP.ordinal())); } return null; @@ -267,12 +304,16 @@ public class FourCornerUnicodeDisplay { if (idx > 26 || idx < 0) { return checkChr; // can't handle this } - buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); + if (!renderHiddenControls) { + buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); + } FCDotPIE9CDash26 lowCode = FCDotPIE9CDash26.values()[idx]; Arrays.stream(lowCode.codePoints()).forEach(v -> buf.appendCodePoint(v)); return null; } - buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); + if (!renderHiddenControls) { + buf.append(FCDotCDC1604DashP6.escapeSignUnicode(FCDotCDC1604DashP6.__ESC6.ordinal())); + } return decCode.ordinal(); } diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeImport.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeImport.java index 0e89437..4a70ad3 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeImport.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/FourCornerUnicodeImport.java @@ -23,13 +23,13 @@ package org.x4o.o2o.fc18; import java.util.ArrayList; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.PrimitiveIterator; import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6; +import org.x4o.o2o.fc18.zero33.FCDotDEC1604DashP7; import org.x4o.o2o.octal.PrimordialOctalOrangeJuiceCord; import org.x4o.o2o.octal.PrimordialOctalOrangeString; @@ -41,8 +41,6 @@ import org.x4o.o2o.octal.PrimordialOctalOrangeString; /// public class FourCornerUnicodeImport { - static private final FourCornerUnicodeImport IMPORT_STRICT = new FourCornerUnicodeImport(false); - static private final FourCornerUnicodeImport IMPORT_LOSSY = new FourCornerUnicodeImport(true); private boolean convertDiacritics = false; private final Map int21ToVide = new HashMap<>(); @@ -52,11 +50,11 @@ public class FourCornerUnicodeImport { } static public FourCornerUnicodeImport strict() { - return IMPORT_STRICT; + return new FourCornerUnicodeImport(false); } static public FourCornerUnicodeImport lossy() { - return IMPORT_LOSSY; + return new FourCornerUnicodeImport(true); } public PrimordialOctalOrangeJuiceCord convertToJuice(String text) { @@ -64,13 +62,31 @@ public class FourCornerUnicodeImport { } public List convertToInt18(String text) { - return convertToP6(text).stream().map(v -> v.baklavaPoints()[0]).toList(); + List cakePoints = new ArrayList<>(text.length()); + for (FourCornerX18CakePoints oven : convertToX18(text)) { + for (int v : oven.cakePoints()) { + cakePoints.add(v); + } + } + return cakePoints; } - public List convertToP6(String text) { + public List convertToX06(String text) { + return convertToXXX(text, 6).stream().map(v -> v.toX06()).toList(); + } + + public List convertToX08(String text) { + return convertToXXX(text, 8).stream().map(v -> v.toX08()).toList(); + } + + public List convertToX18(String text) { + return convertToXXX(text, 18).stream().map(v -> v.toX18()).toList(); + } + + private List convertToXXX(String text, int bits) { String textSingleNewLines = text.replaceAll("\r\n", "\n"); // FIXME: regex only allowed in test scope classpath PrimitiveIterator.OfInt i = textSingleNewLines.codePoints().iterator(); - List result = new ArrayList<>(text.length()); + List result = new ArrayList<>(text.length()); FCDotCDC1604DashP6 cdcNumberTerminator = null; FCDotCDC1604DashP6 cdcCaseTerminator = null; while (i.hasNext()) { @@ -85,49 +101,77 @@ public class FourCornerUnicodeImport { } // Handle number sequences manual, to escape once - if (codePoint >= '0' && codePoint <= '9') { - if (!FCDotCDC1604DashP6.NX10_J.equals(cdcNumberTerminator)) { - result.add(FCDotCDC1604DashP6.__PIE); - result.add(FCDotCDC1604DashP6.NX10_J); - cdcNumberTerminator = FCDotCDC1604DashP6.NX10_J; + if (bits != 18) { // 18 direct cake point is found by generic lookup + if (codePoint >= '0' && codePoint <= '9') { + if (!FCDotCDC1604DashP6.NX10_J.equals(cdcNumberTerminator)) { + result.add(FCDotCDC1604DashP6.__PIE); + result.add(FCDotCDC1604DashP6.NX10_J); + cdcNumberTerminator = FCDotCDC1604DashP6.NX10_J; + } + int cdcNumberOff = codePoint - '0'; + int cdcNumber = FCDotCDC1604DashP6.NX01_A.ordinal() + cdcNumberOff; + result.add(FCDotCDC1604DashP6.indexOf(cdcNumber)); + continue; + } + if (cdcNumberTerminator != null) { + cdcNumberTerminator = null; + if (bits == 6) { + result.add(FCDotCDC1604DashP6.__ESC6); + result.add(FCDotCDC1604DashP6.__ESC6); + } else { + result.add(FCDotDEC1604DashP7.__ESC_STOP); + } } - int cdcNumberOff = codePoint - '0'; - int cdcNumber = FCDotCDC1604DashP6.NX01_A.ordinal() + cdcNumberOff; - result.add(FCDotCDC1604DashP6.indexOf(cdcNumber)); - continue; - } - if (cdcNumberTerminator != null) { - cdcNumberTerminator = null; - result.add(FCDotCDC1604DashP6.__ESC6); - result.add(FCDotCDC1604DashP6.__ESC6); } // Handle lower case sequences manual, to escape once - if (codePoint >= 'a' && codePoint <= 'z') { - if (!FCDotCDC1604DashP6.NX26_Z.equals(cdcCaseTerminator)) { - result.add(FCDotCDC1604DashP6.__PIE); - result.add(FCDotCDC1604DashP6.NX26_Z); - cdcCaseTerminator = FCDotCDC1604DashP6.NX26_Z; + if (bits != 18) { // 18 direct cake point is found by generic lookup + if (codePoint >= 'a' && codePoint <= 'z') { + if (!FCDotCDC1604DashP6.NX26_Z.equals(cdcCaseTerminator)) { + result.add(FCDotCDC1604DashP6.__PIE); + result.add(FCDotCDC1604DashP6.NX26_Z); + cdcCaseTerminator = FCDotCDC1604DashP6.NX26_Z; + } + int cdcNumberOff = codePoint - 'a'; + int cdcNumber = FCDotCDC1604DashP6.NX01_A.ordinal() + cdcNumberOff; + result.add(FCDotCDC1604DashP6.indexOf(cdcNumber)); + continue; + } + if (cdcCaseTerminator != null) { + cdcCaseTerminator = null; + if (bits == 6) { + result.add(FCDotCDC1604DashP6.__ESC6); + result.add(FCDotCDC1604DashP6.__ESC6); + } else { + result.add(FCDotDEC1604DashP7.__ESC_STOP); + } } - int cdcNumberOff = codePoint - 'a'; - int cdcNumber = FCDotCDC1604DashP6.NX01_A.ordinal() + cdcNumberOff; - result.add(FCDotCDC1604DashP6.indexOf(cdcNumber)); - continue; - } - if (cdcCaseTerminator != null) { - cdcCaseTerminator = null; - result.add(FCDotCDC1604DashP6.__ESC6); - result.add(FCDotCDC1604DashP6.__ESC6); } // Lookup mapped values FourCornerX00PetitVidePoints chs = int21ToVide.get(codePoint); if (chs != null) { - if (!chs.isX06()) { + if (bits == 6) { + if (!chs.isX06()) { + continue; + } + result.add(chs.toX06()); + //Arrays.stream(chs.toX06().baklavaPoints()).mapToObj(v -> FCDotCDC1604DashP6.indexOf(v)).forEach(v -> result.add(v)); + continue; + } else if (bits == 8) { + if (!chs.isX08()) { + continue; + } + result.add(chs.toX08()); + continue; + } else { + if (!chs.isX18()) { + continue; + } + result.add(chs.toX18()); continue; } - Arrays.stream(chs.toX06().baklavaPoints()).mapToObj(v -> FCDotCDC1604DashP6.indexOf(v)).forEach(v -> result.add(v)); - continue; + // fails below in exception } // Check lossy aliases diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/pie9c/FCDotPIE9CDash10.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/pie9c/FCDotPIE9CDash10.java index 815aab7..df2a96f 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/pie9c/FCDotPIE9CDash10.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/pie9c/FCDotPIE9CDash10.java @@ -37,16 +37,16 @@ import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6; */ public enum FCDotPIE9CDash10 implements FourCornerX06BaklavaPoints, FourCornerX08MuffinPoints, FourCornerX18CakePoints, FourCornerX21CodePoints { - NXX_01('0'), - NXX_02('1'), - NXX_03('2'), - NXX_04('3'), - NXX_05('4'), - NXX_06('5'), - NXX_07('6'), - NXX_08('7'), - NXX_09('8'), - NXX_10('9'), + DECIMAL_0('0'), + DECIMAL_1('1'), + DECIMAL_2('2'), + DECIMAL_3('3'), + DECIMAL_4('4'), + DECIMAL_5('5'), + DECIMAL_6('6'), + DECIMAL_7('7'), + DECIMAL_8('8'), + DECIMAL_9('9'), ; private final int[] codePoints; diff --git a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zero33/FCDotCDC1604DashP6.java b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zero33/FCDotCDC1604DashP6.java index 229b646..6d13e4d 100644 --- a/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zero33/FCDotCDC1604DashP6.java +++ b/nx01-x4o-o2o/src/main/java/org/x4o/o2o/fc18/zero33/FCDotCDC1604DashP6.java @@ -22,7 +22,6 @@ */ package org.x4o.o2o.fc18.zero33; -import org.x4o.o2o.fc18.FourCornerDotCake; import org.x4o.o2o.fc18.FourCornerX06BaklavaPoints; import org.x4o.o2o.fc18.FourCornerX08MuffinPoints; import org.x4o.o2o.fc18.FourCornerX18CakePoints; @@ -140,12 +139,12 @@ public enum FCDotCDC1604DashP6 implements FourCornerX06BaklavaPoints, FourCorner @Override public int[] muffinPoints() { - return cakePoints(); + return new int[] {ordinal()}; } @Override public int[] cakePoints() { - return new int[] {FourCornerDotCake.FC_CDC1604_P6.getStart() + ordinal()}; + return new int[] {ordinal()}; } @Override diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java index cac25de..1107adb 100644 --- a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeDisplayTest.java @@ -47,7 +47,7 @@ public class FourCornerUnicodeDisplayTest { cdc.add(FCDotCDC1604DashP6.NX03_C); // T003 cdc.add(FCDotCDC1604DashP6.NX01_A); // NXX_001 - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); Assertions.assertEquals("X¹/₃", out); } @@ -81,8 +81,8 @@ public class FourCornerUnicodeDisplayTest { cdc.add(FCDotDEC1604DashP7.__ESC_STOP); cdc.add(FCDotCDC1604DashP6.NX15_O); - Assertions.assertEquals("ab B␃cD.jklmO", FourCornerUnicodeDisplay.text().renderFromP6(cdc)); - Assertions.assertEquals("ab B␃cD.jklm␃␃O", FourCornerUnicodeDisplay.text(true).renderFromP6(cdc)); + Assertions.assertEquals("ab B␃cD.jklmO", FourCornerUnicodeDisplay.text().renderFromX06(cdc)); + Assertions.assertEquals("ab B␃cD.jklm␃␃O", FourCornerUnicodeDisplay.text(true).renderFromX06(cdc)); } @Test @@ -96,7 +96,7 @@ public class FourCornerUnicodeDisplayTest { cdc.add(FCDotCDC1604DashP6._AT); cdc.add(FCDotCDC1604DashP6.NX11_K); // = K - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); Assertions.assertEquals("X^%@K", out); } @@ -111,7 +111,7 @@ public class FourCornerUnicodeDisplayTest { cdc.add(FCDotCDC1604DashP6.NX04_D); // 3 cdc.add(FCDotCDC1604DashP6.NX11_K); // K - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); Assertions.assertEquals("B3K", out); } } diff --git a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeImportTest.java b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeImportTest.java index df6b594..10ade48 100644 --- a/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeImportTest.java +++ b/nx01-x4o-o2o/src/test/java/org/x4o/o2o/fc18/FourCornerUnicodeImportTest.java @@ -26,7 +26,10 @@ import java.util.List; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.x4o.o2o.fc18.pie9c.FCDotPIE9CDash10; +import org.x4o.o2o.fc18.pie9c.FCDotPIE9CDash26; import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6; +import org.x4o.o2o.fc18.zero33.FCDotDEC1604DashP7; /** * Tests four corner unicode import. @@ -37,8 +40,25 @@ import org.x4o.o2o.fc18.zero33.FCDotCDC1604DashP6; public class FourCornerUnicodeImportTest { @Test - public void testAsciiSimple() throws Exception { - List cdc = FourCornerUnicodeImport.lossy().convertToP6("foobar"); + public void testAsciiUpper() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX06("FOOBAR"); + Assertions.assertNotNull(cdc); + Assertions.assertFalse(cdc.isEmpty()); + Assertions.assertEquals(6, cdc.size()); + Assertions.assertEquals(FCDotCDC1604DashP6.NX06_F, cdc.get(0)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX15_O, cdc.get(1)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX15_O, cdc.get(2)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(3)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(4)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX18_R, cdc.get(5)); + + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); + Assertions.assertEquals("FOOBAR", out); + } + + @Test + public void testAsciiLower() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX06("foobar"); Assertions.assertNotNull(cdc); Assertions.assertFalse(cdc.isEmpty()); Assertions.assertEquals(8, cdc.size()); @@ -51,16 +71,16 @@ public class FourCornerUnicodeImportTest { Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(6)); Assertions.assertEquals(FCDotCDC1604DashP6.NX18_R, cdc.get(7)); - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); Assertions.assertEquals("foobar", out); } @Test - public void testAsciiUpper() throws Exception { - List cdc = FourCornerUnicodeImport.lossy().convertToP6("fooBAR"); + public void testAsciiMixedX06() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX06("fooBAR"); Assertions.assertNotNull(cdc); Assertions.assertFalse(cdc.isEmpty()); - Assertions.assertEquals(10, cdc.size()); + Assertions.assertEquals(10, cdc.size()); // = 60 bit Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(0)); Assertions.assertEquals(FCDotCDC1604DashP6.NX26_Z, cdc.get(1)); Assertions.assertEquals(FCDotCDC1604DashP6.NX06_F, cdc.get(2)); @@ -72,25 +92,63 @@ public class FourCornerUnicodeImportTest { Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(8)); Assertions.assertEquals(FCDotCDC1604DashP6.NX18_R, cdc.get(9)); - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); Assertions.assertEquals("fooBAR", out); } @Test - public void testCheckDiacritics() throws Exception { - String foobar = "ꞘȍőḆẬř"; - List cdc = FourCornerUnicodeImport.lossy().convertToP6(foobar); + public void testAsciiMixedX08() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX08("fooBAR"); Assertions.assertNotNull(cdc); Assertions.assertFalse(cdc.isEmpty()); - Assertions.assertEquals("FOOBAR", FourCornerUnicodeDisplay.text().renderFromP6(cdc)); + Assertions.assertEquals(9, cdc.size()); // = 72 bit + Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(0)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX26_Z, cdc.get(1)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX06_F, cdc.get(2)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX15_O, cdc.get(3)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX15_O, cdc.get(4)); + Assertions.assertEquals(FCDotDEC1604DashP7.__ESC_STOP, cdc.get(5)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(6)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(7)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX18_R, cdc.get(8)); + + String out = FourCornerUnicodeDisplay.text().renderFromX08(cdc); + Assertions.assertEquals("fooBAR", out); + } + + @Test + public void testAsciiMixedX18() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX18("fooBAR"); + Assertions.assertNotNull(cdc); + Assertions.assertFalse(cdc.isEmpty()); + Assertions.assertEquals(6, cdc.size()); // = 108 bit + Assertions.assertEquals(FCDotPIE9CDash26.LOW_F, cdc.get(0)); + Assertions.assertEquals(FCDotPIE9CDash26.LOW_O, cdc.get(1)); + Assertions.assertEquals(FCDotPIE9CDash26.LOW_O, cdc.get(2)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(3)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(4)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX18_R, cdc.get(5)); + + String out = FourCornerUnicodeDisplay.text().renderFromX18(cdc); + Assertions.assertEquals("fooBAR", out); + } + + + @Test + public void testCheckDiacritics() throws Exception { + String foobar = "ꞘȍőḆẬř"; + List cdc = FourCornerUnicodeImport.lossy().convertToX06(foobar); + Assertions.assertNotNull(cdc); + Assertions.assertFalse(cdc.isEmpty()); + Assertions.assertEquals("FOOBAR", FourCornerUnicodeDisplay.text().renderFromX06(cdc)); Assertions.assertThrows(IllegalArgumentException.class, () -> { - FourCornerUnicodeImport.strict().convertToP6(foobar); + FourCornerUnicodeImport.strict().convertToX06(foobar); }); } @Test - public void testNumber012() throws Exception { - List cdc = FourCornerUnicodeImport.lossy().convertToP6("01201337"); + public void testNumberX06() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX06("01201337"); Assertions.assertNotNull(cdc); Assertions.assertFalse(cdc.isEmpty()); Assertions.assertEquals(10, cdc.size()); @@ -105,13 +163,53 @@ public class FourCornerUnicodeImportTest { Assertions.assertEquals(FCDotCDC1604DashP6.NX04_D, cdc.get(8)); // 3 Assertions.assertEquals(FCDotCDC1604DashP6.NX08_H, cdc.get(9)); // 7 - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); + Assertions.assertEquals("01201337", out); + } + + @Test + public void testNumberX08() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX08("01201337"); + Assertions.assertNotNull(cdc); + Assertions.assertFalse(cdc.isEmpty()); + Assertions.assertEquals(10, cdc.size()); + Assertions.assertEquals(FCDotCDC1604DashP6.__PIE, cdc.get(0)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX10_J, cdc.get(1)); + Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(2)); // 0 + Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(3)); // 1 + Assertions.assertEquals(FCDotCDC1604DashP6.NX03_C, cdc.get(4)); // 2 + Assertions.assertEquals(FCDotCDC1604DashP6.NX01_A, cdc.get(5)); // 0 + Assertions.assertEquals(FCDotCDC1604DashP6.NX02_B, cdc.get(6)); // 1 + Assertions.assertEquals(FCDotCDC1604DashP6.NX04_D, cdc.get(7)); // 3 + Assertions.assertEquals(FCDotCDC1604DashP6.NX04_D, cdc.get(8)); // 3 + Assertions.assertEquals(FCDotCDC1604DashP6.NX08_H, cdc.get(9)); // 7 + + String out = FourCornerUnicodeDisplay.text().renderFromX08(cdc); + Assertions.assertEquals("01201337", out); + } + + @Test + public void testNumberX18() throws Exception { + List cdc = FourCornerUnicodeImport.strict().convertToX18("01201337"); + Assertions.assertNotNull(cdc); + Assertions.assertFalse(cdc.isEmpty()); + Assertions.assertEquals(8, cdc.size()); + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_0, cdc.get(0)); // 0 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_1, cdc.get(1)); // 1 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_2, cdc.get(2)); // 2 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_0, cdc.get(3)); // 0 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_1, cdc.get(4)); // 1 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_3, cdc.get(5)); // 3 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_3, cdc.get(6)); // 3 + Assertions.assertEquals(FCDotPIE9CDash10.DECIMAL_7, cdc.get(7)); // 7 + + String out = FourCornerUnicodeDisplay.text().renderFromX18(cdc); Assertions.assertEquals("01201337", out); } @Test public void testLineEndings() throws Exception { - List cdc = FourCornerUnicodeImport.strict().convertToP6("A\nB\rC\r\nD\n"); + List cdc = FourCornerUnicodeImport.strict().convertToX06("A\nB\rC\r\nD\n"); Assertions.assertNotNull(cdc); Assertions.assertFalse(cdc.isEmpty()); Assertions.assertEquals(8, cdc.size()); @@ -124,7 +222,7 @@ public class FourCornerUnicodeImportTest { Assertions.assertEquals(FCDotCDC1604DashP6.NX04_D, cdc.get(6)); Assertions.assertEquals(FCDotCDC1604DashP6.__LINE, cdc.get(7)); - String out = FourCornerUnicodeDisplay.text().renderFromP6(cdc); + String out = FourCornerUnicodeDisplay.text().renderFromX06(cdc); Assertions.assertEquals("A\nB\nC\nD\n", out); } }