commit 3f27d54f75472fe30bc86d335ba10ff297a98361
parent 8879cbfba0a2e64da855ae597d98c09fa6432b47
Author: lash <dev@holbrook.no>
Date: Tue, 20 Aug 2024 18:56:07 +0100
Accept plus prefix in input
Diffstat:
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/vm/input.go b/vm/input.go
@@ -11,7 +11,7 @@ import (
)
var (
- inputRegexStr = "^[a-zA-Z0-9].*$"
+ inputRegexStr = "^\\+?[a-zA-Z0-9].*$"
inputRegex = regexp.MustCompile(inputRegexStr)
ctrlRegexStr = "^[><_^.]$"
ctrlRegex = regexp.MustCompile(ctrlRegexStr)
diff --git a/vm/input_test.go b/vm/input_test.go
@@ -0,0 +1,34 @@
+package vm
+
+import (
+ "testing"
+)
+
+func TestPhoneInput(t *testing.T) {
+ err := ValidInput([]byte("+12345"))
+ if err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestMenuInputs(t *testing.T) {
+ err := ValidInput([]byte("0"))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = ValidInput([]byte("99"))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = ValidInput([]byte("foo"))
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ err = ValidInput([]byte("foo Bar"))
+ if err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/vm/runner_test.go b/vm/runner_test.go
@@ -670,11 +670,10 @@ func TestCatchCleanMenu(t *testing.T) {
t.Fatal(err)
}
- r, err := vm.Render(ctx)
+ _, err = vm.Render(ctx)
if err != nil {
t.Fatal(err)
}
- fmt.Printf("Result:\n%s", r)
}
func TestSetLang(t *testing.T) {