/** Test that matching of full names works. Bug #859. */ @Test public void matchesFullName() { char c = File.separatorChar; IFileAnalyzerFactory faf = AnalyzerGuru.find(c + "path" + c + "to" + c + "Makefile"); assertSame(ShAnalyzerFactory.class, faf.getClass()); faf = AnalyzerGuru.find("GNUMakefile"); assertSame(ShAnalyzerFactory.class, faf.getClass()); }
@Test public void rfe3401() { IFileAnalyzerFactory f1 = AnalyzerGuru.find("main.c"); assertNotNull(f1); IFileAnalyzerFactory f2 = AnalyzerGuru.find("main.cc"); assertNotNull(f2); assertNotSame(f1.getClass(), f2.getClass()); }
@Test public void testUTF8ByteOrderMark() throws Exception { byte[] xml = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF, // UTF-8 BOM '<', '?', 'x', 'm', 'l', ' ', 'v', 'e', 'r', 's', 'i', 'o', 'n', '=', '"', '1', '.', '0', '"', '?', '>' }; ByteArrayInputStream in = new ByteArrayInputStream(xml); IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "/dummy/file"); assertSame(XMLAnalyzer.class, fa.getClass()); }
/** Test that we get the correct analyzer if the file name exactly matches a known extension. */ @Test public void testFileNameSameAsExtension() throws Exception { ByteArrayInputStream in = new ByteArrayInputStream("#!/bin/sh\nexec /usr/bin/zip \"$@\"\n".getBytes("US-ASCII")); String file = "/dummy/path/to/source/zip"; IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, file); assertSame(ShAnalyzer.class, fa.getClass()); }
@Test public void testJar() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); JarOutputStream jos = new JarOutputStream(baos); jos.putNextEntry(new JarEntry("dummy")); jos.closeEntry(); jos.close(); InputStream in = new ByteArrayInputStream(baos.toByteArray()); IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "dummy"); assertSame(JarAnalyzer.class, fa.getClass()); }
@Test public void addPrefix() throws Exception { // should not find analyzer for this unlikely extension assertNull(AnalyzerGuru.find("unlikely_prefix.foo")); IFileAnalyzerFactory faf = AnalyzerGuru.findFactory(ShAnalyzerFactory.class.getName()); // should be the same factory as the built-in analyzer for sh scripts assertSame(AnalyzerGuru.find("myscript.sh"), faf); // add an analyzer for the prefix and see that it is picked up AnalyzerGuru.addPrefix("UNLIKELY_PREFIX", faf); assertSame(ShAnalyzerFactory.class, AnalyzerGuru.find("unlikely_prefix.foo").getClass()); // remove the mapping and verify that it is gone AnalyzerGuru.addPrefix("UNLIKELY_PREFIX", null); assertNull(AnalyzerGuru.find("unlikely_prefix.foo")); }
@Test public void testUTF8ByteOrderMarkPlainFile() throws Exception { byte[] bytes = { (byte) 0xEF, (byte) 0xBB, (byte) 0xBF, // UTF-8 BOM 'h', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd' }; ByteArrayInputStream in = new ByteArrayInputStream(bytes); IFileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "/dummy/file"); assertSame(PlainAnalyzer.class, fa.getClass()); }
@Test public void rfe2969() { IFileAnalyzerFactory faf = AnalyzerGuru.find("foo.hxx"); assertNotNull(faf); assertSame(CxxAnalyzerFactory.class, faf.getClass()); }
@Test public void testPlainText() throws IOException { ByteArrayInputStream in = new ByteArrayInputStream("This is a plain text file.".getBytes("US-ASCII")); assertSame(PlainAnalyzer.class, AnalyzerGuru.getAnalyzer(in, "dummy").getClass()); }