Lines
100 %
Functions
Branches
use super::*;
#[tokio::test]
async fn false_bool_in_an_anyref_slot_is_nil() {
for form in [
"(null? (car (cdr (if (> (rpc-protocol-version) 0) (list t nil) (list 1 2)))))",
"(null? (car (cdr (handler-case (list (> (rpc-protocol-version) 0) nil) \
(t (e) (list 1/2 (index->scalar (rpc-protocol-version))))))))",
"(null? (car (if (> (rpc-protocol-version) 0) \
(list nil (> (rpc-protocol-version) 0)) (list \"a\" (rpc-protocol-version)))))",
"(null? (car (cons (> (rpc-protocol-version) 5) (list \"a\"))))",
"(null? (car (fold (lambda (acc x) (cons x acc)) '(\"a\") \
(list (> (rpc-protocol-version) 5)))))",
"(null? (if (> (rpc-protocol-version) 0) (> (rpc-protocol-version) 5) \"s\"))",
"(null? (car (cdr (append (list (> (rpc-protocol-version) 0) nil) \
(list (rpc-protocol-version))))))",
] {
assert_values(&[(form, "t")]).await;
}
assert_values(&[(
"(null? (car (cons (> (rpc-protocol-version) 0) (list \"a\"))))",
"nil",
)])
.await;
async fn index_result_beyond_i31_crosses_the_eval_boundary_exactly() {
assert_values(&[
(
"(handler-case (* 1073741824 (rpc-protocol-version)) (index-overflow (e) -1))",
"1073741824",
),
("2000000000", "2000000000"),
"(if (> (rpc-protocol-version) 0) 2000000000 0)",
"2000000000",
("(- -2147483647 (rpc-protocol-version))", "-2147483648"),
])
async fn car_and_cdr_of_a_runtime_null_pair_never_trap() {
"(car (if (< (rpc-protocol-version) 0) (list \"a\") nil))",
"(car (if (< (rpc-protocol-version) 0) (list t) nil))",
"(car (if (> (rpc-protocol-version) 0) \
(if (> (rpc-protocol-version) 1) (list \"a\") nil) (list \"b\" \"c\")))",
"(cdr (if (< (rpc-protocol-version) 0) (list 1) nil))",
"(handler-case (car (cdr (list (rpc-protocol-version)))) (car-of-nil (e) -1))",
"-1",
assert_error_code("(car (cdr (list (rpc-protocol-version))))", "CAR-OF-NIL").await;
assert_error_code(
"(car (if (< (rpc-protocol-version) 0) (list 1) nil))",
"CAR-OF-NIL",
)
// A scalar or money value is never nil either, so an empty numeric list
// has no car. The untaken branch never calls the DB-backed host fn.
"(+ (car (if (< (rpc-protocol-version) 0) (list 1/2) nil)) 1)",
"(car (if (< (rpc-protocol-version) 0) (list (account-balance \"cash\")) nil))",
"(handler-case (car (if (< (rpc-protocol-version) 0) (list 1/2) nil)) \
(car-of-nil (e) 7))",
"7",
async fn filter_and_do_treat_a_runtime_index_as_true() {
("(filter (lambda (x) (* 0 x)) (list 1 2))", "\"(1 2)\""),
"(filter (lambda (x) (* 0 x)) (list 1 (rpc-protocol-version)))",
"\"(1 1)\"",
"(let ((n 0)) (do ((i (* 0 (rpc-protocol-version)) (+ i 1))) (i n) \
(setf n (+ n (rpc-protocol-version)))))",
"0",
async fn handler_case_reconciles_an_anyref_body_with_literal_and_nil_arms() {
"(handler-case (if (> (rpc-protocol-version) 0) (rpc-protocol-version)) (t (e) 0))",
"\"<anyref>\"",
let response = eval_value_of("(handler-case (rpc-protocol-version) (t (e) nil))").await;
assert!(
response.contains("HANDLER-CASE: a nil arm cannot join a i32 result"),
"got: {response}"
);
async fn fractional_literal_never_crosses_into_an_index_arm() {
"(if (> (rpc-protocol-version) 0) (rpc-protocol-version) 1/2)",
"(if (> (rpc-protocol-version) 0) (if (> (rpc-protocol-version) 1) 1 2) 1/2)",
"(if (> (rpc-protocol-version) 0) (index->scalar (rpc-protocol-version)) 1/2)",
"1",
let response = eval_value_of("(handler-case (rpc-protocol-version) (t (e) 1/2))").await;
response.contains("conflicting result types i32 and ratio"),
async fn a_runtime_index_is_never_nil() {
("(null? (* 0 (rpc-protocol-version)))", "nil"),
("(not (* 0 (rpc-protocol-version)))", "nil"),
("(if (* 0 (rpc-protocol-version)) 1 2)", "1"),
("(if (< (rpc-protocol-version) 0) 5)", "nil"),
("(null? (if (> (rpc-protocol-version) 0) 5))", "nil"),
("(null? (> (rpc-protocol-version) 5))", "t"),
"(and (* 0 (rpc-protocol-version)) (> (rpc-protocol-version) 0))",
"t",
"(or (* 0 (rpc-protocol-version)) (> (rpc-protocol-version) 5))",
async fn constant_list_arms_materialize_as_chains() {
"(if (> (rpc-protocol-version) 0) '(1 2) '(\"a\"))",
"\"(<anyref> <anyref>)\"",
"(let ((xs (list 1 2))) (if (> (rpc-protocol-version) 0) xs nil))",
"\"(1 2)\"",
"(let ((xs '(1 2))) (handler-case xs (t (e) nil)))",
"(let ((xs '(1 2))) (car (if (> (rpc-protocol-version) 0) xs \
(list (rpc-protocol-version)))))",
async fn nil_arm_after_runtime_effects_reconciles() {
"(let ((n 0)) (handler-case (begin (setf n (rpc-protocol-version)) nil) \
(t (e) (list 1))) n)",
async fn map_applies_a_quoted_defun_over_a_runtime_list() {
for head in ["map", "mapcar"] {
&format!("(begin (defun g2 (x) (+ x 1)) ({head} 'g2 (list (rpc-protocol-version))))"),
"\"(2)\"",