Skip to content

Commit 88781a0

Browse files
author
Laura Dean
committed
started the project, and perhaps committed roughly the right IDEA files.
0 parents  commit 88781a0

18 files changed

+347
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
out
2+
output
3+

.idea/.gitignore

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/ant.xml

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/scopes/scope_settings.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/uiDesigner.xml

+125
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

input/StandAlone.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is a stand-alone page about one thing.

src/Formatter.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class Formatter {
2+
public String format(String input) {
3+
boolean inBold = false;
4+
StringBuilder result = new StringBuilder();
5+
for (int i=0; i<input.length(); i++) {
6+
char currChar = input.charAt(i);
7+
if (currChar == '*') {
8+
if (inBold) result.append("</b>");
9+
else result.append("<b>");
10+
inBold = !inBold;
11+
} else {
12+
result.append(currChar);
13+
}
14+
}
15+
return result.toString();
16+
}
17+
}

src/Wiki.java

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import java.io.File;
2+
import java.io.FileWriter;
3+
import java.io.IOException;
4+
5+
public class Wiki {
6+
public static void main(String[] args) {
7+
try {
8+
File file = new File("output/StandAlone.html");
9+
FileWriter writer = new FileWriter(file);
10+
writer.write("<html>");
11+
writer.write("<body>");
12+
writer.write("This is a stand-alone page about one thing.");
13+
writer.write("</body>");
14+
writer.write("</html>");
15+
writer.close();
16+
} catch (Exception e) {
17+
e.printStackTrace();
18+
}
19+
}
20+
}

test/FormatterTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import org.junit.Before;
2+
import org.junit.Test;
3+
4+
import static junit.framework.Assert.assertEquals;
5+
6+
public class FormatterTest {
7+
8+
private Formatter formatter = new Formatter();
9+
10+
@Test
11+
public void shouldTurnStarredTextBold() {
12+
assertEquals("This is a <b>test</b>.", formatter.format("This is a *test*."));
13+
assertEquals("<b>This</b> way <b>also</b> works.", formatter.format("*This* way *also* works."));
14+
}
15+
}

test/WikiTest.java

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import org.hamcrest.BaseMatcher;
2+
import org.hamcrest.Description;
3+
import org.hamcrest.Matcher;
4+
import org.junit.Test;
5+
6+
import java.io.*;
7+
8+
import static org.junit.Assert.assertThat;
9+
import static org.junit.Assert.assertTrue;
10+
11+
public class WikiTest {
12+
@Test
13+
public void shouldMakeSomeOutput() throws Exception {
14+
Wiki.main(new String[0]);
15+
16+
String result = readFile("output/StandAlone.html");
17+
18+
assertThat(result, equalsIgnoreSpace("<html><body>This is a stand-alone page about one thing.</body></html>"));
19+
}
20+
21+
private static Matcher<String> equalsIgnoreSpace(final String s) {
22+
return new BaseMatcher<String>() {
23+
public boolean matches(Object o) {
24+
return s.trim().equals(((String)o).trim());
25+
}
26+
27+
public void describeTo(Description description) {
28+
description.appendText("a string equal (ignoring whitespace) to \"" + s + "\"");
29+
}
30+
};
31+
}
32+
33+
private String readFile(String fileName) throws IOException {
34+
ByteArrayOutputStream result = new ByteArrayOutputStream();
35+
PrintStream resultStream = new PrintStream(result);
36+
BufferedReader reader = new BufferedReader(new FileReader(fileName));
37+
while (reader.ready()) {
38+
resultStream.println(reader.readLine());
39+
}
40+
reader.close();
41+
return result.toString();
42+
}
43+
}

wiki.iml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8+
</content>
9+
<orderEntry type="inheritedJdk" />
10+
<orderEntry type="sourceFolder" forTests="false" />
11+
<orderEntry type="module-library">
12+
<library>
13+
<CLASSES>
14+
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.10.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>
22+

0 commit comments

Comments
 (0)