KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ruby > RubyMimeResolverTest


1 /*
2  * RubyMimeResolverTest.java
3  * JUnit based test
4  *
5  * Created on November 6, 2006, 12:24 PM
6  */

7 package org.netbeans.modules.ruby;
8
9 import junit.framework.TestCase;
10
11 import java.io.ByteArrayOutputStream JavaDoc;
12 import java.io.ByteArrayOutputStream JavaDoc;
13 import java.io.StringWriter JavaDoc;
14
15 import org.netbeans.modules.ruby.RubyMimeResolver;
16
17
18 /**
19  *
20  * @author Tor Norbye
21  */

22 public class RubyMimeResolverTest extends TestCase {
23     public RubyMimeResolverTest(String JavaDoc testName) {
24         super(testName);
25     }
26
27     private boolean checkValidHeader(String JavaDoc header) {
28         byte[] h = header.getBytes();
29
30         return RubyMimeResolver.isRubyHeader(h);
31     }
32
33     public void testRubyHeader() {
34         assertTrue(checkValidHeader("#!/usr/bin/ruby"));
35         assertTrue(checkValidHeader("#!/usr/bin/jruby"));
36         assertTrue(checkValidHeader("#! /usr/bin/ruby"));
37         assertTrue(checkValidHeader("#! /usr/bin/ruby\n"));
38         assertTrue(checkValidHeader("#! /usr/bin/ruby.exe"));
39         assertTrue(checkValidHeader("#! /usr/bin/ruby.exe "));
40         assertTrue(checkValidHeader("#!C:\\programs\\ruby.exe"));
41         assertTrue(checkValidHeader("#!C:\\programs\\ruby.exe"));
42         assertTrue(!checkValidHeader("# !C:\\programs\\ruby.exe"));
43         assertTrue(!checkValidHeader("#!/usr/bin/jjruby"));
44         assertTrue(!checkValidHeader("#!/usr/bin/rubyy"));
45         assertTrue(!checkValidHeader("#!/usr/bin/rub"));
46         assertTrue(!checkValidHeader("#!/usr/bin/"));
47         assertTrue(!checkValidHeader("#! /usr/bin/rub\ny"));
48         assertTrue(!checkValidHeader("#! /usr/b\nin/ruby"));
49         assertTrue(!checkValidHeader("#/usr/bin/ruby"));
50         assertTrue(!checkValidHeader("# !C:\\programs\\ruby.foo"));
51
52         assertTrue(checkValidHeader("#!/usr/bin/env ruby"));
53         assertTrue(checkValidHeader("#!/usr/bin/env jruby"));
54         assertTrue(checkValidHeader("#!/usr/bin/env.exe jruby"));
55         assertTrue(!checkValidHeader("#!/usr/bin/env.exe jrub"));
56         assertTrue(!checkValidHeader("#!/usr/bin/env.exe rubyy"));
57         assertTrue(!checkValidHeader("#!/usr/bin/env.txt ruby"));
58         assertTrue(!checkValidHeader("#/usr/bin/env.exe jruby"));
59         assertTrue(!checkValidHeader("#!/usr/bin/env.exejruby"));
60
61         // TODO - what about case? Is "Env" legal on Windows?
62
}
63 }
64
Popular Tags