I wanted to get the list of methods of a class if their implementation has at least two occurrences of a word 'assert' in Smalltalk.
Can somebody help me with this? Thanks in advance!
I wanted to get the list of methods of a class if their implementation has at least two occurrences of a word 'assert' in Smalltalk.
Can somebody help me with this? Thanks in advance!
Copyright © 2021 Jogjafile Inc.
I'm not sure about the details of gnu-Smalltalk, but in Pharo, you can do something like this:
Here I use a trivial regex to see if I can match two "assert" words in the source code.
However, with Smalltalk, it's easy to do more precise searches. Image, you want to see if a method sends at least two
assert:
messages. You can find such methods this way:In the example above, for each method, we simply count the number of AST nodes that are message sends, and have the
assert:
selector. Then we check if the number of these nodes is greater or equal to 2.