Skip to content

Commit

Permalink
Make all test cases work again
Browse files Browse the repository at this point in the history
* Move DokN test case to testkit, out of examples
* Fix precedence of operators so arbitrary ones come last
* Recognize known operators "pow" and "now"
* Avoid checking for assignment compatibility in certain cases where
  it isn't possible
* Make sure hierarchy is right for OnClauses
* Fix path identifiers in test case riddl source
* Clean up test case output
  • Loading branch information
reidspencer committed Aug 21, 2022
1 parent ca411f7 commit 8ade103
Show file tree
Hide file tree
Showing 16 changed files with 121 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import java.nio.file.Files
class CheckExamplesSpec extends HugoTranslateExamplesBase {

val output = "examples/target/translator/"
val roots = Map("Reactive BBQ" -> "ReactiveBBQ/ReactiveBBQ.riddl"
// FIXME: , "DokN" -> "dokn/dokn.riddl"
)
val roots = Map("Reactive BBQ" -> "ReactiveBBQ/ReactiveBBQ.riddl")

"Examples" should {
for { (name, path) <- roots } {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.reactific.riddl.translator.hugo
class HugoTranslatorTest extends HugoTranslateExamplesBase {

val output: String = "hugo-translator/target/translator/"
val roots = Map("Reactive BBQ" -> s"ReactiveBBQ/ReactiveBBQ.riddl"
// FIXME: , "DokN" -> s"dokn/dokn.riddl"
)
val roots = Map("Reactive BBQ" -> s"ReactiveBBQ/ReactiveBBQ.riddl")

"HugoTranslator" should {
for { (name, fileName) <- roots } {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ object Validation {
Option[Definition]
) => ValidationState


private val nullSingleMatchingValidationFunction
: SingleMatchValidationFunction =
(state, _, _, _, _, _) => { state }

private val defaultSingleMatchValidationFunction
: SingleMatchValidationFunction =
(state, foundClass, id, defClass, _, _) => {
Expand Down Expand Up @@ -381,11 +386,11 @@ object Validation {
): ValidationState = {
checkPathRef[T](reference.id, defn, kind)() }

def checkMessageRef(ref: MessageRef, defn: Definition, kind: MessageKind): ValidationState = {
def checkMessageRef(ref: MessageRef, topDef: Definition, kind: MessageKind): ValidationState = {
if (ref.isEmpty) {
addError(ref.id.loc, s"${ref.identify} is empty")
} else {
checkPathRef[Type](ref.id, defn, Some(kind.kind)) { (state, _, _, _, defn, _) =>
checkPathRef[Type](ref.id, topDef, Some(kind.kind)) { (state, _, _, _, defn, _) =>
defn match {
case Type(_, _, typ, _, _) => typ match {
case MessageType(_, mk, _) =>
Expand Down Expand Up @@ -746,7 +751,8 @@ object Validation {
): ValidationState =
expression match {
case ValueExpression(_, path) =>
checkPathRef[Field](path,defn)()
// FIXME: Can we validate based on type? What if a Type is returned?
checkPathRef[Field](path,defn)(nullSingleMatchingValidationFunction)
case GroupExpression(_, expressions) =>
checkSequence(expressions) {
(st, expr) => st.checkExpression(expr, defn)
Expand Down Expand Up @@ -996,7 +1002,9 @@ object Validation {
state.checkDefinition(container, function)
case onClause: OnClause =>
state.checkIf(onClause.msg.nonEmpty) { st =>
state.captureHierarchy(onClause +: parents)
st.checkMessageRef(onClause.msg, container, onClause.msg.messageKind)
state.captureHierarchy(parents)
}
case st: State =>
state.checkDefinition(parents.head, st)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,8 @@ trait ExpressionParser extends CommonParser with ReferenceParser {

def terminalExpression[u: P]: P[Expression] = {
P(terminalCondition | literalDecimal | literalInteger |
aggregateConstruction | entityIdValue |
valueExpression | undefinedExpression |
arbitraryExpression | arbitraryOperator
entityIdValue | valueExpression | undefinedExpression |
arbitraryExpression
)
}

Expand All @@ -176,7 +175,7 @@ trait ExpressionParser extends CommonParser with ReferenceParser {
}

def knownOperatorName[u:P]: P[String] = {
StringIn("senderOf").!
StringIn("pow", "now").!
}

def arithmeticOperator[u: P]: P[ArithmeticOperator] = {
Expand Down Expand Up @@ -207,8 +206,9 @@ trait ExpressionParser extends CommonParser with ReferenceParser {

def expression[u: P]: P[Expression] = {
P(
terminalExpression | ternaryExpression | arithmeticOperator |
functionCallExpression | groupExpression
terminalExpression | aggregateConstruction | ternaryExpression |
groupExpression | arithmeticOperator |
arbitraryOperator | functionCallExpression
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class PathResolutionSpec extends AnyWordSpec with Matchers{
| requires: { t: ^^^.Top }
| returns: { a: String }
| example impl {
| then return @^t.m.b.a
| then return @^^foo.t.m.b.a
| }
| }
| }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,10 @@ class ParsingTest extends ParsingTestBase {
val rpi = RiddlParserInput(file)
TopLevelParser.parse(rpi) match {
case Left(errors) =>
val msg = errors.map(_.format).mkString
val msg = errors.map(_.format).mkString("\n")
fail(msg)
case Right(rc) => rc
case Right(rc) =>
rc
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ abstract class TranslatingTestBase[OPTS <: TranslatingOptions]
val directory = "examples/src/riddl/"
val output = "examples/target/translator/"
val roots: Map[String, String] = Map(
"Reactive BBQ" -> "ReactiveBBQ/ReactiveBBQ.riddl",
"DokN" -> "dokn/dokn.riddl"
"Reactive BBQ" -> "ReactiveBBQ/ReactiveBBQ.riddl"
)
val logger: Logger = StringLogger()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,15 @@ abstract class ValidatingTest extends ParsingTest {
}
}

private def defaultFail(msgs: Messages): Assertion = {
fail(msgs.map(_.format).mkString("\n"))
}
def validateFile(
label: String,
fileName: String,
options: CommonOptions = CommonOptions()
)(validation: (RootContainer, Messages) => Assertion
= (_,msgs) => defaultFail(msgs)
): Assertion = {
val directory = "testkit/src/test/input/"
val file = new File(directory + fileName)
Expand Down
132 changes: 64 additions & 68 deletions testkit/src/test/input/check/everything/everything.check
Original file line number Diff line number Diff line change
@@ -1,81 +1,77 @@
Missing: everything.riddl(3:1): Domain 'Everything' should have a description
Missing: everything.riddl(50:5): Type 'optional' should have a description
Style: everything.riddl(27:5): Type 'ident' should start with a capital letter
Missing: everything.riddl(42:7): Field 'key' should have a description
Missing: everything.riddl(44:7): Field 'time' should have a description
Style: everything.riddl(29:5): Type 'tim' should start with a capital letter
Missing: everything.riddl(64:7): State 'someState' should have a description
Missing: everything.riddl(6:3): Type 'DoAThing' should have a description
Missing: everything.riddl(30:5): Type 'stamp' should have a description
Error: everything.riddl(78:29): Path 'Inebriated' was not resolved, in Example 'only', but should refer to an event
Missing: everything.riddl(11:3): Plant 'APlant' should have a description
Missing: everything.riddl(12:24): Outlet 'Commands' should have a description
Missing: everything.riddl(12:24): entity reference in Outlet 'Commands' should not be empty
Missing: everything.riddl(13:20): Inlet 'Commands' should have a description
Missing: everything.riddl(13:20): entity reference in Inlet 'Commands' should not be empty
Missing: everything.riddl(15:5): Joint 'input' should have a description
Missing: everything.riddl(16:5): Joint 'output' should have a description
Missing: everything.riddl(20:3): Context 'full' should have a description
Missing: everything.riddl(59:5): Entity 'Something' should have a description
Missing: everything.riddl(43:7): Field 'id' should have a description
Style: everything.riddl(28:5): Type 'dat' should start with a capital letter
Style: everything.riddl(34:25): Field identifier 'a' is too short. The minimum length is 3
Missing: everything.riddl(62:7): Type 'somethingDate' should have a description
Missing: everything.riddl(34:5): Type 'PeachType' should have a description
Style: everything.riddl(26:5): Type 'boo' should start with a capital letter
Style: everything.riddl(48:5): Type 'oneOrMore' should start with a capital letter
Missing: everything.riddl(24:5): Type 'str' should have a description
Style: everything.riddl(30:5): Type 'stamp' should start with a capital letter
Missing: everything.riddl(25:5): Type 'num' should have a description
Style: everything.riddl(38:5): Type 'alt' should start with a capital letter
Missing: everything.riddl(34:25): Field 'a' should have a description
Missing: everything.riddl(26:5): Type 'boo' should have a description
Missing: everything.riddl(27:5): Type 'ident' should have a description
Missing: everything.riddl(28:5): Type 'dat' should have a description
Missing: everything.riddl(29:5): Type 'tim' should have a description
Missing: everything.riddl(30:5): Type 'stamp' should have a description
Missing: everything.riddl(31:5): Type 'url' should have a description
Missing: everything.riddl(82:5): Entity 'SomeOtherThing' should have a description
Missing: everything.riddl(34:25): Field 'a' should have a description
Missing: everything.riddl(34:5): Type 'PeachType' should have a description
Missing: everything.riddl(35:27): Enumerator 'Apple' should have a description
Missing: everything.riddl(35:33): Enumerator 'Pear' should have a description
Missing: everything.riddl(35:38): Enumerator 'Peach' should have a description
Missing: everything.riddl(35:48): Enumerator 'Persimmon' should have a description
Missing: everything.riddl(35:5): Type 'enum' should have a description
Missing: everything.riddl(38:5): Type 'alt' should have a description
Style: everything.riddl(24:5): Type 'str' should start with a capital letter
Missing: everything.riddl(66:7): Function 'whenUnderTheInfluence' should have a description
Style: everything.riddl(35:5): Type 'enum' should start with a capital letter
Style: everything.riddl(62:7): Type 'somethingDate' should start with a capital letter
Missing: everything.riddl(28:5): Type 'dat' should have a description
Style: everything.riddl(25:5): Type 'num' should start with a capital letter
Missing: everything.riddl(3:1): Domain 'Everything' should have a description
Missing: everything.riddl(41:5): Type 'agg' should have a description
Style: everything.riddl(31:5): Type 'url' should start with a capital letter
Missing: everything.riddl(5:3): Type 'SomeType' should have a description
Missing: everything.riddl(64:28): Field 'someField' should have a description
Missing: everything.riddl(42:7): Field 'key' should have a description
Missing: everything.riddl(43:7): Field 'id' should have a description
Missing: everything.riddl(44:7): Field 'time' should have a description
Missing: everything.riddl(48:5): Type 'oneOrMore' should have a description
Missing: everything.riddl(49:5): Type 'zeroOrMore' should have a description
Style: everything.riddl(50:5): Type 'optional' should start with a capital letter
Style: everything.riddl(41:5): Type 'agg' should start with a capital letter
Missing: everything.riddl(50:5): Type 'optional' should have a description
Missing: everything.riddl(59:5): Entity 'Something' should have a description
Missing: everything.riddl(5:3): Type 'SomeType' should have a description
Missing: everything.riddl(62:7): Type 'somethingDate' should have a description
Missing: everything.riddl(64:7): Type 'ACommand' should have a description
Missing: everything.riddl(66:28): Field 'someField' should have a description
Missing: everything.riddl(66:7): State 'someState' should have a description
Missing: everything.riddl(68:7): Function 'whenUnderTheInfluence' should have a description
Missing: everything.riddl(69:20): Field 'n' should have a description
Missing: everything.riddl(70:19): Field 'b' should have a description
Missing: everything.riddl(6:3): Type 'DoAThing' should have a description
Missing: everything.riddl(6:30): Field 'thingField' should have a description
Missing: everything.riddl(73:15): Handler 'foo' should have a description
Missing: everything.riddl(74:12): On Clause 'On command ACommand' should have a description
Missing: everything.riddl(75:11): Example 'only' should have a description
Missing: everything.riddl(84:5): Entity 'SomeOtherThing' should have a description
Missing: everything.riddl(86:34): Field 'then' should have a description
Missing: everything.riddl(86:7): State 'otherThingState' should have a description
Missing: everything.riddl(87:15): Handler 'fee' should have a description
Missing: everything.riddl(85:34): Field 'when' should have a description
Missing: everything.riddl(88:12): On Clause 'On event ItHappened' should have a description
Missing: everything.riddl(85:7): Type 'ItHappened' should have a description
Missing: everything.riddl(89:11): Example 'only' should have a description
Style: everything.riddl(13:20): Inlet 'Commands' overloads Outlet 'Commands' at everything.riddl(12:24)
Style: everything.riddl(24:5): Type 'str' should start with a capital letter
Style: everything.riddl(25:5): Type 'num' should start with a capital letter
Style: everything.riddl(26:5): Type 'boo' should start with a capital letter
Style: everything.riddl(27:5): Type 'ident' should start with a capital letter
Style: everything.riddl(28:5): Type 'dat' should start with a capital letter
Style: everything.riddl(29:5): Type 'tim' should start with a capital letter
Style: everything.riddl(30:5): Type 'stamp' should start with a capital letter
Style: everything.riddl(31:5): Type 'url' should start with a capital letter
Style: everything.riddl(34:25): Field identifier 'a' is too short. The minimum length is 3
Style: everything.riddl(35:5): Type 'enum' should start with a capital letter
Style: everything.riddl(38:5): Type 'alt' should start with a capital letter
Style: everything.riddl(41:5): Type 'agg' should start with a capital letter
Style: everything.riddl(43:7): Field identifier 'id' is too short. The minimum length is 3
Missing: everything.riddl(35:5): Type 'enum' should have a description
Missing: everything.riddl(27:5): Type 'ident' should have a description
Missing: everything.riddl(29:5): Type 'tim' should have a description
Style: everything.riddl(48:5): Type 'oneOrMore' should start with a capital letter
Style: everything.riddl(49:5): Type 'zeroOrMore' should start with a capital letter
Missing: everything.riddl(84:7): State 'otherThingState' should have a description
Missing: everything.riddl(83:7): Type 'ItHappened' should have a description
Missing: everything.riddl(35:48): Enumerator 'Persimmon' should have a description
Missing: everything.riddl(35:33): Enumerator 'Pear' should have a description
Missing: everything.riddl(12:24): Outlet 'Commands' should have a description
Missing: everything.riddl(15:5): Joint 'input' should have a description
Missing: everything.riddl(16:5): Joint 'output' should have a description
Missing: everything.riddl(35:27): Enumerator 'Apple' should have a description
Missing: everything.riddl(35:38): Enumerator 'Peach' should have a description
Missing: everything.riddl(13:20): Inlet 'Commands' should have a description
Error: everything.riddl(72:20): Reference[Type] 'Something'(72:12) was expected to be a command type but is an Entity instead
Style: everything.riddl(13:20): Inlet 'Commands' overloads Outlet 'Commands' at everything.riddl(12:24)
Error: everything.riddl(76:29): Path 'Inebriated' was not resolved, in Example 'only', but should refer to an event
Missing: everything.riddl(83:34): Field 'when' should have a description
Missing: everything.riddl(84:34): Field 'then' should have a description
Missing: everything.riddl(73:11): Example 'only' should have a description
Missing: everything.riddl(87:11): Example 'only' should have a description
Style: everything.riddl(87:11): Example 'only' overloads Example 'only' at everything.riddl(73:11)
Style: everything.riddl(67:20): Field identifier 'n' is too short. The minimum length is 3
Style: everything.riddl(68:19): Field identifier 'b' is too short. The minimum length is 3
Missing: everything.riddl(68:19): Field 'b' should have a description
Missing: everything.riddl(67:20): Field 'n' should have a description
Missing: everything.riddl(11:3): Plant 'APlant' should have a description
Missing: everything.riddl(71:15): Handler 'foo' should have a description
Missing: everything.riddl(86:12): On Clause 'On event ItHappened' should have a description
Missing: everything.riddl(85:15): Handler 'fee' should have a description
Missing: everything.riddl(72:12): On Clause 'On command Something' should have a description
Missing: everything.riddl(13:20): entity reference in Inlet 'Commands' should not be empty
Missing: everything.riddl(12:24): entity reference in Outlet 'Commands' should not be empty
Error: everything.riddl(88:22): Setting a value requires assignment compatibility, but field:
SomeOtherThing.otherThingState.then (<not found>)
is not assignment compatible with expression:
@ItHappened.when (<not found>)
Style: everything.riddl(50:5): Type 'optional' should start with a capital letter
Style: everything.riddl(62:7): Type 'somethingDate' should start with a capital letter
Style: everything.riddl(69:20): Field identifier 'n' is too short. The minimum length is 3
Style: everything.riddl(70:19): Field identifier 'b' is too short. The minimum length is 3
Style: everything.riddl(89:11): Example 'only' overloads Example 'only' at everything.riddl(75:11)

4 changes: 3 additions & 1 deletion testkit/src/test/input/check/everything/everything.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ domain Everything is {

type somethingDate is Date

command ACommand is {}

state someState is { someField: SomeType }

function whenUnderTheInfluence is {
Expand All @@ -69,7 +71,7 @@ domain Everything is {
}

handler foo is {
on command Something {
on command ACommand {
example only {
given "Something arrives"
when misc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ domain dokn is {
type ModifyNotesAtLocation is command { cid: CompanyId, note: String }
type NotesForLocationModified is event { note: String }

type LocationAddressReceived is event { newAddress: Address }
type LocationAddressReceived is event { newAddress: dokn.Address }

type getLocationDetails is query {}
type LocationDetails is result { ??? }
Expand Down Expand Up @@ -160,7 +160,7 @@ domain dokn is {
)
}
on event LocationAddressReceived {
then set ^^LocationBase.address to @^^^^LocationAddressReceived.newAddress
then set LocationBase.address to @^^LocationAddressReceived.newAddress
}
on query getLocationDetails { then tell result LocationDetails() to Driver }
on query getLocationNotes { then tell result LocationNotes(notes=empty()) to Driver }
Expand Down
8 changes: 5 additions & 3 deletions testkit/src/test/input/everything.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ domain Everything is {
type str is String // Define str as a String
type num is Number // Define num as a Number
type boo is Boolean // Define boo as a Boolean
type ident is Id(someDef) // Define ident as an Id
type ident is Id(Something) // Define ident as an Id
type dat is Date // Define dat as a Date
type tim is Time // Define tim as a Time
type stamp is TimeStamp // Define stamp as a TimeStamp
Expand Down Expand Up @@ -70,7 +70,7 @@ domain Everything is {
// Commands, Events, Queries and Results are defined in terms of some
// type, previously defined. Commands yield events. Queries yield results.


command ACommand is {}

// Entities are the main objects that contexts define. They can be
// transient (memory only) or aggregate (they consume commands and queries)
Expand All @@ -79,6 +79,8 @@ domain Everything is {

type somethingDate is Date

event Inebriated is {}

state someState is { field: SomeType }

function whenUnderTheInfluence is {
Expand All @@ -87,7 +89,7 @@ domain Everything is {
}

handler foo is {
on command Something {
on command ACommand {
example only {
given "Something arrives "
when misc()
Expand Down
Loading

0 comments on commit 8ade103

Please sign in to comment.