<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>non-random ramble &#187; regex</title>
	<atom:link href="http://jimbarritt.com/non-random/category/regex/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Tue, 20 Sep 2011 13:16:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Make Fireworks IntelliJ Plugin Ignore Integration Tests</title>
		<link>http://jimbarritt.com/non-random/2010/05/28/make-fireworks-intellij-plugin-ignore-integration-tests/</link>
		<comments>http://jimbarritt.com/non-random/2010/05/28/make-fireworks-intellij-plugin-ignore-integration-tests/#comments</comments>
		<pubDate>Fri, 28 May 2010 10:37:00 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=497</guid>
		<description><![CDATA[http://www.wafermaneuver.com/nick/img/photo/fireworks2.jpg The Fireworks Plugin for IntelliJ allows you to automatically run all your unit tests when you make a change to the code. Its a well behaved plugin, it allows you to configure wether or not to do this so you can just turn it on or off. Whilst using it I made a detour [...]]]></description>
			<content:encoded><![CDATA[<p><img width="400" src="http://www.wafermaneuver.com/nick/img/photo/fireworks2.jpg" /><br />
<code>http://www.wafermaneuver.com/nick/img/photo/fireworks2.jpg</code></p>
<p>The <a href="http://plugins.intellij.net/plugin/?id=1106">Fireworks</a> Plugin for IntelliJ allows you to automatically run all your unit tests when you make a change to the code. </p>
<p>Its a well behaved plugin, it allows you to configure wether or not to do this so you can just turn it on or off. </p>
<p>Whilst using it I made a detour to <a href="http://blog.gigoo.org/2010/05/26/how-can-pomodore-help-you-shave-a-yak/">Shave a couple of Yaks</a>. So thought I&#8217;d document it here.</p>
<p>I found it was also running some integration tests which relied on the file system and so didn&#8217;t work because there doesn&#8217;t appear to be a way to specify the working directory (you can specify JVM args so I could use that instead. I submitted an <a href="http://code.google.com/p/dontmakemetest/issues/detail?id=4">issue</a>. </p>
<p>In the mean time, actually I thought I would rather not run my integration tests. Fortunately Fireworks allows a regex pattern to decide which files are tests.</p>
<p>After some hunting, I found the <a href="http://stackoverflow.com/questions/406230/regular-expression-to-match-string-not-containing-a-word">following post</a> on stack overflow which gave me the clues i needed to include <code>Test</code> but <strong>not</strong> <code>IntegrationTest</code>.</p>
<p>The solution takes advantage of <a href="http://www.regular-expressions.info/lookaround.html">&#8220;lookaround&#8221;</a> features of regex. The syntax in question is:</p>
<pre name='code' class='java:nogutter:nocontrols'>
(?!Integration)
</pre>
<p>The <code>(?!  regex )</code> syntax means negative look ahead. You can put any regex in there. In our case, just &#8220;Integration&#8221;. This says, something not followed by &#8220;Integration&#8221;.</p>
<p>The code on stack overflow had some unnescessary syntax at the beginning (^) and I changed the ordering around a bit to make it read more logically.</p>
<pre name='code' class='java:nogutter:nocontrols'>
(.(?!Integration))*Test
</pre>
<p>The first &#8220;<code>^</code>&#8221; was unnescessary, and putting the &#8220;<code>.</code>&#8221; first made it read better i think. The parentheses are to provide some structure (regex groups) more than any functional reason. </p>
<p>So in words, the new expression reads &#8220;match any repeating character (<code>.*</code>) not followed by &#8220;Integration&#8221; <code>(?!Integration)</code>), then only match if &#8220;Test&#8221; is on the end.</p>
<p>Here is a test case for it (which along with some other regex stuff can be found on <a href="http://github.com/jimbarritt/spikes/tree/master/regex/src/test/unit/java/com/jimbarritt/spikes/regex/">Github</a> :</p>
<pre name='code' class='java:nogutter:nocontrols'>
    @Test
    public void matchesUnitTestsButNotIntegrationTests() {
        String expression = &#8220;(.(?!Integration))*Test&#8221;;
        Pattern pattern = Pattern.compile(expression);
        assertThat(pattern.matcher(&#8220;SomeUnitTest&#8221;).matches(), is(true));
        assertThat(pattern.matcher(&#8220;SomeIntegrationTest&#8221;).matches(), is(false));
        assertThat(pattern.matcher(&#8220;SomeNonTestClass&#8221;).matches(), is(false));
    }
</pre>
<p>I found it hard to get this to work on the command line with grep. But I&#8217;ve got too much YAK HAIR on my floor now!</p>
<p>Now the Yaks are shaved I can go back to putting a system property in to allow my integration test to work.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2010%2F05%2F28%2Fmake-fireworks-intellij-plugin-ignore-integration-tests%2F&amp;title=Make%20Fireworks%20IntelliJ%20Plugin%20Ignore%20Integration%20Tests"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2010/05/28/make-fireworks-intellij-plugin-ignore-integration-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sweet Search And Highlight Command</title>
		<link>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/</link>
		<comments>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 17:40:49 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[linux commands]]></category>
		<category><![CDATA[os x]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/</guid>
		<description><![CDATA[Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files: grep -r Hoffman */*.tex &#124; less +/Hoffman Where &#8220;Hoffman&#8221; is the search term which can of course be any regular expression. The &#8220;less&#8221; command has a very [...]]]></description>
			<content:encoded><![CDATA[<p>Been doing quite a bit of manipulating LaTeX files on the command line recently, and have a very sweet little command for searching for text in multiple files:</p>
<p><code>grep -r Hoffman */*.tex | less +/Hoffman</code></p>
<p>Where &#8220;Hoffman&#8221; is the search term which can of course be any regular expression.</p>
<p>The &#8220;less&#8221; command has a very convenient argument &#8220;+&#8221; which allows you to pass a search term in and will automatically highlight it for you.</p>
<p>The -r in grep recurses directories and */*.tex looks for all tex files. the | pipes the result to less.</p>
<p>sweet.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2007%2F07%2F15%2Fsweet-search-and-highlight-command%2F&amp;title=Sweet%20Search%20And%20Highlight%20Command"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2007/07/15/sweet-search-and-highlight-command/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

