Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow leading whitespace before steps #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, fina
}
}

// Allow leading whitespace.
lineStart = Strings.removeLeadingSpaces(lineStart);

logger.debug("Autocompletion offset: {} partition text: {}", offset, partitionText);
logger.debug("Autocompletion line start: {}", lineStart);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,8 @@ private void consolidateFragments() {
log.error("Failed to consolidate fragments", e);
}

int expected = 0;
for(Fragment fragment : fragments) {
if(fragment.offset!=expected)
log.warn("humpff");
log.debug("fragment: {}, {}, {}", o(fragment.offset, fragment.length, fragment.token.getData()));
expected = fragment.offset + fragment.length;
log.debug("fragment: {}, {}, {}", o(fragment.offset, fragment.length, fragment.token.getData()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ public void parse(CharIterator it, int baseOffset, StoryVisitor visitor) {
if (read == CharIterator.EOF) {
break;
}
line.append((char) read);

// Allow leading whitespace on steps
if(offset == line.offset && Character.isSpaceChar(read)) {
line.reset(offset+1);
}
else {
line.append((char)read);
}

if (isNewlineCharacter(read)) {
if (line.startsWithBreakingKeyword(tree, block)) {
block.emitTo(visitor);
Expand Down
22 changes: 22 additions & 0 deletions org.jbehave.eclipse/test/data/LeadingWhitespace.story
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Narrative:
In order to be more communicative
As a story writer
I want to explain the use of And steps and also show that I can use keywords in scenario title and comments

Scenario: And steps should match the previous step type

Given a 5 by 5 game
When I toggle the cell at (2, 3)
Then the grid should look like
.....
.....
.....
..X..
.....
When I toggle the cell at (2, 4)
Then the grid should look like
.....
.....
.....
..X..
..X..
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ public void parse_case1() throws IOException {

assertElements(expected, parser.parse(storyAsText));
}

@Test
public void parse_cas1_with_leading_whitespace() throws IOException {
String story = "/data/LeadingWhitespace.story";
String storyAsText = readToString(story);

String[] expected = {
"offset: 0, length: 11, content: >>Narrative:\n<<", //
"offset: 12, length: 34, content: >>In order to be more communicative\n<<", //
"offset: 51, length: 18, content: >>As a story writer\n<<", //
"offset: 69, length: 109, content: >>I want to explain the use of And steps and also show that I can use keywords in scenario title and comments\n\n<<", //
"offset: 178, length: 57, content: >>Scenario: And steps should match the previous step type\n\n<<", //
"offset: 235, length: 20, content: >>Given a 5 by 5 game\n<<", //
"offset: 255, length: 33, content: >>When I toggle the cell at (2, 3)\n<<", //
"offset: 288, length: 61, content: >>Then the grid should look like\n.....\n.....\n.....\n..X..\n.....\n<<", //
"offset: 349, length: 33, content: >>When I toggle the cell at (2, 4)\n<<", //
"offset: 382, length: 61, content: >>Then the grid should look like\n.....\n.....\n.....\n..X..\n..X..\n<<" };

assertElements(expected, parser.parse(storyAsText));
}

@Test
public void parse_case2() throws Exception {
Expand Down