More operand/dw tests (#228)

This commit is contained in:
simon987 2020-07-30 19:13:07 -04:00
parent fe299fe061
commit 73dc9b1dca
3 changed files with 57 additions and 26 deletions

View File

@ -1,24 +0,0 @@
package net.simon987.mar.server.assembly;
import net.simon987.mar.server.FakeConfiguration;
import net.simon987.mar.server.IServerConfiguration;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class DWTest {
@Test
public void TestSemiColonInString() {
IServerConfiguration configuration = new FakeConfiguration();
configuration.setInt("memory_size", 1000);
configuration.setInt("org_offset", 400);
Assembler assembler = new Assembler(new DefaultInstructionSet(), new DefaultRegisterSet(), configuration);
AssemblyResult ar = assembler.parse("DW \";\"");
assertEquals(0, ar.exceptions.size());
}
}

View File

@ -1,10 +1,11 @@
package net.simon987.mar.server.assembly;
import net.simon987.mar.server.FakeConfiguration;
import net.simon987.mar.server.IServerConfiguration;
import net.simon987.mar.server.TestExecutionResult;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
public class DwDirectiveTest {
@Test
@ -20,4 +21,42 @@ public class DwDirectiveTest {
assertTrue(res.ar.exceptions.isEmpty());
assertEquals('H', res.regValue("A"));
}
@Test
public void semiColonInString() {
String code = "DW \";\"";
TestExecutionResult res = TestHelper.executeCode(code);
assertTrue(res.ar.exceptions.isEmpty());
}
@Test
public void nullEscape() {
String code = "DW \"\\0\\0\"";
TestExecutionResult res = TestHelper.executeCode(code);
assertTrue(res.ar.exceptions.isEmpty());
}
@Test
public void unicode1() {
String code = "DW \"\\u0123\"";
TestExecutionResult res = TestHelper.executeCode(code);
assertTrue(res.ar.exceptions.isEmpty());
assertEquals(0x0123 ,res.memValue(res.ar.origin));
}
@Test
public void escapeQuote() {
String code = "DW \"\\\"\"";
TestExecutionResult res = TestHelper.executeCode(code);
assertTrue(res.ar.exceptions.isEmpty());
assertEquals('"' ,res.memValue(res.ar.origin));
}
}

View File

@ -150,4 +150,20 @@ public class OperandTest {
try{ new Operand("[A+A+]", labels, registerSet, 0); } catch (InvalidOperandException ignored){}
try{ new Operand("[A+[1]]", labels, registerSet, 0); } catch (InvalidOperandException ignored){}
}
@Test
public void octalLiteral() throws Exception {
Operand op = new Operand("0600", new HashMap<>(), new DefaultRegisterSet(), 0);
assertEquals(OperandType.IMMEDIATE16, op.getType());
assertEquals(Operand.IMMEDIATE_VALUE, op.getValue());
assertEquals(384, op.getData());
}
@Test
public void binaryLiteral() throws Exception {
Operand op = new Operand("0b1000", new HashMap<>(), new DefaultRegisterSet(), 0);
assertEquals(OperandType.IMMEDIATE16, op.getType());
assertEquals(Operand.IMMEDIATE_VALUE, op.getValue());
assertEquals(0b1000, op.getData());
}
}