Hi, I recently tried writing my own logic for commenting and uncommenting lines. It has several requirements, and so I wanted to write unit tests for my logic.
I tried following https://leoeditor.com/unitTesting.html but it did not really work for my use case. What I'm doing: Creating a @command node called "toggle-comments", and all the Python code under it handles the logic. I have several sub nodes that handle commenting/uncommenting a given line. None of those nodes are Leo-aware. At the top level function, I take all the relevant input from Leo and pass it on to these functions to get my results, and then put it back in the Leo node I ran the command from. Bottom line: I need to unit test those sub nodes. Each subnode is a simple Python function. As an example, here is a function: def uncomment_line_single(line, delimiter): """ Uncomment a line with a single delimiter. """ if not line.strip(): return line delimiter_index = re.search(re.escape(delimiter), line).start() white_space = line[:delimiter_index] content = line[delimiter_index+len(delimiter):] # This is assuming that some editor inserted the whitespace while # adding the comment marker. if content.startswith(' '): content = content[1:] return "%s%s" % (white_space, content) The trouble I'm having with @test is finding a way to refer to this function. If I create a sibling @test node, it has no idea that the uncomment_line_single function exists. Is there a better way? Thanks. -- You received this message because you are subscribed to the Google Groups "leo-editor" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/leo-editor. For more options, visit https://groups.google.com/d/optout.
