浏览代码

Shell: Add some tests for 'match'

AnotherTest 4 年之前
父节点
当前提交
4f223793c0
共有 1 个文件被更改,包括 53 次插入0 次删除
  1. 53 0
      Shell/Tests/match.sh

+ 53 - 0
Shell/Tests/match.sh

@@ -0,0 +1,53 @@
+#!/bin/Shell
+
+result=no
+match hello {
+    he* { result=yes }
+    * { result=fail }
+};
+
+test "$result" = yes || echo invalid result $result for normal string match, single option && exit 1
+
+result=no
+match hello {
+    he* | f* { result=yes }
+    * { result=fail }
+};
+
+test "$result" = yes || echo invalid result $result for normal string match, multiple options && exit 1
+
+result=no
+match (well hello friends) {
+    (* *) { result=fail }
+    (* * *) { result=yes }
+    * { result=fail }
+};
+
+test "$result" = yes || echo invalid result $result for list match && exit 1
+
+result=no
+match yes as v {
+    () { result=fail }
+    (*) { result=yes }
+    * { result=$v }
+};
+
+test "$result" = yes || echo invalid result $result for match with name && exit 1
+
+result=no
+# $(...) is a list, $(echo) should be an empty list, not an empty string
+match $(echo) {
+    * { result=fail }
+    () { result=yes }
+};
+
+test "$result" = yes || echo invalid result $result for list subst match && exit 1
+
+result=no
+# "$(...)" is a string, "$(echo)" should be an empty string, not an empty list
+match "$(echo)" {
+    * { result=yes }
+    () { result=fail }
+};
+
+test "$result" = yes || echo invalid result $result for string subst match && exit 1