Skip to content

Commit

Permalink
Add unit test and fix for APSTUD-3640 JavaScript Editor Adds Space Af…
Browse files Browse the repository at this point in the history
…ter Comment
  • Loading branch information
sgtcoolguy committed Oct 14, 2011
1 parent 2fee207 commit 0c1981a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Expand Up @@ -138,7 +138,6 @@ protected String getAutoIndentAfterNewLine(IDocument d, DocumentCommand c)
buf.append(indent);

String line = d.get(info.getOffset(), info.getLength());
String trimmedLine = line.trim();
int lineOffset = c.offset - info.getOffset();
String upToOffset = line.substring(0, lineOffset);

Expand Down Expand Up @@ -187,7 +186,7 @@ else if (upToOffset.trim().startsWith("/*") && !upToOffset.contains("*/")) //$NO
}
d.replace(c.offset, 0, "\n" + indent + toEnd); //$NON-NLS-1$
}
else if (buf.length() != 0 && trimmedLine.endsWith("*/") && buf.charAt(buf.length() - 1) == ' ') //$NON-NLS-1$
else if (buf.length() != 0 && upToOffset.endsWith("*/") && buf.charAt(buf.length() - 1) == ' ') //$NON-NLS-1$
{
// We want to delete an extra space when closing block comments
buf.deleteCharAt(buf.length() - 1);
Expand Down
Expand Up @@ -194,7 +194,7 @@ protected String findCorrectIndentString(IDocument d, int lineNumber, String cur
/**
* APSTUD-1218
*/
public void testDontAddStarAfterBlockComment()
public void testDontAddStarAfterBlockComment() throws Exception
{
RubyRegexpAutoIndentStrategy strategy = new AlwaysMatchRubyRegexpAutoIndentStrategy()
{
Expand All @@ -209,8 +209,13 @@ protected boolean matchesRegexp(RubyRegexp regexp, String lineContent)
// After end of block comment, don't add a star
DocumentCommand command = createNewlineCommand(12);
strategy.customizeDocumentCommand(document, command);
assertEquals("\n ", command.text);
assertTrue(command.doit);
if (command.doit)
{
document.replace(command.offset, command.length, command.text);
}
assertEquals("/**\n * \n **/\nfunction name() {\n}\n", document.get());

}

/**
Expand Down Expand Up @@ -434,6 +439,26 @@ public void testAutoCloseBlockCommentStart() throws Exception
assertEquals("/*\n * \n */", document.get());
}

/**
* APSTUD3640
*
* @throws Exception
*/
public void testDontAddLeadingSpaceAfterBlockCOmmentCloseBeforeNextLineContent() throws Exception
{
RubyRegexpAutoIndentStrategy strategy = new CSSRubleRubyRegexpAutoIndentStrategy();
IDocument document = new Document("/*\n * \n */body {}");

DocumentCommand command = createNewlineCommand(10);
strategy.customizeDocumentCommand(document, command);
assertTrue(command.doit);
if (command.doit)
{
document.replace(command.offset, command.length, command.text);
}
assertEquals("/*\n * \n */\nbody {}", document.get());
}

protected DocumentCommand createNewlineCommand(int offset)
{
return createTextCommand(offset, "\n");
Expand Down

0 comments on commit 0c1981a

Please sign in to comment.