renaming context to scope, as it is rather scp[e than the context
This commit is contained in:
1 parent
6cf99fbd13
commit
ddbcbf9e4e
29 files changed
+414
-412
No files matched your search
@@ -3,8 +3,8 @@ import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.lyng.Context
|
||||
import net.sergeych.lyng.ObjVoid
|
||||
import net.sergeych.lyng.Scope
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Files.readAllLines
|
||||
import java.nio.file.Paths
|
||||
@@ -158,10 +158,10 @@ fun parseDocTests(fileName: String, bookMode: Boolean = false): Flow<DocTest> =
|
||||
}
|
||||
.flowOn(Dispatchers.IO)
|
||||
|
||||
suspend fun DocTest.test(context: Context = Context()) {
|
||||
suspend fun DocTest.test(scope: Scope = Scope()) {
|
||||
val collectedOutput = StringBuilder()
|
||||
val currentTest = this
|
||||
context.apply {
|
||||
scope.apply {
|
||||
addFn("println") {
|
||||
if( bookMode ) {
|
||||
println("${currentTest.fileNamePart}:${currentTest.line}> ${args.joinToString(" "){it.asStr.value}}")
|
||||
@@ -177,7 +177,7 @@ suspend fun DocTest.test(context: Context = Context()) {
|
||||
}
|
||||
var error: Throwable? = null
|
||||
val result = try {
|
||||
context.eval(code)
|
||||
scope.eval(code)
|
||||
} catch (e: Throwable) {
|
||||
error = e
|
||||
null
|
||||
@@ -204,10 +204,10 @@ suspend fun DocTest.test(context: Context = Context()) {
|
||||
}
|
||||
|
||||
suspend fun runDocTests(fileName: String, bookMode: Boolean = false) {
|
||||
val bookContext = Context()
|
||||
val bookScope = Scope()
|
||||
var count = 0
|
||||
parseDocTests(fileName, bookMode).collect { dt ->
|
||||
if (bookMode) dt.test(bookContext)
|
||||
if (bookMode) dt.test(bookScope)
|
||||
else dt.test()
|
||||
count++
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.datetime.Clock
|
||||
import net.sergeych.lyng.Context
|
||||
import net.sergeych.lyng.Scope
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import kotlin.io.path.extension
|
||||
@@ -13,7 +13,7 @@ suspend fun executeSampleTests(fileName: String) {
|
||||
Files.readString(Paths.get(fileName))
|
||||
}
|
||||
runBlocking {
|
||||
val c = Context()
|
||||
val c = Scope()
|
||||
val start = Clock.System.now()
|
||||
c.eval(sample)
|
||||
val time = Clock.System.now() - start
|
||||
|
||||
Reference in new issue
Block a user