How to test substitution actions?

Hello,

how can I write a test to verify that my node substitution actions are working correctly?

I have four actions implemented.

  • remove all defaults: clears the substitution menu (btw. the confluence page says that this "removes all default actions and adds only those actions which are specified in the actions language", while the MPS Book says about this action "This action type lets you remove all items that were provided by the substitution menu default construction mechanism." What is true?!
  • three actions that add custom items very selectively

I tried to use a NodeTest and figured the @check scope@ annotation might be the right way to go, but as soon as I add this annotation, my condition for my action is not even hit anymore. In other words, without the annotion, I can see by invoking the substituion menu manually, that my action is applied and works as expected. With the annotation, however, the action is not invoked anymore.

My questions are:

  1. Is this even the reight way to test my action?
  2. If yes, can somebody maybe explain why the action is not invoked once there is an annotation?

Thanks,

Robert

3 comments

I would recommend using the EditorTest and check availability of the requested actions with the "type" test action. Would this work?

Vaclav

 

0

Hi Vaclav,

I don't think this solves my issue, but then again maybe I don't fully get it?

If I create an EditorTest case, my understanding is that I can use the "type" test action to command the test to type something. How would this allow me to see if the items in my substitution menu are the ones I expect?

As an example, let's say I want to make sure in a certain context, the substitution menu onyl offers "Apples, Bananas, Oranges". In my language, by default, it would allow all sorts of fruits. However, since wrote a clever Substitution Action, the menu only contains the three I mentioned.

Now I want to write a test that checks if, in a given context, the substitution menu does indeed only contain the three items.

Thanks,

Robert

0

Hi Robert,

substitute actions enhance the editor functionality and thus editor tests should be used to test them. The "Complete" action simulates "Control + Space" and if the typed string matches an entry in the menu, it is inserted into the editor. Additionally, the "editor component" expression can be used to inspect or manipulate the state of the current editor component, including its substitute menu. I've added a few examples to the doc at https://confluence.jetbrains.com/display/MPSD34/Testing+languages#Testinglanguages-Inspectingtheeditorstate

Vaclav

 

1

Please sign in to leave a comment.