-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dsl): support expect property statement
- Loading branch information
Showing
8 changed files
with
205 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ermedia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/ClassParsingTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* generated by Xtext 2.18.0 | ||
*/ | ||
package app.hypermedia.testing.dsl.tests | ||
|
||
import app.hypermedia.testing.dsl.core.ClassBlock | ||
import app.hypermedia.testing.dsl.core.Model | ||
import com.google.inject.Inject | ||
import org.eclipse.xtext.testing.InjectWith | ||
import org.eclipse.xtext.testing.extensions.InjectionExtension | ||
import org.eclipse.xtext.testing.util.ParseHelper | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.^extension.ExtendWith | ||
import static org.junit.Assert.assertEquals | ||
|
||
@ExtendWith(InjectionExtension) | ||
@InjectWith(CoreInjectorProvider) | ||
class ClassParsingTest { | ||
@Inject | ||
ParseHelper<Model> parseHelper | ||
|
||
@Test | ||
def void withClass_ParsesName() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Foo" { | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val classBlock = result.steps.get(0) as ClassBlock | ||
assertEquals(classBlock.name, "Foo") | ||
} | ||
|
||
@Test | ||
def void withClass_shouldNotAllowNestingItself() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Foo" { | ||
With Class "Bar" { | ||
} | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsingFailed(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...edia.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/PropertyParsingTest.xtend
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* generated by Xtext 2.18.0 | ||
*/ | ||
package app.hypermedia.testing.dsl.tests | ||
|
||
import app.hypermedia.testing.dsl.core.ClassBlock | ||
import app.hypermedia.testing.dsl.core.Model | ||
import com.google.inject.Inject | ||
import org.eclipse.xtext.testing.InjectWith | ||
import org.eclipse.xtext.testing.extensions.InjectionExtension | ||
import org.eclipse.xtext.testing.util.ParseHelper | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.^extension.ExtendWith | ||
|
||
import static org.junit.Assert.assertEquals | ||
import app.hypermedia.testing.dsl.core.PropertyBlock | ||
import app.hypermedia.testing.dsl.core.PropertyStatement | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
@ExtendWith(InjectionExtension) | ||
@InjectWith(CoreInjectorProvider) | ||
class PropertyParsingTest { | ||
@Inject | ||
ParseHelper<Model> parseHelper | ||
|
||
@Test | ||
def void withProperty_parsesName() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Person" { | ||
With Property "name" { | ||
} | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val classBlock = result.steps.get(0) as ClassBlock | ||
val propertyBlock = classBlock.children.get(0) as PropertyBlock | ||
assertEquals(propertyBlock.name, "name") | ||
} | ||
|
||
@Test | ||
def void expectProperty_parsesWithoutChildren() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Person" { | ||
Expect Property "name" | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val classBlock = result.steps.get(0) as ClassBlock | ||
val propertyStmt = classBlock.children.get(0) as PropertyStatement | ||
assertEquals(propertyStmt.name, "name") | ||
} | ||
|
||
@Test | ||
def void expectProperty_parsesOptionalValueToAssert() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Person" { | ||
Expect Property "name" "TOMASZ" | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val classBlock = result.steps.get(0) as ClassBlock | ||
val propertyStmt = classBlock.children.get(0) as PropertyStatement | ||
assertEquals(propertyStmt.value, "TOMASZ") | ||
} | ||
|
||
@Test | ||
def void withProperty_parsedSuccessfullyWithChildren() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Book" { | ||
With Property "author" { | ||
Expect Property "name" | ||
} | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val classBlock = result.steps.get(0) as ClassBlock | ||
val propertyBlock = classBlock.children.get(0) as PropertyBlock | ||
assertEquals(propertyBlock.children.length, 1) | ||
assertThat(propertyBlock.children.get(0)).isInstanceOf(PropertyStatement) | ||
} | ||
|
||
@Test | ||
def void withProperty_parsingFailsWhenItHasNoChildren() { | ||
// when | ||
val result = parseHelper.parse(''' | ||
With Class "Book" { | ||
With Property "author" | ||
} | ||
''') | ||
|
||
// then | ||
TestHelpers.assertModelParsingFailed(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters