From 7a8c66331560cd5895c7ba98e75903f620dda9eb Mon Sep 17 00:00:00 2001 From: Joshua Bell Date: Mon, 5 Dec 2022 18:46:44 -0800 Subject: [PATCH] Further fixes for LEFT$/MID$/RIGHT$ and tests * MID$ allows 0 for the second (length) argument * Add tests for error cases. --- basic.js | 2 +- samples/sample.unittests.txt | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/basic.js b/basic.js index f8ebc01..7ac7131 100644 --- a/basic.js +++ b/basic.js @@ -1141,7 +1141,7 @@ this.basic = (function() { if (n < 1 || n > 255) { runtime_error(ERRORS.ILLEGAL_QUANTITY); } - if (n2 < 1 || n2 > 255) { + if (n2 < 0 || n2 > 255) { runtime_error(ERRORS.ILLEGAL_QUANTITY); } return n2 === (void 0) ? s.substring(n - 1) : s.substring(n - 1, n + n2 - 1); diff --git a/samples/sample.unittests.txt b/samples/sample.unittests.txt index cef6335..236a9f3 100644 --- a/samples/sample.unittests.txt +++ b/samples/sample.unittests.txt @@ -592,19 +592,51 @@ : S = (LEN("") = 0) : GOSUB 1 11020 T$ = "LEFT$()" -: S = (LEFT$("ABC",0) = "") : GOSUB 1 : S = (LEFT$("ABC",2) = "AB") : GOSUB 1 : S = (LEFT$("ABC",4) = "ABC") : GOSUB 1 +: ONERR GOTO 11022 +11021 T = 1 +: T = (LEFT$("A",0) = "NOPE") +11022 S = (T=1) : GOSUB 1 : POKE 216,0 +: ONERR GOTO 11024 +11023 T = 1 +: T = (LEFT$("A",256) = "NOPE") +11024 S = (T=1) : POKE 216,0 : GOSUB 1 11030 T$ = "MID$()" : S = (MID$("ABCD",2,2) = "BC") : GOSUB 1 : S = (MID$("ABCD",3) = "CD") : GOSUB 1 : S = (MID$("ABCD",4,3) = "D") : GOSUB 1 +: S = (MID$("ABCD",5,4) = "") : GOSUB 1 +: ONERR GOTO 11032 +11031 T = 1 +: T = (MID$("A",0) = "NOPE") +11032 S = (T=1) : GOSUB 1 : POKE 216,0 +: ONERR GOTO 11034 +11033 T = 1 +: T = (MID$("A",256) = "NOPE") +11034 S = (T=1) : POKE 216,0 : GOSUB 1 +: S = (MID$("A",1,0) = "") : GOSUB 1 +: ONERR GOTO 11036 +11035 T = 1 +: T = (MID$("A",1,-1) = "NOPE") +11036 S = (T=1) : POKE 216,0 : GOSUB 1 +: ONERR GOTO 11038 +11037 T = 1 +: T = (MID$("A",1,256) = "NOPE") +11038 S = (T=1) : POKE 216,0 : GOSUB 1 11040 T$ = "RIGHT$()" -: S = (RIGHT$("ABC",0) = "") : GOSUB 1 : S = (RIGHT$("ABC",2) = "BC") : GOSUB 1 : S = (RIGHT$("ABC",4) = "ABC") : GOSUB 1 +: ONERR GOTO 11042 +11041 T = 1 +: T = (RIGHT$("A",0) = "NOPE") +11042 S = (T=1) : GOSUB 1 : POKE 216,0 +: ONERR GOTO 11044 +11043 T = 1 +: T = (RIGHT$("A",256) = "NOPE") +11044 S = (T=1) : POKE 216,0 : GOSUB 1 12000 PRINT : PRINT "Type Conversion Functions ";