fn test_methods()

in starlark/src/assert/assert.rs [142:198]


fn test_methods(builder: &mut GlobalsBuilder) {
    // Used by one of the test methods in Go
    const fibonacci: Vec<i32> = vec![0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89];

    // Approximate version of a method used by the Go test suite
    fn hasfields() -> anyhow::Result<Struct<'v>> {
        Ok(Struct::new(SmallMap::new()))
    }

    // Approximate version of a method used by the Go test suite
    fn set(xs: Value) -> anyhow::Result<Value<'v>> {
        Ok(xs)
    }

    fn assert_eq(a: Value, b: Value) -> anyhow::Result<NoneType> {
        assert_equals(a, b)
    }

    fn assert_ne(a: Value, b: Value) -> anyhow::Result<NoneType> {
        assert_different(a, b)
    }

    fn assert_lt(a: Value, b: Value) -> anyhow::Result<NoneType> {
        assert_less_than(a, b)
    }

    fn assert_true(a: Value) -> anyhow::Result<NoneType> {
        if !a.to_bool() {
            Err(anyhow!("assertion failed"))
        } else {
            Ok(NoneType)
        }
    }

    fn assert_false(a: Value) -> anyhow::Result<NoneType> {
        if a.to_bool() {
            Err(anyhow!("assertion failed"))
        } else {
            Ok(NoneType)
        }
    }

    // This is only safe to call at the top-level of a Starlark module
    fn garbage_collect() -> anyhow::Result<NoneType> {
        eval.trigger_gc();
        Ok(NoneType)
    }

    fn assert_type(v: Value, ty: Value) -> anyhow::Result<NoneType> {
        v.check_type(ty, Some("v"), heap)?;
        Ok(NoneType)
    }

    fn is_type(v: Value, ty: Value) -> anyhow::Result<bool> {
        v.is_type(ty, heap)
    }
}