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.
//

add: {
    #[test(13)]
    fn add_ints(): int {
        return 5 + 8;
    }

    #[test(13.52)]
    fn add_floats(): float {
        return 5.3 + 8.22;
    }

    #[test(-6)]
    fn add_negative(): int {
        return -4 + -2;
    }
}

sub: {
    #[test(3)]
    fn subtract_ints(): int {
        return 8 - 5;
    }

    #[test(4.1)]
    fn subtract_floats(): float {
        return (9.3 - 5.2).round(1);
    }
}

mult: {
    #[test(6)]
    fn multiply_ints(): int {
        return 2 * 3;
    }

    #[test(4.0)]
    fn multipy_floats(): float {
        return 2.0 * 2.0;
    }
}

div: {
    #[test(5)]
    fn divide_ints(): int {
        return 10 / 2;
    }

    #[test(5.0)]
    fn divide_floats(): float {
        return 10.0 / 2.0;
    }
}

mod: {
    #[test(2)]
    fn mod_ints(): int {
        return 12 % 10;
    }

    #[test(2.0)]
    fn mod_floats(): float {
        return 12.0 % 10.0;
    }
}

calls: {
    fn add_two_func(a: int, b: int): int {
        return a + b;
    }

    #[test(6)]
    fn add_two(): int {
        return self.add_two_func(4, 2);
    }
}

order_of_ops: {
    #[test(2)]
    fn right_to_left_add_sub(): int {
        return 3 + 12 - 10 + 3 - 6;
    }

    #[test(30)]
    fn right_to_left_mul_div(): int {
        return 3 * 2 / 2 * 10;
    }

    #[test(10)]
    fn multiply_before_add(): int {
        return 4 + 2 * 3;
    }

    #[test(4)]
    fn multiply_before_sub(): int {
        return 10 - 3 * 2;
    }

    #[test(8)]
    fn divide_before_add(): int {
        return 3 * 2 + 4 / 2; 
    }

    #[test(6)]
    fn divide_before_sub(): int {
        return 2 * 4 - 4 / 2;
    }

    #[test(34)]
    fn mod_before_add(): int {
        return 2 * 10 + 14 % 16;
    }

    #[test(38)]
    fn mod_before_sub(): int {
        return 2 * 20 - 20 % 3;
    }

    #[test(5)]
    fn parans_priority(): int {
        return 2 * (4 + 4) / 3;
    }
}