Skip to content

Commit

Permalink
fix: VAL("invalid string") should return 0
Browse files Browse the repository at this point in the history
fixes #71
  • Loading branch information
ianatha committed Nov 7, 2023
1 parent 941b275 commit 05fce63
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,7 @@ object Functions {
try {
result!!.float64 = str!!.toDouble()
} catch (e: NumberFormatException) {
throw RuntimeError(
RuntimeError.ErrorCode.DATA_OUT_OF_RANGE,
"Failed to parse string: $str as numeric"
)
result!!.float64 = 0.0
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class IntegrationTest {
runTest("string_functions.bas", "string_functions.bas.output")
}

@Test
fun testValOfString() {
runTest("val_of_string.bas", "val_of_string.bas.output")
}

@Test
fun testJim01() {
val e = assertFailsWith<RuntimeError> {
Expand Down
3 changes: 3 additions & 0 deletions libbababasic/src/test/resources/val_of_string.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRINT VAL("1")
PRINT VAL("2")
PRINT VAL("INVALID")
3 changes: 3 additions & 0 deletions libbababasic/src/test/resources/val_of_string.bas.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.0
2.0
0.0

0 comments on commit 05fce63

Please sign in to comment.