stof 0.3.24

Stof is a unified data interface and interchange format for creating, sharing, and manipulating data. Stof removes the fragile and cumbersome parts of combining and using data in applications.
Documentation
//
// Copyright 2024 Formata, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//


fn test_function(a: float, b: float, c: float): float {
    return a * b / c;
}

#[test]
fn function_name() {
    let func = self.test_function;
    assertEq(func.name(), 'test_function');
}

#[test]
fn function_parameters() {
    let func = self.test_function;
    let params = func.parameters();
    assertEq(params, [('a', 'float'), ('b', 'float'), ('c', 'float')]);
}

#[test]
fn function_return_type() {
    let func = self.test_function;
    assertEq(func.returnType(), 'float');
}

#[test]
fn function_object() {
    let func = self.test_function;
    assertEq(func.object(), self);
}

#[test]
fn function_objects() {
    let func = box(self.test_function);
    assertEq(func.objects(), [self]);
}

#[test]
fn function_call() {
    let func = self.test_function;
    assertEq(func.call(1, 2, 2), 1);
}

#[test]
fn expand_call_array() {
    let func = self.test_function;
    let params = [1, 2, 2];
    assertEq(func.expandCall(params), 1);
}

#[test]
fn expand_call_tuple() {
    let func = self.test_function;
    let params = (1, 2, 2);
    assertEq(func.expandCall(params), 1);
}

#[test]
fn expand_call_set() {
    let func = self.test_function;
    let params = set(1, 2, 3);
    assert(func.expandCall(params) > 0);
}

attributes: {
    #[ordering(2)]
    #[hello]
    #[dude]
    fn attrs() {

    }

    #[test(['dude', 'hello', 'ordering'])]
    fn get_attrs(): vec {
        let attrs = Function.attributes(self.attrs);
        assertEq(attrs.values(), [null, null, 2]);
        return attrs.keys();
    }

    #[custom(2)]
    #[test]
    #[main22]
    fn main() {
        let attrs = self.main.attributes();
        assertEq(attrs.keys(), ["custom", "main22", "test"]);
    }

    #[test]
    fn has_attribute() {
        let func = self.attrs;
        assert(func.hasAttribute('dude'));
        assertNot(func.hasAttribute('dne'));
        assert(func.hasAttribute("ordering"));
    }
}