From: Phlip Date: 2007-01-04T09:10:15+09:00 Subject: Re: how to lex javascript for an assert_js system? spooq wrote: > Could you let me know how the perl script is going, either here or off-list? Awesome - it works perfectly as a lexer, and it only produces two tiny bugs (so far). One is 'new Ajax.Updater' doesn't fly, and you need 'ajax = new Ajax.Updater'. The other is you gotta have a ; on the ends of lines. So here's a sample test case. I am attempting to test-FIRST Javascript (thru Rails). That's much harder than just acceptance-testing it thru the existing test rigs, but the rewards will be substantial. assert_xpath '/form/textarea' do |textarea| assert_js textarea.attributes['onkeydown'] do assert_xpath 'Statement[1]' do assert_xpath '//Identifier[ @name = "Callee" and . = "editor_keydown" ]' end end end assert_xpath asserts that the hidden @xdoc variable can call XPath.first() on the given string without returning nil. So you can pack lots of goodies into your XPath strings, including queries and string comparisons. The first assert_xpath calls after something generated XHTML and then loaded it into @xdoc. So we can assert this XHTML contains a FORM containing a TEXTAREA. assert_js just copies the given Javascript into a temporary file, calls jsToXml.pl on it, and loads this into @xdoc. The above test case trivially tests that