-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[base] Add an id variant of the string concatenator repeated
Also, add some unit tests for the new repeateds
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 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
28 changes: 28 additions & 0 deletions
28
Base/src/test/scala-3/typeclass/VersonSpecificRepeatedTest.scala
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,28 @@ | ||
package name.rayrobdod.stringContextParserCombinator | ||
package typeclass | ||
package repeated | ||
|
||
import scala.quoted.* | ||
import munit.Location | ||
|
||
final class QuotedConcatenateStringTest extends munit.FunSuite { | ||
inline def assertParseSuccess( | ||
inline sc: StringContext, | ||
inline args: Any*)( | ||
expecting:String)( | ||
using loc:Location | ||
):Unit = ${ | ||
QuotedConcatenateStringTestImpls.assertParseSuccessImpl( | ||
'this, 'sc, 'args, 'expecting, 'loc) | ||
} | ||
|
||
test ("0") { | ||
assertParseSuccess(StringContext(""))("") | ||
} | ||
test ("1") { | ||
assertParseSuccess(StringContext("ab"))("ab") | ||
} | ||
test ("many") { | ||
assertParseSuccess(StringContext("ab", "cd", "ef"), "12", "34")("ab12cd34ef") | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
Base/src/test/scala-3/typeclass/VersonSpecificRepeatedTestImpls.scala
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,30 @@ | ||
package name.rayrobdod.stringContextParserCombinator | ||
package typeclass | ||
package repeated | ||
|
||
import scala.quoted.* | ||
import munit.Location | ||
import Interpolator.{charWhere, ofType, end} | ||
|
||
object QuotedConcatenateStringTestImpls { | ||
def assertParseSuccessImpl( | ||
self: Expr[munit.FunSuite], | ||
sc: Expr[StringContext], | ||
args: Expr[Seq[Any]], | ||
expecting: Expr[String], | ||
loc: Expr[Location])( | ||
using Quotes | ||
):Expr[Unit] = { | ||
|
||
val dut = (charWhere(_ => true).repeat(1).mapToExpr orElse ofType[String]) | ||
.repeat()(using Repeated.quotedConcatenateString) | ||
.andThen(end) | ||
|
||
val actual = dut.interpolate(sc, args) | ||
|
||
'{ | ||
given Location = ${loc} | ||
$self.assertEquals($actual, $expecting) | ||
} | ||
} | ||
} |
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,21 @@ | ||
package name.rayrobdod.stringContextParserCombinator | ||
package typeclass | ||
package repeated | ||
|
||
import Interpolator.idInterpolators.{charWhere, ofType, end} | ||
|
||
final class IdConcatenateString extends BaseInterpolatorSuite { | ||
val dut = (charWhere(_ => true).repeat(1) orElse ofType[String]) | ||
.repeat()(using Repeated.idConcatenateString) | ||
.andThen(end) | ||
|
||
test ("0") { | ||
assertParseSuccess(dut, ("" :: Nil, Nil), "") | ||
} | ||
test ("1") { | ||
assertParseSuccess(dut, ("ab" :: Nil, Nil), "ab") | ||
} | ||
test ("many") { | ||
assertParseSuccess(dut, ("ab" :: "cd" :: "ef" :: Nil, "12" :: "34" :: Nil), "ab12cd34ef") | ||
} | ||
} |