diff --git a/src/core/gc.c b/src/core/gc.c index d6cd51ae..0cb5562e 100644 --- a/src/core/gc.c +++ b/src/core/gc.c @@ -245,10 +245,7 @@ static void janet_deinit_block(JanetGCMemoryHeader *block) { break; case JANET_MEMORY_ABSTRACT: if (h->type->gc) { - if (h->type->gc((void *)(h + 1), h->size)) { - /* finalizer failed. try again later? Panic? For now do nothing. */ - ; - } + janet_assert(!h->type->gc((void *)(h + 1), h->size), "finalizer failed"); } break; case JANET_MEMORY_FUNCENV: diff --git a/src/core/string.c b/src/core/string.c index 04f9ceea..f2db2fe7 100644 --- a/src/core/string.c +++ b/src/core/string.c @@ -605,6 +605,11 @@ static void kmp_deinit(struct kmp_state *state) { free(state->lookup); } +static void kmp_seti(struct kmp_state *state, int32_t i) { + state->i = i; + state->j = 0; +} + static int32_t kmp_next(struct kmp_state *state) { int32_t i = state->i; int32_t j = state->j; @@ -880,6 +885,7 @@ static int cfun_replaceall(JanetArgs args) { janet_buffer_push_bytes(&b, s.kmp.text + lastindex, result - lastindex); janet_buffer_push_bytes(&b, s.subst, s.substlen); lastindex = result + s.kmp.patlen; + kmp_seti(&s.kmp, lastindex); } janet_buffer_push_bytes(&b, s.kmp.text + lastindex, s.kmp.textlen - lastindex); ret = janet_string(b.data, b.count); diff --git a/src/include/janet/janet.h b/src/include/janet/janet.h index 03274cf0..56f22b31 100644 --- a/src/include/janet/janet.h +++ b/src/include/janet/janet.h @@ -167,10 +167,12 @@ extern "C" { * To turn of nanboxing, for debugging purposes or for certain * architectures (Nanboxing only tested on x86 and x64), comment out * the JANET_NANBOX define.*/ +#ifndef JANET_NO_NANBOX #define JANET_NANBOX /* Further refines the type of nanboxing to use. */ #define JANET_NANBOX_47 +#endif /* Alignment for pointers */ #ifdef JANET_32 diff --git a/test/suite0.janet b/test/suite0.janet index 71c48a28..8c4e2ae9 100644 --- a/test/suite0.janet +++ b/test/suite0.janet @@ -34,6 +34,8 @@ (assert (<= 1.0 2.0 3.0 3.0 4.0 5.0 6.0) "less than or equal to reals") (assert (>= 6 5 4 4 3 2 1) "greater than or equal to integers") (assert (>= 6.0 5.0 4.0 4.0 3.0 2.0 1.0) "greater than or equal to reals") +(assert (= 7 (% 20 13)) "modulo 1") +(assert (= -7 (% -20 13)) "modulo 2") (assert (order< nil false true (fiber.new (fn [x] x)) @@ -60,6 +62,8 @@ (assert (not nil) "nil literal") (assert (= 7 (| 3 4)) "bit or") (assert (= 0 (& 3 4)) "bit and") +(assert (= 0xFF (^ 0x0F 0xF0)) "bit xor") +(assert (= 0xF0 (^ 0xFF 0x0F)) "bit xor 2") # Set global variables to prevent some possible compiler optimizations that defeat point of the test (var zero 0) diff --git a/test/suite2.janet b/test/suite2.janet index ca138679..482c1294 100644 --- a/test/suite2.janet +++ b/test/suite2.janet @@ -52,5 +52,25 @@ (def X1 100) (assert (= X1 100) "X1 as symbol") +# String functions +(assert (= 3 (string.find "abc" " abcdefghijklmnop")) "string.find 1") +(assert (= nil (string.find "" "")) "string.find 2") +(assert (= 0 (string.find "A" "A")) "string.find 3") +(assert (= (string.replace "X" "." "XXX...XXX...XXX") ".XX...XXX...XXX") "string.replace 1") +(assert (= (string.replace-all "X" "." "XXX...XXX...XXX") "...............") "string.replace-all 1") +(assert (= (string.replace-all "XX" "." "XXX...XXX...XXX") ".X....X....X") "string.replace-all 2") +(assert (= (string.ascii-lower "ABCabc&^%!@:;.") "abcabc&^%!@:;.") "string.ascii-lower") +(assert (= (string.ascii-upper "ABCabc&^%!@:;.") "ABCABC&^%!@:;.") "string.ascii-lower") +(assert (= (string.reverse "") "") "string.reverse 1") +(assert (= (string.reverse "a") "a") "string.reverse 2") +(assert (= (string.reverse "abc") "cba") "string.reverse 3") +(assert (= (string.reverse "abcd") "dcba") "string.reverse 4") +(assert (= (string.join @["one" "two" "three"] ",") "one,two,three") "string.join 1") +(assert (= (string.join @["one" "two" "three"] ", ") "one, two, three") "string.join 2") +(assert (= (string.join @["one" "two" "three"]) "onetwothree") "string.join 3") +(assert (= (string.join @[] "hi") "") "string.join 4") +(assert (deep= (string.split "," "one,two,three") @["one" "two" "three"]) "string.split 1") +(assert (deep= (string.split "," "onetwothree") @["onetwothree"]) "string.split 2") + (end-suite)