Skip to content

Commit

Permalink
Added some parsing failures unit tests (asserting that does not parse…
Browse files Browse the repository at this point in the history
… some bad code)
  • Loading branch information
sthilaid committed Apr 10, 2012
1 parent 1a40aaf commit dd96fc9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dcpu/parser/dcpuLex.go
Expand Up @@ -175,5 +175,5 @@ loop:
}

func (DCPULex) Error(s string) {
println("syntax error!")
panic("syntax error!")
}
64 changes: 47 additions & 17 deletions dcpu/parser/dcpuParser_test.go
Expand Up @@ -87,26 +87,56 @@ func TestParsing4(t *testing.T) {
}
}


/*
func TestParsing1(t *testing.T) {
//-----------------------------------------------------------------------------
// Parsing failure checks

func TestParsingFailure0(t *testing.T) {
defer func() {
if panic := recover(); panic == nil {
t.Errorf("Should not parse code with invalid syntax (missing ',')...")
}
}()

lex := new(DCPULex)
lex.code = "ADD [0xAAAA], 0xFF00 SET PUSH, [0xAAAA]"
// missing a "," after 'a'
lex.Init("SET PUSH 0x10")
yyParse(lex)
}

var expr0 DcpuExpression
var expr1 DcpuExpression
var ref0 DcpuReference
func TestParsingFailure1(t *testing.T) {
defer func() {
if panic := recover(); panic == nil {
t.Errorf("Should not permit addition outside ref...")
}
}()

lex := new(DCPULex)
// not allowed to have addition outside a reference
lex.Init("SET 0x10+B, 0x10")
yyParse(lex)
}

expr0.inst = DcpuInstruction("ADD")
ref0 = DcpuLitteral(0xaaaa)
expr0.a = ref0
expr0.b = DcpuLitteral(0xff00)
func TestParsingFailure2(t *testing.T) {
defer func() {
if panic := recover(); panic == nil {
t.Errorf("Should not be allowed to referece special registers...")
}
}()

lex := new(DCPULex)
// not allowed to have addition outside a reference
lex.Init("SET [SP], 0x0")
yyParse(lex)
}

expr1.inst = DcpuInstruction("SET")
//...
ast := new(DcpuProgram)
ast.expressions = []DcpuExpression{expr0, expr1}
func TestParsingFailure3(t *testing.T) {
defer func() {
if panic := recover(); panic == nil {
t.Errorf("Should not parse invalid instructions...")
}
}()

lex := new(DCPULex)
lex.Init("SOT A, 0x0")
yyParse(lex)
}
*/

0 comments on commit dd96fc9

Please sign in to comment.