mirror of
https://gitlab.com/camelot/kickc.git
synced 2024-11-24 14:31:15 +00:00
Added a few enum error tests
This commit is contained in:
parent
291c87621e
commit
2acc1010ec
@ -1207,6 +1207,7 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
|
||||
@Override
|
||||
public Object visitEnumDef(KickCParser.EnumDefContext ctx) {
|
||||
try {
|
||||
String enumDefName;
|
||||
if(ctx.NAME() != null) {
|
||||
enumDefName = ctx.NAME().getText();
|
||||
@ -1227,6 +1228,9 @@ public class Pass0GenerateStatementSequence extends KickCBaseVisitor<Object> {
|
||||
parentScope.add(new ConstantVar(member.getLocalName(), parentScope, SymbolType.BYTE, member.getValue()));
|
||||
}
|
||||
return SymbolType.BYTE;
|
||||
} catch (CompileError e) {
|
||||
throw new CompileError(e.getMessage(), new StatementSource(ctx));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,6 +35,21 @@ public class TestPrograms {
|
||||
public TestPrograms() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumErr2() throws IOException, URISyntaxException {
|
||||
assertError("enum-err-2", "Enum value not constant");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumErr1() throws IOException, URISyntaxException {
|
||||
assertError("enum-err-1", "Symbol already declared");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumErr0() throws IOException, URISyntaxException {
|
||||
assertError("enum-err-0", "Symbol already declared");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnum8() throws IOException, URISyntaxException {
|
||||
compileAndCompare("enum-8");
|
||||
|
15
src/test/kc/enum-err-0.kc
Normal file
15
src/test/kc/enum-err-0.kc
Normal file
@ -0,0 +1,15 @@
|
||||
// Test of simple enum error - name already used
|
||||
|
||||
byte ON = 17;
|
||||
|
||||
enum State {
|
||||
OFF,
|
||||
ON
|
||||
};
|
||||
|
||||
void main() {
|
||||
enum State state = ON;
|
||||
const byte* SCREEN = 0x0400;
|
||||
*SCREEN = state;
|
||||
}
|
||||
|
14
src/test/kc/enum-err-1.kc
Normal file
14
src/test/kc/enum-err-1.kc
Normal file
@ -0,0 +1,14 @@
|
||||
// Test of simple enum error - name already used
|
||||
|
||||
enum State {
|
||||
OFF,
|
||||
ON,
|
||||
OFF
|
||||
};
|
||||
|
||||
void main() {
|
||||
enum State state = ON;
|
||||
const byte* SCREEN = 0x0400;
|
||||
*SCREEN = state;
|
||||
}
|
||||
|
15
src/test/kc/enum-err-2.kc
Normal file
15
src/test/kc/enum-err-2.kc
Normal file
@ -0,0 +1,15 @@
|
||||
// Test of simple enum error - name already used
|
||||
|
||||
byte val;
|
||||
|
||||
enum State {
|
||||
OFF,
|
||||
ON = val
|
||||
};
|
||||
|
||||
void main() {
|
||||
enum State state = ON;
|
||||
const byte* SCREEN = 0x0400;
|
||||
*SCREEN = state;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user