diff --git a/compiler+runtime/CMakeLists.txt b/compiler+runtime/CMakeLists.txt index decd5bfab..f7be9303a 100644 --- a/compiler+runtime/CMakeLists.txt +++ b/compiler+runtime/CMakeLists.txt @@ -449,11 +449,17 @@ if(jank_tests) test/cpp/jank/read/lex.cpp test/cpp/jank/read/parse.cpp test/cpp/jank/analyze/box.cpp + test/cpp/jank/runtime/core.cpp + test/cpp/jank/runtime/core/seq.cpp test/cpp/jank/runtime/detail/native_persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/ratio.cpp + test/cpp/jank/runtime/obj/persistent_list.cpp test/cpp/jank/runtime/obj/persistent_string.cpp test/cpp/jank/runtime/obj/persistent_vector.cpp + test/cpp/jank/runtime/obj/range.cpp + test/cpp/jank/runtime/obj/integer_range.cpp + test/cpp/jank/runtime/obj/repeat.cpp test/cpp/jank/jit/processor.cpp ) add_executable(jank::test_exe ALIAS jank_test_exe) diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp index 0cf41f3c1..e39f79b45 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/integer_range.hpp @@ -19,6 +19,7 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(integer_ptr, integer_ptr); + /* Constructors are only to be used in integer_range.cpp. Prefer range::create. */ integer_range() = default; integer_range(integer_range &&) noexcept = default; integer_range(integer_range const &) = default; diff --git a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp index 62e403173..a5c91451c 100644 --- a/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/obj/range.hpp @@ -21,6 +21,7 @@ namespace jank::runtime::obj using bounds_check_t = native_bool (*)(object_ptr, object_ptr); + /* Constructors are only to be used in range.cpp. Prefer range::create. */ range() = default; range(range &&) noexcept = default; range(range const &) = default; diff --git a/compiler+runtime/src/cpp/clojure/core_native.cpp b/compiler+runtime/src/cpp/clojure/core_native.cpp index 078c7b709..ec971e516 100644 --- a/compiler+runtime/src/cpp/clojure/core_native.cpp +++ b/compiler+runtime/src/cpp/clojure/core_native.cpp @@ -798,8 +798,10 @@ jank_object_ptr jank_load_clojure_core_native() { auto const fn( make_box(behavior::callable::build_arity_flags(2, false, false))); - fn->arity_1 = [](object * const val) -> object * { return repeat(val); }; - fn->arity_2 = [](object * const n, object * const val) -> object * { return repeat(n, val); }; + fn->arity_1 = [](object * const val) -> object * { return obj::repeat::create(val); }; + fn->arity_2 = [](object * const n, object * const val) -> object * { + return obj::repeat::create(n, val); + }; intern_fn_obj("repeat", fn); } diff --git a/compiler+runtime/src/cpp/jank/read/parse.cpp b/compiler+runtime/src/cpp/jank/read/parse.cpp index e7791c81e..170069cd3 100644 --- a/compiler+runtime/src/cpp/jank/read/parse.cpp +++ b/compiler+runtime/src/cpp/jank/read/parse.cpp @@ -783,7 +783,7 @@ namespace jank::read::parse auto const jank_keyword(__rt_ctx->intern_keyword("", "jank").expect_ok()); auto const default_keyword(__rt_ctx->intern_keyword("", "default").expect_ok()); - for(auto it(list->fresh_seq()); it != nullptr;) + for(auto it(list->fresh_seq()); it != nullptr; it = next_in_place(next_in_place(it))) { auto const kw(it->first()); /* We take the first match, checking for :jank first. If there are duplicates, it doesn't @@ -829,8 +829,6 @@ namespace jank::read::parse return object_source_info{ next_in_place(it)->first(), start_token, list_end }; } } - - it = next_in_place(next_in_place(it)); } return ok(none); diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index b5d60b6cd..a6cae170e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -1032,7 +1032,7 @@ namespace jank::runtime } if(!l_it) { - return r_it == nullptr; + return false; } for(; l_it != nullptr; l_it = l_it->next_in_place(), r_it = r_it->next_in_place()) @@ -1178,12 +1178,12 @@ namespace jank::runtime object_ptr repeat(object_ptr const val) { - return make_box(val); + return obj::repeat::create(val); } object_ptr repeat(object_ptr const n, object_ptr const val) { - return make_box(n, val); + return obj::repeat::create(n, val); } object_ptr sort(object_ptr const coll) diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp index cf9ede269..dde61c883 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/chunked_cons.cpp @@ -162,12 +162,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp index e7e70f8fc..74f2f0994 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/cons.cpp @@ -77,12 +77,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp index 9628ead67..373e7c5ce 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/base_persistent_map_sequence.cpp @@ -23,12 +23,12 @@ namespace jank::runtime::obj::detail for(auto it(fresh_seq()); it != nullptr; it = it->next_in_place(), seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp index fa3a80f30..d28e7255c 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/detail/iterator_sequence.cpp @@ -39,7 +39,7 @@ namespace jank::runtime::obj::detail return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp index d1e072d22..a827a29d7 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/integer_range.cpp @@ -80,7 +80,7 @@ namespace jank::runtime::obj } else if(is_zero(step)) { - return make_box(make_box(start)); + return repeat::create(make_box(start)); } return make_box(start, end, @@ -137,12 +137,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = it->next_in_place(), seq = seq->next_in_place()) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp index 6f7a23020..2395a9888 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/iterator.cpp @@ -64,12 +64,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); @@ -92,6 +92,7 @@ namespace jank::runtime::obj native_hash iterator::to_hash() const { + /* Runs forever. */ return hash::ordered(&base); } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp index fb2ee6e5b..a14c31646 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/lazy_sequence.cpp @@ -56,6 +56,7 @@ namespace jank::runtime::obj if(sequence) { auto const n(runtime::next(sequence)); + assert(n); if(n == nil::nil_const()) { return nullptr; @@ -69,6 +70,7 @@ namespace jank::runtime::obj { assert(sequence); auto const n(runtime::next_in_place(sequence)); + assert(n); if(n == nil::nil_const()) { return nullptr; diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp index 368893b20..dc38e595e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_array_sequence.cpp @@ -23,7 +23,7 @@ namespace jank::runtime::obj assert(size > 0); } - /* behavior::objectable */ + /* behavior::object_like */ native_bool native_array_sequence::equal(object const &o) const { return runtime::equal(o, arr + index, arr + size); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp index 60f176815..2dc258503 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/native_vector_sequence.cpp @@ -32,7 +32,7 @@ namespace jank::runtime::obj { } - /* behavior::objectable */ + /* behavior::object_like */ native_bool native_vector_sequence::equal(object const &o) const { return runtime::equal(o, data.begin(), data.end()); @@ -120,6 +120,7 @@ namespace jank::runtime::obj { auto const meta(behavior::detail::validate_meta(m)); auto ret(fresh_seq()); + assert(ret); ret->meta = meta; return ret; } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp index dbcd92967..f85b4a5eb 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_list.cpp @@ -86,11 +86,7 @@ namespace jank::runtime::obj persistent_list_sequence_ptr persistent_list::seq() const { - if(data.empty()) - { - return nullptr; - } - return make_box(this, data.begin(), data.end(), data.size()); + return fresh_seq(); } persistent_list_sequence_ptr persistent_list::fresh_seq() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp index dad7697b6..549dcaf5f 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string.cpp @@ -156,11 +156,7 @@ namespace jank::runtime::obj persistent_string_sequence_ptr persistent_string::seq() const { - if(data.empty()) - { - return nullptr; - } - return make_box(const_cast(this)); + return fresh_seq(); } persistent_string_sequence_ptr persistent_string::fresh_seq() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp index 0785819f5..8ebf7b4e8 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_string_sequence.cpp @@ -19,7 +19,7 @@ namespace jank::runtime::obj assert(!s->data.empty() && i < s->data.size()); } - /* behavior::objectable */ + /* behavior::object_like */ native_bool persistent_string_sequence::equal(object const &o) const { return runtime::equal(o, str->data.begin() + index, str->data.end()); diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp index 12d5e2c01..5cf8d752e 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector.cpp @@ -97,18 +97,12 @@ namespace jank::runtime::obj { size_t i{}; auto e(typed_o->fresh_seq()); - for(; e != nullptr; e = e->next_in_place()) + for(; e != nullptr && i < data.size(); e = e->next_in_place(), ++i) { if(!runtime::equal(data[i], e->first())) { return false; } - - if(++i == data.size()) - { - e = e->next_in_place(); - break; - } } return e == nullptr && i == data.size(); } @@ -184,11 +178,7 @@ namespace jank::runtime::obj persistent_vector_sequence_ptr persistent_vector::seq() const { - if(data.empty()) - { - return nullptr; - } - return make_box(const_cast(this)); + return fresh_seq(); } persistent_vector_sequence_ptr persistent_vector::fresh_seq() const diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp index c4d28a9b0..447453ffa 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/persistent_vector_sequence.cpp @@ -20,7 +20,7 @@ namespace jank::runtime::obj assert(0 < v->data.size() - index); } - /* behavior::objectable */ + /* behavior::object_like */ native_bool persistent_vector_sequence::equal(object const &o) const { return runtime::equal( diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp index 6d2b0a99e..b70fe0a60 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/range.cpp @@ -90,7 +90,7 @@ namespace jank::runtime::obj } /* TODO: Repeat object. */ //else if(is_zero(step)) - //{ return make_box(start); } + //{ return repeat::create(start); } return make_box(start, end, step, @@ -209,12 +209,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); @@ -244,6 +244,7 @@ namespace jank::runtime::obj { auto const meta(behavior::detail::validate_meta(m)); auto ret(fresh_seq()); + assert(ret); ret->meta = meta; return ret; } diff --git a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp index ba49ec034..88cbcf030 100644 --- a/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/obj/repeat.cpp @@ -16,6 +16,7 @@ namespace jank::runtime::obj : value{ value } , count{ count } { + assert(0 < to_int(count)); } object_ptr repeat::create(object_ptr const value) @@ -53,7 +54,7 @@ namespace jank::runtime::obj { return this; } - if(lt(count, make_box(1))) + if(lte(count, make_box(1))) { return nullptr; } @@ -88,12 +89,12 @@ namespace jank::runtime::obj for(auto it(fresh_seq()); it != nullptr; it = runtime::next_in_place(it), seq = runtime::next_in_place(seq)) { - if(seq == nullptr || !runtime::equal(it, seq->first())) + if(seq == nullptr || !runtime::equal(it->first(), seq->first())) { return false; } } - return true; + return seq == nullptr; }, []() { return false; }, &o); diff --git a/compiler+runtime/test/cpp/jank/runtime/core.cpp b/compiler+runtime/test/cpp/jank/runtime/core.cpp new file mode 100644 index 000000000..e3b4ad9ab --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/core.cpp @@ -0,0 +1,18 @@ +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime +{ + TEST_SUITE("core runtime") + { + TEST_CASE("equal") + { + CHECK(equal(nullptr, nullptr)); + CHECK(!equal(nullptr, make_box(42))); + CHECK(!equal(make_box(42), nullptr)); + } + } +} diff --git a/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp new file mode 100644 index 000000000..f6f3fd409 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/core/seq.cpp @@ -0,0 +1,18 @@ +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::core +{ + TEST_SUITE("core runtime for seq") + { + TEST_CASE("sequence_equal") + { + CHECK(equal(nullptr, nullptr)); + CHECK(!equal(nullptr, make_box(42))); + CHECK(!equal(make_box(42), nullptr)); + } + } +} diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp new file mode 100644 index 000000000..94498feed --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/integer_range.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("integer_range") + { + TEST_CASE("equal") + { + CHECK(equal(integer_range::create(make_box(5)), integer_range::create(make_box(5)))); + CHECK(equal(integer_range::create(make_box(1)), integer_range::create(make_box(1)))); + CHECK(!equal(integer_range::create(make_box(6)), integer_range::create(make_box(5)))); + CHECK(!equal(integer_range::create(make_box(5)), integer_range::create(make_box(6)))); + CHECK(equal(integer_range::create(make_box(0)), integer_range::create(make_box(0)))); + CHECK(!equal(integer_range::create(make_box(0)), integer_range::create(make_box(5)))); + CHECK(!equal(integer_range::create(make_box(1)), integer_range::create(make_box(0)))); + } + } +} diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp new file mode 100644 index 000000000..81acadca8 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_list.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("persistent_list") + { + TEST_CASE("equal") + { + CHECK( + equal(make_box(std::in_place), make_box(std::in_place))); + CHECK(!equal(make_box(std::in_place), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place))); + CHECK(equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f')))); + } + } +} diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp index d0abcc14d..285475234 100644 --- a/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp +++ b/compiler+runtime/test/cpp/jank/runtime/obj/persistent_vector.cpp @@ -63,5 +63,20 @@ namespace jank::runtime::obj CHECK(equal(v->get_entry(under), nil)); CHECK(equal(v->get_entry(non_int), nil)); } + TEST_CASE("equal") + { + CHECK(equal(make_box(std::in_place), + make_box(std::in_place))); + CHECK(!equal(make_box(std::in_place), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place))); + CHECK(equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f')), + make_box(std::in_place, make_box('f'), make_box('o')))); + CHECK(!equal(make_box(std::in_place, make_box('f'), make_box('o')), + make_box(std::in_place, make_box('f')))); + } } } diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp new file mode 100644 index 000000000..41aab4a9d --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/range.cpp @@ -0,0 +1,23 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("range") + { + TEST_CASE("equal") + { + CHECK(equal(range::create(make_box(5)), range::create(make_box(5)))); + CHECK(equal(range::create(make_box(1)), range::create(make_box(1)))); + CHECK(!equal(range::create(make_box(6)), range::create(make_box(5)))); + CHECK(!equal(range::create(make_box(5)), range::create(make_box(6)))); + CHECK(equal(range::create(make_box(0)), range::create(make_box(0)))); + CHECK(!equal(range::create(make_box(0)), range::create(make_box(5)))); + CHECK(!equal(range::create(make_box(1)), range::create(make_box(0)))); + } + } +} diff --git a/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp new file mode 100644 index 000000000..3d7bec719 --- /dev/null +++ b/compiler+runtime/test/cpp/jank/runtime/obj/repeat.cpp @@ -0,0 +1,37 @@ +#include +#include +#include + +/* This must go last; doctest and glog both define CHECK and family. */ +#include + +namespace jank::runtime::obj +{ + TEST_SUITE("repeat") + { + TEST_CASE("equal") + { + CHECK( + equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(5)))); + CHECK( + equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(1), make_box(1)))); + CHECK( + !equal(repeat::create(make_box(6), make_box(5)), repeat::create(make_box(5), make_box(5)))); + CHECK( + !equal(repeat::create(make_box(5), make_box(5)), repeat::create(make_box(5), make_box(6)))); + CHECK( + equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(0), make_box(0)))); + CHECK( + !equal(repeat::create(make_box(0), make_box(0)), repeat::create(make_box(5), make_box(0)))); + CHECK( + !equal(repeat::create(make_box(1), make_box(1)), repeat::create(make_box(0), make_box(1)))); + + CHECK(equal(repeat::create(make_box(0), make_box(0)), persistent_list::empty())); + CHECK(equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); + } + TEST_CASE("seq") + { + CHECK(equal(seq(repeat::create(make_box(0), make_box(0))), nil::nil_const())); + } + } +}