当前位置: 首页>>代码示例>>C++>>正文


C++ Branch::contains方法代码示例

本文整理汇总了C++中Branch::contains方法的典型用法代码示例。如果您正苦于以下问题:C++ Branch::contains方法的具体用法?C++ Branch::contains怎么用?C++ Branch::contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Branch的用法示例。


在下文中一共展示了Branch::contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_if_elif_else

void test_if_elif_else()
{
    Branch branch;

    branch.compile("if true { a = 1 } elif true { a = 2 } else { a = 3 } a=a");
    evaluate_branch(&branch);

    test_assert(branch.contains("a"));
    test_equals(branch["a"]->asInt(), 1);

    branch.compile(
        "if false { b = 'apple' } elif false { b = 'orange' } else { b = 'pineapple' } b=b");
    evaluate_branch(&branch);
    test_assert(branch.contains("b"));
    test_assert(branch["b"]->asString() == "pineapple");

    // try one without 'else'
    branch.clear();
    branch.compile("c = 0");
    branch.compile("if false { c = 7 } elif true { c = 8 }; c=c");
    evaluate_branch(&branch);
    test_assert(branch.contains("c"));
    test_assert(branch["c"]->asInt() == 8);

    // try with some more complex conditions
    branch.clear();
    branch.compile("x = 5");
    branch.compile("if x > 6 { compare = 1 } elif x < 6 { compare = -1 } else { compare = 0}");
    branch.compile("compare=compare");
    evaluate_branch(&branch);

    test_assert(branch.contains("compare"));
    test_assert(branch["compare"]->asInt() == -1);
}
开发者ID:julianhaslinger,项目名称:circa,代码行数:34,代码来源:if_block_tests.cpp

示例2: test_dont_always_rebind_inner_names

void test_dont_always_rebind_inner_names()
{
    Branch branch;
    branch.compile("if false { b = 1 } elif false { c = 1 } elif false { d = 1 } else { e = 1 }");
    evaluate_branch(&branch);
    test_assert(!branch.contains("b"));
    test_assert(!branch.contains("c"));
    test_assert(!branch.contains("d"));
    test_assert(!branch.contains("e"));
}
开发者ID:julianhaslinger,项目名称:circa,代码行数:10,代码来源:if_block_tests.cpp

示例3: test_if_joining

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");
}
开发者ID:julianhaslinger,项目名称:circa,代码行数:22,代码来源:if_block_tests.cpp


注:本文中的Branch::contains方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。