Skip to main content

Fixing Bugs, Writing Tests and Error Handling in the Lexer/Scanner

· One min read
Abhinn Pandey

Fixing Bugs is like being the Culprit and Detective in an Thriller Movie

Its Pretty Hard to detect Bugs and also to not Add anymore while fixing them, so Lets Write some Tests to Find them and to maintain the quality of the code.

Tests are Basically an INPUT of an experssion and the expected OUTPUT of the expression. For Example

  • INPUT :- add(1,2)
  • EXPECTED OUTPUT :- 3
  • OUTPUT :- 5
  • TEST RESULT :- FAIL

In Rust, we can use assert_eq!() macro to check these Tests,

Error Handling !!

The tools our language provides for dealing with errors make up a large portion of its user interface. When the user’s code is working, they aren’t thinking about our language at all—their headspace is all about their program. It’s usually only when things go wrong that they notice our implementation.

When that happens, it’s up to us to give the user all the information they need to understand what went wrong and guide them gently back to where they are trying to go.