]> git.kaiwu.me - quickjs.git/commitdiff
Add more tests
authorBen Noordhuis <info@bnoordhuis.nl>
Wed, 29 Nov 2023 07:50:53 +0000 (08:50 +0100)
committerCharlie Gordon <github@chqrlie.org>
Sun, 11 Feb 2024 15:20:39 +0000 (16:20 +0100)
- add regexp tests in tests/microbench.js
- add bjson_test_regexp in tests/test_test_bjson.js

tests/microbench.js
tests/test_bjson.js

index 69d963bc7e1f8e20e186867e62fec878442f4bd0..302f2ad7579cf5ce90bc8b48526a6d29f91c6e02 100644 (file)
@@ -695,6 +695,30 @@ function math_min(n)
     return n * 1000;
 }
 
+function regexp_ascii(n)
+{
+    var i, j, r, s;
+    s = "the quick brown fox jumped over the lazy dog"
+    for(j = 0; j < n; j++) {
+        for(i = 0; i < 10000; i++)
+            r = /the quick brown fox/.exec(s)
+        global_res = r;
+    }
+    return n * 10000;
+}
+
+function regexp_utf16(n)
+{
+    var i, j, r, s;
+    s = "the quick brown ᶠᵒˣ jumped over the lazy ᵈᵒᵍ"
+    for(j = 0; j < n; j++) {
+        for(i = 0; i < 10000; i++)
+            r = /the quick brown ᶠᵒˣ/.exec(s)
+        global_res = r;
+    }
+    return n * 10000;
+}
+
 /* incremental string contruction as local var */
 function string_build1(n)
 {
@@ -1026,6 +1050,8 @@ function main(argc, argv, g)
         array_for_in,
         array_for_of,
         math_min,
+        regexp_ascii,
+        regexp_utf16,
         string_build1,
         string_build1x,
         string_build2c,
index f15ef9158cba0f5fae672f79312d83558cf56202..faa22a6263a53e07d19a916bcb9ba157fa1bf5db 100644 (file)
@@ -144,6 +144,18 @@ function bjson_test_reference()
     }
 }
 
+function bjson_test_regexp()
+{
+    var buf, r;
+
+    bjson_test(/xyzzy/);
+    bjson_test(/xyzzy/digu);
+
+    buf = bjson.write(/(?<𝓓𝓸𝓰>dog)/);
+    r = bjson.read(buf, 0, buf.byteLength);
+    assert("sup dog".match(r).groups["𝓓𝓸𝓰"], "dog");
+}
+
 function bjson_test_all()
 {
     var obj;
@@ -186,6 +198,7 @@ function bjson_test_all()
     }
 
     bjson_test_reference();
+    bjson_test_regexp();
 }
 
 bjson_test_all();