Skip to content

Commit

Permalink
Remove pending items from ContextValidationTest
Browse files Browse the repository at this point in the history
* Also fix contents bug in projection that was avoiding validations

Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Nov 13, 2022
1 parent 762856e commit 8d16b53
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ object RepeatCommand {
}
}

class RepeatCommand extends CommandPlugin[RepeatCommand.Options](RepeatCommand.cmdName) {
class RepeatCommand
extends CommandPlugin[RepeatCommand.Options](RepeatCommand.cmdName) {
import RepeatCommand.Options

/** Provide an scopt OParser for the commands options type, OPT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,8 +834,7 @@ case class MarkdownWriter(
val maybeActor = state.resolvePathIdentifier[Actor](actorPid, stack)
h2("User Story")
maybeActor match {
case None =>
p(s"Unresolvable Actor id: ${actorPid.format}")
case None => p(s"Unresolvable Actor id: ${actorPid.format}")
case Some(actor) =>
val name = actor.id.value
val role = actor.is_a.s
Expand Down Expand Up @@ -915,7 +914,9 @@ case class MarkdownWriter(
): this.type = {
containerHead(projection, "Projection")
emitDefDoc(projection, parents)
emitFields(projection.aggregation.fields)
if (projection.aggregation.nonEmpty) {
emitFields(projection.aggregation.get.fields)
}
listOf("Handlers", projection.handlers)
emitUsage(projection)
emitTerms(projection.terms)
Expand Down
16 changes: 9 additions & 7 deletions language/src/main/scala/com/reactific/riddl/language/AST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1235,27 +1235,29 @@ object AST extends ast.Expressions with ast.Options with parsing.Terminals {
case class Projection(
loc: Location,
id: Identifier,
aggregation: Aggregation,
handlers: Seq[Handler] = Seq.empty[Handler],
invariants: Seq[Invariant] = Seq.empty[Invariant],
authors: Seq[AuthorRef] = Seq.empty[AuthorRef],
options: Seq[ProjectionOption] = Seq.empty[ProjectionOption],
includes: Seq[Include[ProjectionDefinition]] = Seq
.empty[Include[ProjectionDefinition]],
options: Seq[ProjectionOption] = Seq.empty[ProjectionOption],
aggregation: Option[Aggregation] = None,
handlers: Seq[Handler] = Seq.empty[Handler],
invariants: Seq[Invariant] = Seq.empty[Invariant],
terms: Seq[Term] = Seq.empty[Term],
brief: Option[LiteralString] = Option.empty[LiteralString],
description: Option[Description] = None)
extends VitalDefinition[ProjectionOption, ProjectionDefinition]
with ContextDefinition {
override lazy val contents: Seq[ProjectionDefinition] = {
super.contents ++ aggregation.fields ++ terms
super.contents ++ aggregation.map(_.fields).getOrElse(Seq.empty[Field]) ++
handlers ++ invariants ++ terms
}
final val kind: String = "Projection"

override def maturity: Int = {
var score = super.maturity
if (aggregation.fields.nonEmpty) score +=
Math.max(aggregation.fields.count(_.nonEmpty), maxMaturity)
val fields: Seq[Field] = aggregation.map(_.fields).getOrElse(Seq.empty)
if (fields.nonEmpty) score +=
Math.max(fields.count(_.nonEmpty), maxMaturity)
Math.max(score, maxMaturity)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,15 @@ object Validation {
)
}

def checkAggregation(
aggregation: Option[Aggregation]
): ValidationState = {
aggregation match {
case None => this
case Some(aggregation) => checkAggregation(aggregation)
}
}

def checkAggregation(
agg: Aggregation
): ValidationState = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ trait TypeExpression extends AbstractDefinitions {
extends AggregateTypeExpression {}

object Aggregation {
val empty: Aggregation = { Aggregation(Location.empty) }
// val empty: Aggregation = { Aggregation(Location.empty) }
def empty(loc: Location = Location.empty): Aggregation = {
Aggregation(loc)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
package com.reactific.riddl.language.parsing

import com.reactific.riddl.language.AST.*
import com.reactific.riddl.language.ast.Location
import fastparse.*
import fastparse.ScalaWhitespace.*

Expand All @@ -30,15 +29,13 @@ trait ProjectionParser extends TypeParser with HandlerParser {
P(term | projectionInclude | handler | invariant).rep(0)
}

def projectionBody[
u: P
]: P[(Seq[ProjectionOption], Aggregation, Seq[ProjectionDefinition])] = {
type ProjectionBody =
(Seq[ProjectionOption], Option[Aggregation], Seq[ProjectionDefinition])
def projectionBody[u: P]: P[ProjectionBody] = {
P(
undefined((
Seq.empty[ProjectionOption],
Aggregation(Location.empty, Seq.empty[Field]),
Seq.empty[ProjectionDefinition]
)) | (projectionOptions ~ aggregation ~ projectionDefinitions)
undefined(
(Seq.empty[ProjectionOption], None, Seq.empty[ProjectionDefinition])
) | (projectionOptions ~ aggregation.? ~ projectionDefinitions)
)
}

Expand Down Expand Up @@ -74,12 +71,12 @@ trait ProjectionParser extends TypeParser with HandlerParser {
Projection(
loc,
id,
authors,
options,
includes,
aggregation,
handlers,
invariants,
authors,
includes,
options,
terms,
briefly,
description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,105 @@ class ContextValidationTest extends ValidatingTest {
))
}
}
"allow functions" in { pending } // TODO: write this case
"allow entities" in { pending } // TODO: write this case
"allow terms" in { pending } // TODO: write this case
"allow functions" in {
val input = """function bar is {
| requires { i: Integer }
| returns { o: Integer }
|}
|""".stripMargin
parseAndValidateContext(input) {
case (context: Context, rpi, msgs: Messages) =>
val errors = msgs.justErrors
info(errors.format)
errors must be(empty)
context.functions.size mustBe (1)
val expected = Function(
(2, 2, rpi),
Identifier((2, 11, rpi), "bar"),
input = Some(Aggregation(
(3, 12, rpi),
Seq(Field(
(3, 14, rpi),
Identifier((3, 14, rpi), "i"),
Integer((3, 17, rpi))
))
)),
output = Some(Aggregation(
(4, 11, rpi),
Seq(Field(
(4, 13, rpi),
Identifier((4, 13, rpi), "o"),
Integer((4, 16, rpi))
))
))
)
context.functions.head mustBe expected
}
}
"allow entities" in {
val input = """entity bar is { ??? }
|""".stripMargin
parseAndValidateContext(input) {
case (context: Context, rpi, msgs: Messages) =>
val errors = msgs.justErrors
info(errors.format)
errors must be(empty)
val expected = Entity((2, 2, rpi), Identifier((2, 9, rpi), "bar"))
context.entities.size mustBe (1)
context.entities.head mustBe expected
}

}
"allow terms" in {
val input = """term bar is briefly "imaginary line in court room"
|""".stripMargin
parseAndValidateContext(input) {
case (context: Context, rpi, msgs: Messages) =>
val errors = msgs.justErrors
info(errors.format)
errors must be(empty)
val expected = Term(
(2, 2, rpi),
Identifier((2, 7, rpi), "bar"),
Some(LiteralString((2, 22, rpi), "imaginary line in court room"))
)
context.terms.size mustBe (1)
context.terms.head mustBe expected
}
}
"allow processors" in {
val input = """source foo is { ??? }
|""".stripMargin
parseAndValidateContext(input) {
case (context: Context, rpi, msgs: Messages) =>
val errors = msgs.justErrors
info(errors.format)
errors must be(empty)
val expected = Processor(
(2, 2, rpi),
Identifier((2, 9, rpi), "foo"),
Source((2, 2, rpi))
)
context.processors.size mustBe (1)
context.processors.head mustBe expected
}
}
"allow projections" in {
val input = """projection foo is { ??? }
|""".stripMargin
parseAndValidateContext(input) {
case (context: Context, rpi, msgs: Messages) =>
val errors = msgs.justErrors
info(errors.format)
errors must be(empty)
val expected = Projection(
(2, 2, rpi),
Identifier((2, 13, rpi), "foo")
)
context.projections.size mustBe (1)
context.projections.head mustBe expected
}
}
"allow includes" in { pending } // TODO: write this case
"allow processors" in { pending } // TODO: write this case
"allow projections" in { pending } // TODO: write this case
}
}

0 comments on commit 8d16b53

Please sign in to comment.