1 7 package org.netbeans.modules.ruby; 8 9 import junit.framework.TestCase; 10 11 import java.io.ByteArrayOutputStream ; 12 import java.io.ByteArrayOutputStream ; 13 import java.io.StringWriter ; 14 15 import org.netbeans.modules.ruby.RubyMimeResolver; 16 17 18 22 public class RubyMimeResolverTest extends TestCase { 23 public RubyMimeResolverTest(String testName) { 24 super(testName); 25 } 26 27 private boolean checkValidHeader(String 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 } 63 } 64 | Popular Tags |