Use table-driven tests for specific parsers
This commit is contained in:
parent
5869c1ea18
commit
f248ece3aa
12 changed files with 355 additions and 167 deletions
16
spec/runtime/languages/arithmetic/errors.txt
Normal file
16
spec/runtime/languages/arithmetic/errors.txt
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
=====================================================
|
||||
recovers from errors at the top level
|
||||
=====================================================
|
||||
x * * y
|
||||
---
|
||||
(ERROR)
|
||||
|
||||
=====================================================
|
||||
recovers from errors inside parenthesized expressions
|
||||
=====================================================
|
||||
x + (y * + z) * 5
|
||||
---
|
||||
(expression
|
||||
(term (factor (variable)))
|
||||
(plus)
|
||||
(term (factor (ERROR)) (times) (factor (number))))
|
||||
54
spec/runtime/languages/arithmetic/main.txt
Normal file
54
spec/runtime/languages/arithmetic/main.txt
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
====================
|
||||
parses numbers
|
||||
===================
|
||||
5
|
||||
---
|
||||
(expression (term (factor (number))))
|
||||
|
||||
===================
|
||||
parses variables
|
||||
===================
|
||||
x
|
||||
---
|
||||
(expression (term (factor (variable))))
|
||||
|
||||
===================
|
||||
parses products
|
||||
===================
|
||||
x * x
|
||||
---
|
||||
(expression (term
|
||||
(factor (variable))
|
||||
(times)
|
||||
(factor (variable))))
|
||||
|
||||
===================
|
||||
parses sums
|
||||
===================
|
||||
x + x
|
||||
---
|
||||
(expression
|
||||
(term (factor (variable)))
|
||||
(plus)
|
||||
(term (factor (variable))))
|
||||
|
||||
====================
|
||||
parses complex trees
|
||||
====================
|
||||
x * y + z * a
|
||||
---
|
||||
(expression
|
||||
(term (factor (variable)) (times) (factor (variable)))
|
||||
(plus)
|
||||
(term (factor (variable)) (times) (factor (variable))))
|
||||
|
||||
=================================
|
||||
handles parenthesized expressions
|
||||
=================================
|
||||
x * (y + z)
|
||||
---
|
||||
(expression
|
||||
(term (factor (variable))
|
||||
(times)
|
||||
(factor (expression (term (factor (variable))) (plus) (term (factor (variable)))))))
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue