Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Snippets improvements
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Uniwares
Tomato Guru

Portugal
2322 Posts

Posted - Aug 27 2020 :  04:26:15 AM  Show Profile  Reply with Quote
I am missing some macros in the snippets that allow me to manipulate the classname, or, support for Test frameworks (the later is probably the harder to implement).

I am doing lots of unit testing lately and have quite a few snippets prepared for that, but one thing I always miss is to insert into the test class, the name of the class I am testing. Like this:

Snippet:

	[TestMethod()]
	public void TestSingleton()
	{
		$ClassName$ sng = $ClassName$.Instance;
		Assert.IsNotNull(sng);
		Assert.AreEqual(sng, $ClassName$.Instance);
	}


Now point is that this snippet is inserted into classes that tests another class (with a patterned similar name), so $classname$ does not resolve to the correct one. So I need MySingletone as classname but I have MySingletonTest instead.

If I could do something like: $left($classname$, $len($classname$)-4) I am settled. Of course, something like $TestClassName$ would be more elegant :)

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 27 2020 :  07:55:08 AM  Show Profile  Reply with Quote
How about getting the Snippet to prompt you for the target class name, using the current, test class name, as the default value? Then you can just edit the test class name to become the class name that is going to be tested, and this edited value will be inserted everywhere you want inside the snippet?

This example snippet does this, via the key bit:

$TargetClass=$ClassName$$

and here is the full test snippet, just copy and paste the XML into your VA Snippet editor:

<VA_Snippet>
<Language>C#</Language>
<Title />
<Shortcut>single</Shortcut>
<Description />
<Code>[TestMethod()]
public void TestSingleton()
{
	$TargetClass=$ClassName$$ sng = $TargetClass$.Instance;
	Assert.IsNotNull(sng);
	Assert.AreEqual(sng, $TargetClass$.Instance);
}
</Code>
</VA_Snippet>

When using this snippet edit the test class name by pressing backspace 4 times to take off the "Test" at the end, then press Enter to accept this value, which will then be used for all instances of $TargetClass$ in the inserted snippet.

zen is the art of being at one with the two'ness

Edited by - feline on Aug 27 2020 07:56:22 AM
Go to Top of Page

Uniwares
Tomato Guru

Portugal
2322 Posts

Posted - Aug 27 2020 :  08:44:14 AM  Show Profile  Reply with Quote
This actually kinda works, not as smooth as string operations, but feasible. Even works when using $TargetClass$ in comments in the snippet. Thanks for the idea.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 27 2020 :  10:56:39 AM  Show Profile  Reply with Quote
I have added this example to the feature requests for programming inside snippets, but still not sure it's the "right" approach, simply given that IDE macros were so little used Microsoft removed them. Plus as a rule when I used to suggest solving problems with IDE macros it tended to get a less than eager reaction. Still:

case=68740

zen is the art of being at one with the two'ness
Go to Top of Page

Uniwares
Tomato Guru

Portugal
2322 Posts

Posted - Aug 27 2020 :  11:02:32 AM  Show Profile  Reply with Quote
I guess its a matter of use-case. Maybe more examples and more complex ones can improve acceptance?
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Aug 28 2020 :  06:37:36 AM  Show Profile  Reply with Quote
My personal reaction is "not another macro language to learn" when this idea comes up.

I understand why people didn't like that the old IDE macros used VBScript, but at least this was a known language you could get a book on, not a program specific macro language you have to learn just enough of to do something useful. It seems that most other programs that I use that support macros use their own languages, which is just another barrier to entry.

I find myself in two minds here. I made good use of IDE macros back in the day, but saw very little evidence that our users used them, or were interested in using them as solutions for problems. I just wonder if the investment would be worth the effort.

zen is the art of being at one with the two'ness
Go to Top of Page

Uniwares
Tomato Guru

Portugal
2322 Posts

Posted - Aug 28 2020 :  06:51:00 AM  Show Profile  Reply with Quote
I actually think that people dont use it because they dont know where and whats the benefit. Good examples can change that. Personally I use them a lot for repeating tasks that I can not solve through other means. Like Unit tests for example, its the same all over again and again, just with different classes. Perfect application for snippets, macros, whatever you call them. The "cookiecutter" (stupid name) is not much else, just downloads some more stuff and copies templates.
So may a brainstorming session on what can be done with snippets may be the way to go. I guess there is not too much feedback on snippets from users.
Do you do telemetry in VA? You should. Might give you some insights to the snippets too.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
19024 Posts

Posted - Sep 02 2020 :  2:41:24 PM  Show Profile  Reply with Quote
I don't think we do have telemetry. Maybe worth thinking about, but I remember a lot of concern in some tech news reports when Windows 10 telemetry was first introduced.

As for examples, this is a good point. Do you do anything particularly clever or interesting with the current VA Snippets?

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000