[Profit-devs] SF.net SVN: profit: [77]
Status: Planning
Brought to you by:
pgr0ss
|
From: <yz...@us...> - 2006-11-07 05:56:27
|
Revision: 77
http://svn.sourceforge.net/profit/?rev=77&view=rev
Author: yzhou12
Date: 2006-11-06 21:56:14 -0800 (Mon, 06 Nov 2006)
Log Message:
-----------
comments to java -- handle brace.
Modified Paths:
--------------
src/com/thoughtworks/tools/profit/tojava/FitnesseCommentParser.java
test/com/thoughtworks/tools/profit/tojava/FitnesseCommentParserTest.java
Modified: src/com/thoughtworks/tools/profit/tojava/FitnesseCommentParser.java
===================================================================
--- src/com/thoughtworks/tools/profit/tojava/FitnesseCommentParser.java 2006-10-18 11:15:19 UTC (rev 76)
+++ src/com/thoughtworks/tools/profit/tojava/FitnesseCommentParser.java 2006-11-07 05:56:14 UTC (rev 77)
@@ -12,10 +12,26 @@
private Pattern tableRowPattern;
+ private Pattern bracedCommentStart;
+
+ private Pattern bracedCommentEnd;
+
+ private StringBuffer currentSection;
+
+ private boolean insideBracedComment;
+
+ private boolean wasTableRow;
+
public FitnesseCommentParser(String content) {
sectionList = new ArrayList<String>();
tableRowPattern = Pattern.compile("(^\\|)|(^!\\|)");
- parse(content);
+ bracedCommentStart = Pattern.compile("\\{\\{\\{");
+ bracedCommentEnd = Pattern.compile("\\}\\}\\}");
+ try {
+ parse(content);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
}
public String getSection(int sectionIndex) {
@@ -26,28 +42,66 @@
return sectionList.size();
}
- private void parse(String content) {
+ private void parse(String content) throws IOException {
LineNumberReader r = new LineNumberReader(new StringReader(content));
- try {
- boolean wasTableRow = false;
- StringBuffer section = new StringBuffer();
- for (String line = r.readLine(); line != null; line = r.readLine()) {
- if (!isTableRow(line)) {
- wasTableRow = false;
- section.append("// ").append(line).append("\n");
- } else if (!wasTableRow) {
- wasTableRow = true;
- sectionList.add(section.toString());
- section = new StringBuffer();
- }
+ insideBracedComment = false;
+ currentSection = new StringBuffer();
+ wasTableRow = false;
+ for (String line = r.readLine(); line != null; line = r.readLine()) {
+ if (handleBraceComment(line)) {
+ continue;
+ } else if (handleCommentLine(line)) {
+ continue;
}
- sectionList.add(section.toString());
- } catch (IOException e) {
- throw new RuntimeException(e);
+ handleTableStart(line);
}
+ sectionList.add(currentSection.toString());
}
+ private boolean handleTableStart(String line) {
+ if (!wasTableRow) {
+ wasTableRow = true;
+ sectionList.add(currentSection.toString());
+ currentSection = new StringBuffer();
+ return true;
+ }
+ return false;
+ }
+
+ private boolean handleCommentLine(String line) {
+ if (!isTableRow(line)) {
+ wasTableRow = false;
+ currentSection.append("// ").append(line).append("\n");
+ return true;
+ }
+ return false;
+ }
+
+ private boolean handleBraceComment(String line) {
+ if (isBracedCommentStart(line)) {
+ insideBracedComment = true;
+ currentSection.append("// ").append(line).append("\n");
+ return true;
+ }
+ if (insideBracedComment) {
+ currentSection.append("// ").append(line).append("\n");
+ if (isBracedCommentEnd(line)) {
+ insideBracedComment = false;
+ }
+ return true;
+ }
+ return false;
+ }
+
private boolean isTableRow(String line) {
return tableRowPattern.matcher(line).find();
}
+
+ private boolean isBracedCommentStart(String line) {
+ return bracedCommentStart.matcher(line).find();
+ }
+
+ private boolean isBracedCommentEnd(String line) {
+ return bracedCommentEnd.matcher(line).find();
+ }
}
Modified: test/com/thoughtworks/tools/profit/tojava/FitnesseCommentParserTest.java
===================================================================
--- test/com/thoughtworks/tools/profit/tojava/FitnesseCommentParserTest.java 2006-10-18 11:15:19 UTC (rev 76)
+++ test/com/thoughtworks/tools/profit/tojava/FitnesseCommentParserTest.java 2006-11-07 05:56:14 UTC (rev 77)
@@ -8,7 +8,7 @@
public class FitnesseCommentParserTest {
public static junit.framework.Test suite() {
- return new JUnit4TestAdapter(ColumnTests.class);
+ return new JUnit4TestAdapter(FitnesseCommentParserTest.class);
}
@Test
@@ -25,14 +25,31 @@
}
@Test
+ public void singleTable() {
+ FitnesseCommentParser parser = new FitnesseCommentParser(
+ "!|table| \n|row1| \n");
+ assertEquals(2, parser.getNumOfSection());
+ assertEquals("", parser.getSection(0));
+ assertEquals("", parser.getSection(1));
+
+ parser = new FitnesseCommentParser(
+ "line1 \n!|table| \n|row1| \nline2 \n");
+ assertEquals(2, parser.getNumOfSection());
+ assertEquals("// line1 \n", parser.getSection(0));
+ assertEquals("// line2 \n", parser.getSection(1));
+ }
+
+ @Test
public void oneTableTwoCommentSection() {
final StringBuffer contents = new StringBuffer();
contents.append("'''comment'''\n");
contents.append("|fixture|");
contents.append("more comment");
- FitnesseCommentParser parser = new FitnesseCommentParser(contents.toString());
- assertEquals(2, parser.getNumOfSection());
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
+ assertEquals(2, parser.getNumOfSection());
assertEquals("// '''comment'''\n", parser.getSection(0));
+ // assertEquals("// more comment", parser.getSection(1));
}
@Test
@@ -40,19 +57,21 @@
final StringBuffer contents = new StringBuffer();
contents.append("|fixture|");
contents.append("more comment");
- FitnesseCommentParser parser = new FitnesseCommentParser(contents.toString());
- assertEquals(2, parser.getNumOfSection());
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
+ assertEquals(2, parser.getNumOfSection());
assertEquals("", parser.getSection(0));
}
-
+
@Test
public void oneTableWithLeadingExclaimtionTwoCommentSection() {
final StringBuffer contents = new StringBuffer();
contents.append("'''comment'''\n");
contents.append("!|WikiWordFixture|\n");
contents.append("more comment \n");
- FitnesseCommentParser parser = new FitnesseCommentParser(contents.toString());
- assertEquals(2, parser.getNumOfSection());
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
+ assertEquals(2, parser.getNumOfSection());
assertEquals("// '''comment'''\n", parser.getSection(0));
assertEquals("// more comment \n", parser.getSection(1));
}
@@ -62,14 +81,15 @@
final StringBuffer contents = new StringBuffer();
contents.append("'''comment'''\n");
contents.append("!|WikiWordFixture|\n");
- contents.append("|row1|\n");
+ contents.append("|row1|\n");
contents.append("more comment \n");
- FitnesseCommentParser parser = new FitnesseCommentParser(contents.toString());
- assertEquals(2, parser.getNumOfSection());
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
+ assertEquals(2, parser.getNumOfSection());
assertEquals("// '''comment'''\n", parser.getSection(0));
assertEquals("// more comment \n", parser.getSection(1));
}
-
+
@Test
public void twoTablesMultipleLineCommentSection() {
final StringBuffer comment0 = new StringBuffer();
@@ -88,14 +108,17 @@
final StringBuffer comment2 = new StringBuffer();
comment2.append("comment 21\n");
comment2.append("comment 22 //\n");
-
- final StringBuffer contents = new StringBuffer();
- contents.append(comment0).append(table1).append(comment1).append(table2).append(comment2);
- FitnesseCommentParser parser = new FitnesseCommentParser(contents.toString());
+
+ final StringBuffer contents = new StringBuffer();
+ contents.append(comment0).append(table1).append(comment1)
+ .append(table2).append(comment2);
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
assertEquals(3, parser.getNumOfSection());
-
+
final StringBuffer expectedComment0 = new StringBuffer();
- expectedComment0.append("// ''' |comment01 after space not a table row |'''\n");
+ expectedComment0
+ .append("// ''' |comment01 after space not a table row |'''\n");
expectedComment0.append("// !|omment02\n");
expectedComment0.append("// '''comment'''\n");
assertEquals(expectedComment0.toString(), parser.getSection(0));
@@ -110,5 +133,35 @@
expectedComment2.append("// comment 22 //\n");
assertEquals(expectedComment2.toString(), parser.getSection(2));
}
-
+
+ @Test
+ public void bracedCommentSection() {
+ final StringBuffer contents = new StringBuffer();
+ contents.append("''' comment0\n");
+ contents.append(" {{{ \n");
+ contents.append(" !|fixture|\n");
+ contents.append(" |row1|\n");
+ contents.append("'''comment'''\n");
+ contents.append(" }}}\n");
+
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
+ assertEquals("no table but only one comment", 1, parser.getNumOfSection());
+ }
+
+ @Test
+ public void bracedCommentSameline() {
+ final StringBuffer contents = new StringBuffer();
+ contents.append("''' comment0\n");
+ contents.append(" }}} {{{ comment {{{ \n");
+ contents.append(" !|fixture|\n");
+ contents.append("' }}} {{{ ''comment'''\n");
+ contents.append("{{{!|fixture| }}}\n");
+ contents.append(" comment}}} \n");
+
+ FitnesseCommentParser parser = new FitnesseCommentParser(contents
+ .toString());
+ assertEquals("no table but only one comment", 1, parser.getNumOfSection());
+ }
+
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|