I am trying to write an “unit test” by using an assert macro that was suggested in another topic some time ago.
Here’s my code so far:
\widget $assert.equal(name, param1, param2)
<<name>>
<%if [<param1>match<param2>] %>
OK
<%else%>
FAIL
<!-- Display variables -->
param1=<<param1>>, param2=<<param2>>
<%endif%>
\end
\function .get_line_number_from_str(str, line_number)
[<str>splitregexp[\n]first<line_number>last[1]]
\end
<$vars text="line1\n\line2\nline3" line_number="1" line1="line1" >
<$assert.equal name="Test that line <<line_number>> from '<<text>>' == '<<line1>>'" param1=<<.get_line_number_from_str <<text>>,<<line_number>>>> param2=<<line1>> />
</$vars>
which renders to:
Test that line 1 from 'line1\n\line2\nline3' == 'line1' FAIL param1=<<text, param2=
Besides needing help with fixing the test, I’d like suggestions on the following issues:
- lack of syntax highlight when writing code logic wikitext (I use the CodeMirror vanilla plugin) is extremely painful. how do you write complex functions/macros/filters/whatever without it? the above code snippet is already big enough to overflow my mental model
- lack of a built-in wikitext linter that could produce relevant and helpful error messages is even more painful. By looking at my failed unit test output, I could assume the problem might be a syntax error (like the typical misuse of dreaded brackets for example), but I’m no wikitext guru, I’m a learning starter and I could really use some instructive feedback of a tool as alternative to nagging the more experienced audience of this forum every time a piece of my code doesn’t work[1]
- I truly hope that the “rantish” tone of this post is for a good cause - I have to “scream” my pain, because the gap between hello world level wikitext code and a minimalistic wikitext snippet that is practically useful seems to be a bit too big for my taste. And the resort to unit testing is an attempt to bridge this gap and boost my learning “independence” - as in so I could advance faster on my own, by relying more on “best practices” rather than creating too many help request posts in the forum.