@Test public void basicSanityFromResourceReader() throws Exception { InputStream is = UnicodeBomInputStreamTest.class.getResourceAsStream("bom.js"); UnicodeBomInputStream is2 = new UnicodeBomInputStream(is); is2.skipBOM(); InputStreamReader isr = new InputStreamReader(is2, Charset.forName("UTF-8")); String s = Util.readerToString(isr); String nl = System.getProperty("line.separator"); assertThat(s, is("// This file starts with a UTF-8 BOM." + nl + "alert(\"Hello BOM\");" + nl)); }
@Test public void canLintWithBom() throws Exception { InputStream is = UnicodeBomInputStreamTest.class.getResourceAsStream("bom.js"); UnicodeBomInputStream is2 = new UnicodeBomInputStream(is); is2.skipBOM(); InputStreamReader isr = new InputStreamReader(is2, Charset.forName("UTF-8")); JSLint jsLint = new JSLintBuilder().fromDefault(); jsLint.addOption(Option.UNDEF); JSLintResult result = jsLint.lint("bom.js", isr); assertThat(result.getIssues().size(), is(0)); }
@Test public void basicSanityFromResource() throws Exception { InputStream is = UnicodeBomInputStreamTest.class.getResourceAsStream("bom.js"); UnicodeBomInputStream is2 = new UnicodeBomInputStream(is); try { is2.skipBOM(); // Should start with a double slash then space. assertThat(is2.read(), is(0x2f)); assertThat(is2.read(), is(0x2f)); assertThat(is2.read(), is(0x20)); } finally { is2.close(); } }
@Test public void basicSanity() throws Exception { // UTF-8 BOM + "12345" ByteArrayInputStream in = new ByteArrayInputStream( new byte[] {(byte) 0xEF, (byte) 0xBB, (byte) 0xBF, 0x31, 0x32, 0x33, 0x34, 0x35}); UnicodeBomInputStream in2 = new UnicodeBomInputStream(in); try { in2.skipBOM(); assertThat(in2.read(), is(0x31)); } finally { in2.close(); } }