Skip to content

Commit

Permalink
Text addon tests no longer depend on network connectivity
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Apr 11, 2014
1 parent ee7706e commit 5d052f9
Show file tree
Hide file tree
Showing 312 changed files with 1,000,000 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.jboss.forge.addon.text.highlight.scanner;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -21,28 +19,21 @@
public abstract class AbstractScannerTestCase
{

private static final Charset DEFAULT_CHARSET = Charset.forName("ISO-8859-1");

public static final String ASSERT_ENCODER = "TEST";
{
Syntax.builtIns();
Encoder.Factory.registrer(ASSERT_ENCODER, AssertEncoder.class);
}

public static String OUTPUT = "target/examples";
public static String BASE_URL = "https://raw.github.com/rubychan/coderay-scanner-tests/master/";
public static String OUTPUT = "src/test/resources/examples";
public static Pattern MATCH_DATA = Pattern.compile("(.*)\\..*\\..*");

protected String fetch(String type, String example) throws Exception
{
Path sourcePath = Paths.get(OUTPUT, type, example);
if (!Files.exists(sourcePath))
{
sourcePath.getParent().toFile().mkdirs();
URL source = new URL(BASE_URL + type + "/" + example);
System.out.println("Fetching " + source);
Files.write(sourcePath, asByteArray(new BufferedInputStream(source.openStream())), StandardOpenOption.WRITE,
StandardOpenOption.CREATE);
}
return new String(Files.readAllBytes(sourcePath));
return new String(Files.readAllBytes(sourcePath), DEFAULT_CHARSET);
}

private String expectedName(String example)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
directive(#!/bin/sh)

ident(perl) operator(-)ident(e)string('s/to=5/to=10/') plain(/)method(test)plain(/)ident(file)
method(echo) string<delimiter(")content(Parsed at <%= Time.now %>)delimiter(")>
method(echo) string<delimiter(")content(Executed at `Date`)delimiter(")>
method(command) string('open quote
other_command
)
7 changes: 7 additions & 0 deletions text/src/test/resources/examples/bash/erb_bash.in.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

perl -e's/to=5/to=10/' /test/file
echo "Parsed at <%= Time.now %>"
echo "Executed at `Date`"
command 'open quote
other_command
Loading

0 comments on commit 5d052f9

Please sign in to comment.