Skip to content

Commit

Permalink
[#72] Cucumber java packages to zscript
Browse files Browse the repository at this point in the history
  • Loading branch information
susanw1 committed Aug 1, 2023
1 parent 8fb6b91 commit 3053a92
Show file tree
Hide file tree
Showing 116 changed files with 1,422 additions and 1,426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(features = { "classpath:/features/core_zcode.feature", "classpath:/features" })
@CucumberOptions(features = { "classpath:/features/core_zscript.feature", "classpath:/features" })
public class CucumberRunTests {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.zscript_acceptance_tests.core_zcode;
package net.zscript.zscript_acceptance_tests.core_zscript;

import static net.zscript.zscript_acceptance_tests.acceptancetest_asserts.ZcodeAcceptanceTestAssert.assertThatCommand;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.zscript_acceptance_tests.core_zcode;
package net.zscript.zscript_acceptance_tests.core_zscript;

import static net.zscript.zscript_acceptance_tests.acceptancetest_asserts.ZcodeAcceptanceTestAssert.assertThatCommand;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.zscript_acceptance_tests.core_zcode;
package net.zscript.zscript_acceptance_tests.core_zscript;

import static org.junit.jupiter.api.Assumptions.assumeTrue;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.zscript.zscript_acceptance_tests.core_zcode;
package net.zscript.zscript_acceptance_tests.core_zscript;

import static net.zscript.zscript_acceptance_tests.acceptancetest_asserts.ZcodeAcceptanceTestAssert.assertThatCommand;
import static org.assertj.core.api.Assertions.assertThat;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import java.util.Queue;
import java.util.function.Consumer;

import net.zscript.javaclient.responseParser.ZcodeResponseParser.ResponseHeader;
import net.zscript.javaclient.responseParser.ResponseParser.ResponseHeader;
import net.zscript.javaclient.zcodeApi.CommandSeqElement;
import net.zscript.javaclient.zcodeApi.ZcodeCommandBuilder;
import net.zscript.javaclient.zcodeApi.ZscriptCommandBuilder;

public class ZcodeCommandResponseQueue implements ZcodeCommandResponseSystem {
public class CommandResponseQueue implements CommandResponseSystem {
private static final int MAX_SENT = 10;

private final ZcodeResponseAddressingSystem addrSystem = new ZcodeResponseAddressingSystem(this);
private final ResponseAddressingSystem addrSystem = new ResponseAddressingSystem(this);

private ZcodeConnection connection;
private ZscriptConnection connection;

private interface CommandEntry {
byte[] compile();
Expand All @@ -37,7 +37,7 @@ public CommandSeqElEntry(final CommandSeqElement cmdSeq, final int echo) {
@Override
public byte[] compile() {
// TODO: decide on how locking will work...
byte[] echoF = ZcodeCommandBuilder.writeField((byte) '_', echo);
byte[] echoF = ZscriptCommandBuilder.writeField((byte) '_', echo);
byte[] startData = cmdSeq.compile(false);

ByteArrayOutputStream str = new ByteArrayOutputStream(startData.length + echoF.length + 1);
Expand All @@ -52,7 +52,7 @@ public byte[] compile() {
}

public void callback(final byte[] received) {
ZcodeResponseParser.parseFullResponse(cmdSeq, received);
ResponseParser.parseFullResponse(cmdSeq, received);
}

public int getEcho() {
Expand All @@ -67,9 +67,9 @@ public boolean canBePipelined() {

private class AddrCommandSeqElEntry implements CommandEntry {
private final byte[] cmdSeq;
private final ZcodeAddress addr;
private final ZscriptAddress addr;

public AddrCommandSeqElEntry(final byte[] cmdSeq, final ZcodeAddress addr) {
public AddrCommandSeqElEntry(final byte[] cmdSeq, final ZscriptAddress addr) {
this.cmdSeq = cmdSeq;
this.addr = addr;
}
Expand All @@ -81,7 +81,7 @@ public byte[] compile() {
try {
boolean isFirst = true;
for (int i : addr.getAddr()) {
str.write(ZcodeCommandBuilder.writeField((byte) (isFirst ? '@' : '.'), i));
str.write(ZscriptCommandBuilder.writeField((byte) (isFirst ? '@' : '.'), i));
isFirst = false;
}
str.write(cmdSeq);
Expand Down Expand Up @@ -127,10 +127,10 @@ public boolean canBePipelined() {
private int currentEcho = 0;
private boolean canPipeline = true;

public ZcodeCommandResponseQueue(ZcodeConnection connection) {
public CommandResponseQueue(ZscriptConnection connection) {
this.connection = connection;
connection.onReceive(resp -> {
ResponseHeader header = ZcodeResponseParser.parseResponseHeader(resp);
ResponseHeader header = ResponseParser.parseResponseHeader(resp);
if (header.getAddr().length == 0) {
callback(resp, header.getEcho(), header.getType());
} else {
Expand All @@ -140,7 +140,7 @@ public ZcodeCommandResponseQueue(ZcodeConnection connection) {
}

@Override
public void send(final ZcodeAddress addr, final byte[] data) {
public void send(final ZscriptAddress addr, final byte[] data) {
if (sent.size() < MAX_SENT && canPipeline) {
AddrCommandSeqElEntry el = new AddrCommandSeqElEntry(data, addr);
sent.add(el);
Expand Down Expand Up @@ -211,8 +211,8 @@ private void callback(final byte[] response, int echo, int respType) {
}

@Override
public ZcodeResponseAddressingSystem getResponseAddressingSystem() {
return new ZcodeResponseAddressingSystem(this);
public ResponseAddressingSystem getResponseAddressingSystem() {
return new ResponseAddressingSystem(this);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

import net.zscript.javaclient.zcodeApi.CommandSeqElement;

public interface ZcodeCommandResponseSystem {
public interface CommandResponseSystem {
void send(CommandSeqElement seq);

void send(ZcodeAddress addr, byte[] data);
void send(ZscriptAddress addr, byte[] data);

void send(byte[] zcode, Consumer<byte[]> callback);

ZcodeResponseAddressingSystem getResponseAddressingSystem();
ResponseAddressingSystem getResponseAddressingSystem();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
import java.util.Map;
import java.util.function.Consumer;

public class ZcodeResponseAddressingSystem {
private final ZcodeCommandResponseSystem parent;
private final Map<ZcodeAddress, Consumer<byte[]>> addressResp = new HashMap<>();
private final Map<ZcodeAddress, ZcodeConnection> addressConnection = new HashMap<>();
public class ResponseAddressingSystem {
private final CommandResponseSystem parent;
private final Map<ZscriptAddress, Consumer<byte[]>> addressResp = new HashMap<>();
private final Map<ZscriptAddress, ZscriptConnection> addressConnection = new HashMap<>();

public ZcodeResponseAddressingSystem(ZcodeCommandResponseSystem parent) {
public ResponseAddressingSystem(CommandResponseSystem parent) {
this.parent = parent;
}

public ZcodeConnection getAddressConnection(ZcodeAddress addr) {
return addressConnection.computeIfAbsent(addr, a -> new ZcodeConnection() {
public ZscriptConnection getAddressConnection(ZscriptAddress addr) {
return addressConnection.computeIfAbsent(addr, a -> new ZscriptConnection() {
@Override
public void send(byte[] data) {
parent.send(addr, data);
Expand All @@ -28,7 +28,7 @@ public void onReceive(Consumer<byte[]> handler) {
}

public void response(int[] addr, byte[] received) {
addressResp.get(new ZcodeAddress(addr)).accept(received);
addressResp.get(new ZscriptAddress(addr)).accept(received);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
import java.util.Set;

import net.zscript.javaclient.zcodeApi.CommandSeqElement;
import net.zscript.javaclient.zcodeApi.ZcodeCommand;
import net.zscript.javaclient.zcodeApi.ZcodeUnparsedCommandResponse;
import net.zscript.javaclient.zcodeApi.ZcodeCommand.ZcodeSequencePath;
import net.zscript.javaclient.zcodeApi.ZscriptCommand;
import net.zscript.javaclient.zcodeApi.ZscriptUnparsedCommandResponse;
import net.zscript.javaclient.zcodeApi.ZscriptCommand.ZcodeSequencePath;
import net.zscript.javareceiver.tokenizer.OptIterator;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenExtendingBuffer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenizer;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader;
import net.zscript.javareceiver.tokenizer.ZcodeTokenBuffer.TokenReader.ReadToken;
import net.zscript.javareceiver.tokenizer.TokenBuffer;
import net.zscript.javareceiver.tokenizer.TokenExtendingBuffer;
import net.zscript.javareceiver.tokenizer.Tokenizer;
import net.zscript.javareceiver.tokenizer.TokenBuffer.TokenReader;
import net.zscript.javareceiver.tokenizer.TokenBuffer.TokenReader.ReadToken;

public class ZcodeResponseParser {
public class ResponseParser {
static class ResponseHeader {
private final int[] addr;
private final int type;
Expand All @@ -44,8 +44,8 @@ public int getEcho() {
}

public static ResponseHeader parseResponseHeader(byte[] resp) {
final ZcodeTokenBuffer buffer = new ZcodeTokenExtendingBuffer();
final ZcodeTokenizer in = new ZcodeTokenizer(buffer.getTokenWriter(), 4);
final TokenBuffer buffer = new TokenExtendingBuffer();
final Tokenizer in = new Tokenizer(buffer.getTokenWriter(), 4);
final TokenReader reader = buffer.getTokenReader();

ReadToken lastWritten = null;
Expand Down Expand Up @@ -95,15 +95,15 @@ public static ResponseHeader parseResponseHeader(byte[] resp) {
}

private static byte convertMarkers(byte encoded) {
if (encoded == ZcodeTokenizer.CMD_END_ANDTHEN) {
if (encoded == Tokenizer.CMD_END_ANDTHEN) {
return '&';
} else if (encoded == ZcodeTokenizer.CMD_END_ORELSE) {
} else if (encoded == Tokenizer.CMD_END_ORELSE) {
return '|';
} else if (encoded == ZcodeTokenizer.CMD_END_OPEN_PAREN) {
} else if (encoded == Tokenizer.CMD_END_OPEN_PAREN) {
return '(';
} else if (encoded == ZcodeTokenizer.CMD_END_CLOSE_PAREN) {
} else if (encoded == Tokenizer.CMD_END_CLOSE_PAREN) {
return ')';
} else if (encoded == ZcodeTokenizer.NORMAL_SEQUENCE_END) {
} else if (encoded == Tokenizer.NORMAL_SEQUENCE_END) {
return '\n';
} else {
throw new IllegalArgumentException("Unknown marker: " + Integer.toHexString(Byte.toUnsignedInt(encoded)));
Expand All @@ -112,8 +112,8 @@ private static byte convertMarkers(byte encoded) {

// TODO: Trim the sequence level stuff off of first command
public static void parseFullResponse(final CommandSeqElement command, final byte[] responce) {
final ZcodeTokenBuffer buffer = new ZcodeTokenExtendingBuffer();
final ZcodeTokenizer in = new ZcodeTokenizer(buffer.getTokenWriter(), 4);
final TokenBuffer buffer = new TokenExtendingBuffer();
final Tokenizer in = new Tokenizer(buffer.getTokenWriter(), 4);
for (final byte b : responce) {
in.accept(b);
}
Expand Down Expand Up @@ -146,10 +146,10 @@ public static void parseFullResponse(final CommandSeqElement command, final byte
}

private static void matchMarkers(final CommandSeqElement command, final List<Byte> markers, final List<ReadToken> tokenAfterMarkers) {
ZcodeCommand current = null;
ZcodeSequencePath successPath = ZcodeCommand.findFirstCommand(command);
ZcodeSequencePath failPath = ZcodeCommand.findFirstCommand(command);
Set<ZcodeCommand> sentResponses = new HashSet<>();
ZscriptCommand current = null;
ZcodeSequencePath successPath = ZscriptCommand.findFirstCommand(command);
ZcodeSequencePath failPath = ZscriptCommand.findFirstCommand(command);
Set<ZscriptCommand> sentResponses = new HashSet<>();

int offset = 0;

Expand Down Expand Up @@ -196,11 +196,11 @@ private static void matchMarkers(final CommandSeqElement command, final List<Byt
}
successPath = current.findSuccessPath();
failPath = current.findFailPath();
current.response(new ZcodeUnparsedCommandResponse(tokenAfterMarkers.get(offset)));
current.response(new ZscriptUnparsedCommandResponse(tokenAfterMarkers.get(offset)));
sentResponses.add(current);
}
for (ZcodeSequencePath path = ZcodeCommand.findFirstCommand(command); path != null; path = path.getNext().findNext()) {
ZcodeCommand cmd = path.getNext();
for (ZcodeSequencePath path = ZscriptCommand.findFirstCommand(command); path != null; path = path.getNext().findNext()) {
ZscriptCommand cmd = path.getNext();
if (!sentResponses.contains(cmd)) {
cmd.notExecuted();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@

import java.util.Arrays;

public class ZcodeAddress {
public class ZscriptAddress {
private final int[] addr;

public static ZcodeAddress from(int addr0) {
return new ZcodeAddress(new int[] { addr0 });
public static ZscriptAddress from(int addr0) {
return new ZscriptAddress(new int[] { addr0 });
}

public static ZcodeAddress from(int addr0, int addr1) {
return new ZcodeAddress(new int[] { addr0, addr1 });
public static ZscriptAddress from(int addr0, int addr1) {
return new ZscriptAddress(new int[] { addr0, addr1 });
}

public static ZcodeAddress from(int addr0, int addr1, int addr2) {
return new ZcodeAddress(new int[] { addr0, addr1, addr2 });
public static ZscriptAddress from(int addr0, int addr1, int addr2) {
return new ZscriptAddress(new int[] { addr0, addr1, addr2 });
}

public ZcodeAddress(int[] addr) {
public ZscriptAddress(int[] addr) {
this.addr = addr;
}

Expand All @@ -41,7 +41,7 @@ public boolean equals(Object obj) {
return false;
if (getClass() != obj.getClass())
return false;
ZcodeAddress other = (ZcodeAddress) obj;
ZscriptAddress other = (ZscriptAddress) obj;
if (!Arrays.equals(addr, other.addr))
return false;
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.function.Consumer;

public interface ZcodeConnection {
public interface ZscriptConnection {
void send(byte[] data);

void onReceive(Consumer<byte[]> handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.nio.charset.StandardCharsets;

public class ZcodeAbortCommand extends ZcodeCommand {
public class AbortCommand extends ZscriptCommand {

@Override
public CommandSeqElement thenFail() {
Expand Down Expand Up @@ -65,7 +65,7 @@ public boolean isCommand() {
}

@Override
public void response(ZcodeUnparsedCommandResponse resp) {
public void response(ZscriptUnparsedCommandResponse resp) {
}

@Override
Expand Down
Loading

0 comments on commit 3053a92

Please sign in to comment.