void repro_source_after_append_code() { Branch branch; Term* target = branch.compile("target = {}"); branch.eval("bm = branch_ref(target)"); branch.eval("bm.append_code({ 1 + 1 })"); test_equals(get_branch_source_text(nested_contents(target)), " 1 + 1 "); }
void test_if_joining_on_bool() { // The following code once had a bug where cond wouldn't work // if one of its inputs was missing value. Branch branch; caValue* s = branch.eval("hey = true"); test_assert(s->value_data.ptr != NULL); branch.eval("if false { hey = false }"); evaluate_branch(&branch); test_assert(branch["hey"]->asBool() == true); }
void test_if_joining() { Branch branch; // Test that a name defined in one branch is not rebound in outer scope branch.eval("if true { apple = 5 }"); test_assert(!branch.contains("apple")); // Test that a name which exists in the outer scope is rebound Term* original_banana = create_int(&branch, 10, "banana"); branch.eval("if true { banana = 15 }"); test_assert(branch["banana"] != original_banana); // Test that if a name is defined in both 'if' and 'else' branches, that it gets // defined in the outer scope. branch.eval("if true { Cardiff = 5 } else { Cardiff = 11 }"); test_assert(branch.contains("Cardiff")); // Test that the type of the joined name is correct branch.compile("if true { a = 4 } else { a = 5 }; a = a"); test_equals(get_output_type(branch["a"])->name, "int"); }