more dics & minor bugs fixed
This commit is contained in:
1 parent
9a08da0dfd
commit
5591a66af3
5 files changed
+119
-5
No files matched your search
@@ -8,6 +8,13 @@ data class ArgsDeclaration(val args: List<Item>, val endTokenType: Token.Type) {
|
||||
init {
|
||||
val i = args.count { it.isEllipsis }
|
||||
if (i > 1) throw ScriptError(args[i].pos, "there can be only one argument")
|
||||
val start = args.indexOfFirst { it.defaultValue != null }
|
||||
if (start >= 0)
|
||||
for (j in start + 1 until args.size)
|
||||
if (args[j].defaultValue == null) throw ScriptError(
|
||||
args[j].pos,
|
||||
"required argument can't follow default one"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,7 +68,7 @@ data class ArgsDeclaration(val args: List<Item>, val endTokenType: Token.Type) {
|
||||
fun processEllipsis(index: Int, toFromIndex: Int) {
|
||||
val a = args[index]
|
||||
val l = if (index > toFromIndex) ObjList()
|
||||
else ObjList( fromArgs.values.subList(index, toFromIndex+1).toMutableList())
|
||||
else ObjList(fromArgs.values.subList(index, toFromIndex + 1).toMutableList())
|
||||
assign(a, l)
|
||||
}
|
||||
|
||||
@@ -69,9 +76,8 @@ data class ArgsDeclaration(val args: List<Item>, val endTokenType: Token.Type) {
|
||||
if (leftIndex < args.size) {
|
||||
val end = processTail(leftIndex)
|
||||
processEllipsis(leftIndex, end)
|
||||
}
|
||||
else {
|
||||
if( leftIndex < fromArgs.size)
|
||||
} else {
|
||||
if (leftIndex < fromArgs.size)
|
||||
context.raiseArgumentError("too many arguments for the call")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,6 +125,20 @@ class Script(
|
||||
if( a.compareTo(this, b) != 0 )
|
||||
raiseError(ObjAssertionError(this,"Assertion failed: ${a.inspect()} == ${b.inspect()}"))
|
||||
}
|
||||
addFn("assertThrows") {
|
||||
val code = requireOnlyArg<Statement>()
|
||||
val result =try {
|
||||
code.execute(this)
|
||||
null
|
||||
}
|
||||
catch( e: ExecutionError ) {
|
||||
e.errorObject
|
||||
}
|
||||
catch (e: ScriptError) {
|
||||
ObjNull
|
||||
}
|
||||
result ?: raiseError(ObjAssertionError(this,"Expected exception but nothing was thrown"))
|
||||
}
|
||||
|
||||
addVoidFn("delay") {
|
||||
delay((this.args.firstAndOnly().toDouble()/1000.0).roundToLong())
|
||||
|
||||
@@ -195,7 +195,7 @@ suspend fun DocTest.test(context: Context = Context()) {
|
||||
System.err.println("\nfailed: ${this.detailedString}")
|
||||
}
|
||||
error?.let {
|
||||
fail("test failed", it)
|
||||
fail(it.message, it)
|
||||
}
|
||||
assertEquals(expectedOutput, collectedOutput.toString(), "script output do not match")
|
||||
assertEquals(expectedResult, result.toString(), "script result does not match")
|
||||
@@ -263,4 +263,9 @@ class BookTest {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testArgumentBooks() = runTest {
|
||||
runDocTests("../docs/declaring_arguments.md")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user