|
|
|
@ -1,6 +1,7 @@
|
|
|
|
package fr.celticinfo.lox
|
|
|
|
package fr.celticinfo.lox
|
|
|
|
|
|
|
|
|
|
|
|
import fr.celticinfo.loxext.RpnPrinter
|
|
|
|
import fr.celticinfo.loxext.RpnPrinter
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Assertions
|
|
|
|
import org.junit.jupiter.api.assertDoesNotThrow
|
|
|
|
import org.junit.jupiter.api.assertDoesNotThrow
|
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
|
import java.io.ByteArrayOutputStream
|
|
|
|
import java.io.PrintStream
|
|
|
|
import java.io.PrintStream
|
|
|
|
@ -358,4 +359,32 @@ for (var b = 1; a < 10000; b = temp + b) {
|
|
|
|
System.setOut(standardOut)
|
|
|
|
System.setOut(standardOut)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
fun `Clock native function should return a valid timestamp`() {
|
|
|
|
|
|
|
|
val standardOut = System.out
|
|
|
|
|
|
|
|
val outputStreamCaptor = ByteArrayOutputStream()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
System.setOut(PrintStream(outputStreamCaptor))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
val code = """
|
|
|
|
|
|
|
|
print clock();
|
|
|
|
|
|
|
|
""".trimIndent()
|
|
|
|
|
|
|
|
val scanner = Scanner(code)
|
|
|
|
|
|
|
|
val tokens = scanner.scanTokens()
|
|
|
|
|
|
|
|
val parser = Parser(tokens)
|
|
|
|
|
|
|
|
val statements = parser.parse()
|
|
|
|
|
|
|
|
Assertions.assertEquals(1, statements.size)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Interpreter().interpret(statements)
|
|
|
|
|
|
|
|
val output = outputStreamCaptor.toString().trim()
|
|
|
|
|
|
|
|
val timestamp = output.toDoubleOrNull()
|
|
|
|
|
|
|
|
Assertions.assertNotNull(timestamp)
|
|
|
|
|
|
|
|
Assertions.assertTrue(timestamp!! >= 0)
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
System.setOut(standardOut)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|