News from MathTran

Just another weblog

Writing testable string manipulation code

leave a comment »

For our project we need a lot of string manipulation code. For example, given a textarea and a selection range, we want to extract the paragraph containing the selection and, later, extract the TeX code parts in that paragraph.

We decided to use test driven development for writing cross-browser code for these tasks. A set of tests is designed, which consist of input parameters and the expected output a function should return when called with the given input parameters. Whenever our function does not give the expected output an error message is printed and we know that the code is not correct.

The test framework then consists of the function X that we want to test, the tests, and a test runner function which runs the tests on X and compares the actual output with the expected output. To do this in an automated fashion, we call the js file with a JavaScript interpreter. For Windows we use SpiderMonkey (Mozilla’s implementation of JavaScript) and the build-in Windows Script Host.

After installing SpiderMonkey, we can call our script with “js X.js”, to use the Windows Script Host run “cscript X.js”

This setup allows us to test our code on Mozilla’s and Windows’ JavaScript implementation using the same test data on the command line.


Written by mystar22

June 19, 2008 at 2:07 pm

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: