Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mie6 committed Jan 12, 2025
1 parent 8f51551 commit 034d8bd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package parsley.debug
import scala.annotation.experimental

// scalastyle:off underscore.import
import org.typelevel.scalaccompat.annotation.unused
import parsley.Parsley, Parsley._
import parsley.ParsleyTest
import parsley.character._
Expand Down Expand Up @@ -64,7 +63,7 @@ class DebuggerUsageSpec extends ParsleyTest {
val parser = fresh { hit1 = true }.impure *> fresh { hit2 = true }.impure <* fresh { hit3 = true }
val debugged = attachDebugger(parser)

val _ = debugged._2.parse(""): @unused
val _ = debugged._2.parse("")

assert(hit1 && hit2 && hit3)
}
Expand All @@ -80,7 +79,7 @@ class DebuggerUsageSpec extends ParsleyTest {
val parser = many(string("abc"))
val (treeF, debugged) = attachDebugger(parser)

val _ = debugged.parse("abcabc"): @unused
val _ = debugged.parse("abcabc")
val tree = treeF()

tree.parseResults match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/
package parsley.debug

import org.typelevel.scalaccompat.annotation.unused
import parsley.ParsleyTest

//noinspection ConvertExpressionToSAM
Expand Down Expand Up @@ -37,14 +36,14 @@ class ReuseSpec extends ParsleyTest {
}

info("it should not throw when running a reusable frontend multiple times")
reusable.render("bar", tree): @unused
reusable.render("bar", tree): @unused
reusable.render("bar", tree)
reusable.render("bar", tree)

// The first run should not throw.
singleUse.render("bar", tree): @unused
singleUse.render("bar", tree)
info("it should throw when running a single-use frontend multiple times")
try {
singleUse.render("bar", tree): @unused
singleUse.render("bar", tree)

fail("single-use frontend did not throw an exception after running multiple times")
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RenameSpec extends ParsleyTest {
}

it should "rename a parser it is aware of" in {
val exampleParser: LazyParsley[_] = new DummyParser
val exampleParser: LazyParsley[?] = new DummyParser
Renamer.addNames(Map((exampleParser, "exampleParser")))

Renamer.nameOf(None, exampleParser) shouldBe "exampleParser"
Expand All @@ -45,7 +45,7 @@ class RenameSpec extends ParsleyTest {
}

it should "override a known name if a parser is named." in {
val exampleParser: LazyParsley[_] = new DummyParser
val exampleParser: LazyParsley[?] = new DummyParser
Renamer.addNames(Map((exampleParser, "exampleParser")))

Renamer.nameOf(Some("knownName"), exampleParser) shouldBe "knownName"
Expand Down Expand Up @@ -78,14 +78,14 @@ object Utils {
// These are dummy parsers used for the above tests.
// We don't actually care that they don't implement anything.
private class DummyParser extends LazyParsley[Any] {
override protected def findLetsAux[M[_, +_] : ContOps, R](seen: Set[LazyParsley[_]])(implicit state: LetFinderState): M[R, Unit] = Utils.crash()
override protected def findLetsAux[M[_, +_] : ContOps, R](seen: Set[LazyParsley[?]])(implicit state: LetFinderState): M[R, Unit] = Utils.crash()
override protected def preprocess[M[_, +_] : ContOps, R, A_ >: Any](implicit lets: LetMap): M[R, StrictParsley[A_]] = Utils.crash()
override def visit[T, U[+_]](visitor: LazyParsleyIVisitor[T, U], context: T): U[Any] = visitor.visitUnknown(this, context)
private [parsley] var debugName = "dummyParser"
}

private class <**> extends LazyParsley[Any] {
override protected def findLetsAux[M[_, +_] : ContOps, R](seen: Set[LazyParsley[_]])(implicit state: LetFinderState): M[R, Unit] = Utils.crash()
override protected def findLetsAux[M[_, +_] : ContOps, R](seen: Set[LazyParsley[?]])(implicit state: LetFinderState): M[R, Unit] = Utils.crash()
override protected def preprocess[M[_, +_] : ContOps, R, A_ >: Any](implicit lets: LetMap): M[R, StrictParsley[A_]] = Utils.crash()
override def visit[T, U[+_]](visitor: LazyParsleyIVisitor[T, U], context: T): U[Any] = visitor.visitUnknown(this, context)
private [parsley] var debugName = "<**>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package parsley.internal.deepembedding.frontend

import scala.util.Random

import org.typelevel.scalaccompat.annotation.unused
import parsley.Parsley
import parsley.ParsleyTest
import parsley.combinator.ifS
Expand Down Expand Up @@ -62,38 +61,38 @@ class TotalAttachmentSpec extends ParsleyTest {

override def visitUnary[A, B](self: Unary[A, B], parentIsTag: Boolean)(p: LazyParsley[A]): ConstUnit[B] =
if (parentIsTag == self.isOpaque) {
visitUnknown(p, parentIsTag = false): @unused
visitUnknown(p, parentIsTag = false)
CUnit
} else failure()

override def visitBinary[A, B, C](self: Binary[A, B, C], parentIsTag: Boolean)(l: LazyParsley[A], r: => LazyParsley[B]): ConstUnit[C] =
if (parentIsTag == self.isOpaque) {
visitUnknown(l, parentIsTag = false): @unused
visitUnknown(r, parentIsTag = false): @unused
visitUnknown(l, parentIsTag = false)
visitUnknown(r, parentIsTag = false)
CUnit
} else failure()

override def visitTernary[A, B, C, D](self: Ternary[A, B, C, D], parentIsTag: Boolean)(f: LazyParsley[A],
s: => LazyParsley[B],
t: => LazyParsley[C]): ConstUnit[D] =
if (parentIsTag == self.isOpaque) {
visitUnknown(f, parentIsTag = false): @unused
visitUnknown(s, parentIsTag = false): @unused
visitUnknown(t, parentIsTag = false): @unused
visitUnknown(f, parentIsTag = false)
visitUnknown(s, parentIsTag = false)
visitUnknown(t, parentIsTag = false)
CUnit
} else failure()

override def visit[A](self: <|>[A], parentIsTag: Boolean)(p: LazyParsley[A], q: LazyParsley[A]): ConstUnit[A] =
if (parentIsTag == self.isOpaque) {
visitUnknown(p, parentIsTag = false): @unused
visitUnknown(q, parentIsTag = false): @unused
visitUnknown(p, parentIsTag = false)
visitUnknown(q, parentIsTag = false)
CUnit
} else failure()

override def visit[A](self: ChainPre[A], parentIsTag: Boolean)(p: LazyParsley[A], op: => LazyParsley[A => A]): ConstUnit[A] =
if (parentIsTag == self.isOpaque) {
visitUnknown(p, parentIsTag = false): @unused
visitUnknown(op, parentIsTag = false): @unused
visitUnknown(p, parentIsTag = false)
visitUnknown(op, parentIsTag = false)
CUnit
} else failure()

Expand Down

0 comments on commit 034d8bd

Please sign in to comment.