Lines
100 %
Functions
Branches
//! Entity-accessor native fn codegen.
use nomiscript::SymbolTable;
use super::common::{compile_and_validate, wrap_with_runtime_i32};
#[test]
fn entity_count_alone() {
compile_and_validate("(entity-count)");
}
fn context_type() {
compile_and_validate("(context-type)");
fn primary_entity_type() {
compile_and_validate("(primary-entity-type)");
fn primary_entity_idx() {
compile_and_validate("(primary-entity-idx)");
fn entity_count_in_comparison() {
compile_and_validate("(if (= (entity-count) 0) \"empty\" \"has-entities\")");
fn entity_count_in_do_loop() {
compile_and_validate(
"(let* ((n (entity-count)) (sum 0)) \
(do ((i 0 (+ i 1))) ((>= i n) sum) \
(setf sum (+ sum 1))))",
);
fn entity_type_with_runtime_idx() {
// `IDX` is a runtime i32 via `(entity-count)`; the entity-type
// host fn takes it as an arg through the standard wasm-stack arg
// path. Pre-fix this test injected `Expr::WasmRuntime(I32)` as
// the symbol value directly.
compile_and_validate(&wrap_with_runtime_i32("(entity-type IDX)"));
fn entity_parent_idx_with_runtime_idx() {
compile_and_validate(&wrap_with_runtime_i32("(entity-parent-idx IDX)"));
fn transaction_split_count() {
compile_and_validate(&wrap_with_runtime_i32("(transaction-split-count IDX)"));
fn transaction_tag_count() {
compile_and_validate(&wrap_with_runtime_i32("(transaction-tag-count IDX)"));
fn transaction_is_multi_currency() {
compile_and_validate(&wrap_with_runtime_i32(
"(transaction-is-multi-currency IDX)",
));
fn transaction_post_date() {
compile_and_validate(&wrap_with_runtime_i32("(transaction-post-date IDX)"));
fn transaction_enter_date() {
compile_and_validate(&wrap_with_runtime_i32("(transaction-enter-date IDX)"));
fn split_value_num() {
compile_and_validate(&wrap_with_runtime_i32("(split-value-num IDX)"));
fn split_value_denom() {
compile_and_validate(&wrap_with_runtime_i32("(split-value-denom IDX)"));
fn split_value() {
compile_and_validate(&wrap_with_runtime_i32("(split-value IDX)"));
fn split_reconcile_state() {
compile_and_validate(&wrap_with_runtime_i32("(split-reconcile-state IDX)"));
fn split_reconcile_date() {
compile_and_validate(&wrap_with_runtime_i32("(split-reconcile-date IDX)"));
fn tag_name() {
compile_and_validate(&wrap_with_runtime_i32("(tag-name IDX)"));
fn tag_value() {
compile_and_validate(&wrap_with_runtime_i32("(tag-value IDX)"));
fn get_input_entities() {
compile_and_validate("(get-input-entities)");
fn create_tag_static() {
// create-tag args: (entity-idx, name, value).
compile_and_validate("(create-tag 0 \"my-tag\" \"value\")");
fn create_tag_runtime_idx() {
"(create-tag IDX \"my-tag\" \"value\")",
fn create_tag_runtime_name_routes_through_runtime_path() {
// Runtime-typed name forces compile_create_tag_runtime instead
// of the static layout-pack path. Exercises the alternate branch
// of the runtime/static decision in compile_create_tag.
compile_and_validate("(let* ((n (upcase-string \"my-tag\"))) (create-tag 0 n \"value\"))");
fn delete_entity_runtime_idx() {
compile_and_validate(&wrap_with_runtime_i32("(delete-entity IDX)"));
fn entity_constants_defined() {
let symbols = SymbolTable::with_builtins_for_wasm();
for name in [
"+ENTITY-TRANSACTION+",
"+ENTITY-SPLIT+",
"+ENTITY-TAG+",
"+ENTITY-ACCOUNT+",
"+ENTITY-COMMODITY+",
"+CONTEXT-CREATE+",
"+CONTEXT-UPDATE+",
"+CONTEXT-DELETE+",
"+CONTEXT-BATCH+",
] {
assert!(symbols.lookup(name).is_some(), "missing constant: {name}");