Skip to content

Commit

Permalink
Make all modules pass WartRemover
Browse files Browse the repository at this point in the history
Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Sep 26, 2023
1 parent e180691 commit 3ece9f3
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ trait BasicValidation {
messages.addStyle(last.loc, s"${last.identify} overloads ${head.identifyWithLoc}")
case _ =>
val tailStr: String = tail.map(d => d.identifyWithLoc).mkString(s",\n ")
messages.addStyle(head.loc, s"${head.identify} overloads:\n $tail")
messages.addStyle(head.loc, s"${head.identify} overloads:\n $tailStr")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ trait DefinitionValidation extends BasicValidation {
MissingWarning,
value.loc
)
} else if shouldCheck then
} else if description.nonEmpty then
description.fold(this) { (desc: Description) =>
check(
desc.nonEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ case class RiddlFileEmitter(filePath: Path) extends TextFileWriter {
case Nil =>
""
case pat :: Nil =>
s"Pattern(${pat.format})\n"
s"Pattern(${pat.format})"
case pat :: tail =>
val lines = (pat :: tail).map(_.format).mkString(spc,s"\n$spc", "\n")
val lines = (pat :: tail).map(_.format).mkString(spc, s"\n$spc", "\n")
s"Pattern(\n$lines)\n"
this.add(line)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class RiddlFileEmitterTest extends AnyWordSpec with Matchers {
"emit patterns" in {
rfe.clear
rfe.emitPattern(patt)
rfe.toString mustBe "Pattern(\"^stuff.*$\") "
rfe.toString mustBe "Pattern(\"^stuff.*$\")"
}

"emit type expressions" in {
Expand All @@ -101,114 +101,7 @@ class RiddlFileEmitterTest extends AnyWordSpec with Matchers {
rfe.clear
rfe.emitTypeExpression(Location(At.empty)).toString mustBe "Location"
rfe.clear
rfe.emitTypeExpression(patt).toString mustBe "Pattern(\"^stuff.*$\") "
rfe.clear
rfe.emitTypeExpression(Abstract(At.empty)).toString mustBe "Abstract"
rfe.clear
rfe.emitTypeExpression(SpecificRange(At.empty, Integer(At.empty), 24, 42)).toString mustBe "Integer{24,42}"
}

"emit to a file" in {
rfe.clear
val path = rfe.emit()
Files.exists(path)
Files.size(path) == 0
}
}
}/** Tests For RiddlFileEmitter */
class RiddlFileEmitterTest extends AnyWordSpec with Matchers {

val path: Path = Path.of("prettify/target/test/rfe.out")
val rfe = RiddlFileEmitter(path)

"RiddlFileEmitter" should {
"add literal strings" in {
val string = LiteralString(At.empty, "string")
val strings = Seq(string)
val twoStrings = Seq(string, string)
rfe.clear
rfe.add(strings)
rfe.toString mustBe " \"string\" "
rfe.clear
rfe.add(twoStrings)
rfe.toString mustBe "\n\"string\"\n\"string\"\n"
}
"add string" in {
rfe.clear
rfe.add("string")
rfe.toString mustBe "string"
}
"add option" in {
rfe.clear
rfe.add(Some("string"))(identity)
rfe.toString mustBe "string"
rfe.clear
rfe.add(Option.empty[String])(identity)
rfe.toString mustBe ""
}
"add indent" in {
rfe.clear
rfe.addIndent()
rfe.toString mustBe ""
rfe.indent
rfe.addIndent()
rfe.toString mustBe " "
}
"outdent catches unmatched" in {
rfe.clear
intercept[IllegalArgumentException] { rfe.outdent }
}
"starts a definition with/out a brace" in {
rfe.clear
val defn = Domain(At.empty, Identifier(At.empty, "domain"))
rfe.openDef(defn, withBrace = true)
defn.isEmpty mustBe true
rfe.toString mustBe "domain domain is { ??? }"
rfe.clear
rfe.openDef(defn, withBrace = false)
rfe.toString mustBe "domain domain is "
}
"emits Strngs" in {
rfe.clear
val s1 = Strng(At.empty, Some(3L), Some(6L))
val s2 = Strng(At.empty, Some(3L), None)
val s3 = Strng(At.empty, None, Some(6L))
val s4 = Strng(At.empty)
rfe.emitString(s1).toString mustBe "String(3,6)"
rfe.clear
rfe.emitString(s2).toString mustBe "String(3)"
rfe.clear
rfe.emitString(s3).toString mustBe "String(,6)"
rfe.clear
rfe.emitString(s4).toString mustBe "String"
}
"emits descriptions" in {
rfe.clear
val desc = BlockDescription(At.empty, Seq(LiteralString(At.empty, "foo")))
rfe.emitDescription(Some(desc))
rfe.toString mustBe " described as {\n |foo\n}\n"
}

val patt = Pattern(At.empty, Seq(LiteralString(At.empty, "^stuff.*$")))

"emit patterns" in {
rfe.clear
rfe.emitPattern(patt)
rfe.toString mustBe "Pattern(\"^stuff.*$\") "
}

"emit type expressions" in {
rfe.clear
rfe.emitTypeExpression(Decimal(At.empty, 8, 3)).toString mustBe
"Decimal(8,3)"
rfe.clear
rfe.emitTypeExpression(Real(At.empty)).toString mustBe "Real"
rfe.clear
rfe.emitTypeExpression(DateTime(At.empty)).toString mustBe "DateTime"
rfe.clear
rfe.emitTypeExpression(Location(At.empty)).toString mustBe "Location"
rfe.clear
rfe.emitTypeExpression(patt).toString mustBe "Pattern(\"^stuff.*$\") "
rfe.emitTypeExpression(patt).toString mustBe "Pattern(\"^stuff.*$\")"
rfe.clear
rfe.emitTypeExpression(Abstract(At.empty)).toString mustBe "Abstract"
rfe.clear
Expand Down
2 changes: 1 addition & 1 deletion testkit/src/test/input/check/everything/everything.check
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Style: testkit/src/test/input/check/everything/everything.riddl(65:7):
^
Missing: testkit/src/test/input/check/everything/everything.riddl(67:7):
Command 'ACommand' should have a description:
command ACommand is {}
command ACommand is { ??? }
^
Missing: testkit/src/test/input/check/everything/everything.riddl(3:1):
Vital definitions should have an author reference:
Expand Down
2 changes: 1 addition & 1 deletion testkit/src/test/input/check/everything/everything.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ domain Everything is {

type somethingDate is Date

command ACommand is {}
command ACommand is { ??? }

state someState of type Everything.StateType is { ??? }

Expand Down
2 changes: 1 addition & 1 deletion testkit/src/test/input/check/t0001/main.riddl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
domain foo is {
???
} described as { "" }
} described as ""
8 changes: 4 additions & 4 deletions testkit/src/test/input/dokn.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,20 @@ domain dokn is {
type AddDeliveryLocation is command {
geohash: Location, label: String
}
type DeliveryLocationAdded is event { }
type DeliveryLocationAdded is event { ??? }

type ChangeLocationName is command { newName: String }
type LocationNameChanged is event { newName: String }

type ReportTicketReceived is command {}
type TicketReportedAtLocation is event {}
type ReportTicketReceived is command { ??? }
type TicketReportedAtLocation is event { ??? }

type ModifyNotesAtLocation is command { cid: CompanyId, note: String }
type NotesForLocationModified is event { note: String }

type LocationAddressReceived is event { newAddress: dokn.Address }

type getLocationDetails is query {}
type getLocationDetails is query { ??? }
type LocationDetails is result { ??? }

type getLocationNotes is query { cid: CompanyId }
Expand Down
4 changes: 2 additions & 2 deletions testkit/src/test/input/everything.riddl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,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 {}
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 @@ -73,7 +73,7 @@ domain Everything is {

type somethingDate is Date

event Inebriated is {}
event Inebriated is { ??? }

record fields is { field: SomeType }
state someState of Something.fields is {
Expand Down
4 changes: 2 additions & 2 deletions testkit/src/test/input/issues/406.riddl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
domain Example is {
context ExampleContext is {
command ToBar is {}
command ToFoo is {}
command ToBar is { ??? }
command ToFoo is { ??? }
type Foo is {
bar: String
}
Expand Down

0 comments on commit 3ece9f3

Please sign in to comment.