//
// 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.
//
/**
* Number Tests.
*/
import './numbers/ops' as Numbers.Operations;
import './numbers/units' as Numbers.Units;
import './numbers/std' as Numbers.StdLib;
import './numbers/iteration' as Numbers.Iteration;
/**
* String Tests.
*/
import './strings/std' as Strings.StdLib;
import './strings/iteration' as Strings.Iteration;
import './strings/escaped' as Strings.Escaped;
/**
* Function Tests.
*/
import './functions/decorators' as Functions.Decorators;
import './functions/arrows' as Functions.Arrows;
import './functions/std' as Functions.StdLib;
/**
* Array Tests.
*/
import './arrays/iteration' as Arrays.Iteration;
import './arrays/lib' as Arrays.StdLib;
import './arrays/fields' as Arrays.Fields;
/**
* Tuple Tests.
*/
import './tuples/casting' as Tuples.Casting;
/**
* Map Tests.
*/
import './maps/lib' as Maps.StdLib;
/**
* Set Tests.
*/
import './sets/lib' as Sets.StdLib;
/**
* Blob Tests.
*/
import './blobs/lib' as Blobs.StdLib;
/**
* Opaque Data.
*/
import './data/lib' as OpaqueData.StdLib;
/**
* Object Tests.
*/
import './objects/paths' as Objects.Paths;
import './objects/lib' as Objects.StdLib;
import './objects/schemafy' as Objects.Schemafy;
import './objects/exec' as Objects.Exec;
/**
* Field Tests.
*/
import './fields/attributes' as Fields.Attributes;
/**
* Dec Types Tests.
*/
import './types/geometry' as Types.Geometry;
import './types/casting' as Types.Casting;
import './types/attributes' as Types.Attributes;
import './types/unknown' as Types.Unknown;
import './types/optional_fields' as Types.Optional;
import './types/static' as Types.Static;
/**
* Control Flow Tests.
*/
import './control/flow' as Control.Flow;
import './control/switch' as Control.Switch;
import './control/try' as Control.Try;
/**
* Language Tests.
*/
import './language/shorts' as Language.ShortCircuits;
import './language/boxed' as Language.Boxed;
import './language/null' as Language.Null;
import './language/drop' as Language.Drop;
import './language/ranges' as Language.Ranges;
import './language/trace' as Language.Trace;
import './language/ternary' as Language.Ternary;
import './language/typeof' as Language.TypeOf;
/**
* Import Tests.
*/
import './imports/location' as Imports.Location;
import './imports/package' as Imports.Package;
import './imports/pkg_import' as Imports.PkgImport;
/**
* Format Tests.
*/
import './formats/json' as Formats.JSON;
import './formats/toml' as Formats.TOML;
import './formats/yaml' as Formats.YAML;
import './formats/xml' as Formats.XML;
import './formats/text' as Formats.TEXT;
import './formats/bytes' as Formats.BYTES;
import './formats/url' as Formats.URL;
import './formats/bstof' as Formats.BSTOF;
/**
* Practical Tests.
*/
import './practical/merge' as Practical.Merge;
import './practical/docs' as Practical.Docs;
/**
* System Library Tests.
*/
import './system/time' as System.Time;
/**
* Init test.
* Functions with the 'init' attribute get executed at the end of everything being parsed.
* If they have an expr, that expr will be executed and passed in as a parameter.
*/
init: {
#[init]
fn some_init() {
self.initialized = true;
}
fn initParam(): int { return 20; }
#[init(self.initParam())]
fn param_init(param: int) {
self.param = param;
}
#[test]
fn initialized() {
assert(self.initialized);
assertEq(self.param, 20);
}
}
/**
* Standard Library Tests.
* These functions can always be found in Stof documents in the 'std' library.
*/
stdlib: {
parse: {
#[test]
fn std_parse() {
// Parses 'myfield' into self with a value of true
parse('myfield: true', 'stof', 'self');
assertEq(self.myfield, true);
}
}
blobify: {
exfield: 'hello'
#[test]
fn std_blobify() {
let blb: blob = blobify(self, 'json');
std.parse(blb, 'json', 'self.parsed');
assertEq(self.parsed.exfield, 'hello');
}
}
stringify: {
exfield: 'hello'
#[test]
fn std_stringify() {
let json: str = stringify(self, 'json');
parse(json, 'json', 'self.parsed');
assertEq(self.parsed.exfield, 'hello');
}
}
#[test]
fn has_format() {
assert(hasFormat('json'));
}
#[test]
fn formats() {
assert(formats().len() > 1);
assert(formats().has('json'));
let toml = if formats().has('toml') ? 'yup' : 'nope';
assertEq(toml, 'yup');
}
#[test]
fn has_lib() {
assert(hasLib('Number'));
assert(hasLibrary('Array'));
}
#[test]
fn libraries() {
assert(libraries().len() > 1);
}
#[test]
fn println() {
pln('pln exists'); // If no error, then the func exists...
}
#[test]
fn dbgln() {
dbg('dbg exists');
}
#[test]
fn error() {
err('err exists');
}
#[test]
#[errors]
fn throw() {
throw('This is supposed to throw an error');
}
#[test]
fn assert() {
assert(true);
}
#[test]
#[errors]
fn assert_errors() {
assert(0); // 0 is falsy
}
#[test]
fn assert_not() {
assertNot(false);
}
#[test]
#[errors]
fn assert_not_errors() {
assertNot(true);
}
#[test]
fn assert_null() {
assertNull(null);
}
#[test]
#[errors]
fn assert_null_errors() {
assertNull(true);
}
#[test]
fn assert_obj() {
assertObject(self);
}
#[test]
#[errors]
fn assert_obj_errors() {
assertObject(32);
}
#[test]
fn assert_array() {
assertArray([3, 3]);
}
#[test]
#[errors]
fn assert_array_errors() {
assertArray(32);
}
#[test]
fn assert_tuple() {
assertTuple((1, 2));
}
#[test]
#[errors]
fn assert_tuple_errors() {
assertTuple(new {});
}
#[test]
fn assert_number() {
assertNumber(3);
}
#[test]
#[errors]
fn assert_number_errors() {
assertNumber(false);
}
#[test]
fn assert_eq() {
assertEq(3, 3);
}
#[test]
#[errors]
fn assert_eq_errors() {
assertEq(3, 4);
}
#[test]
fn assert_neq() {
assertNeq(3, 4);
}
#[test]
#[errors]
fn assert_neq_errors() {
assertNeq(4, 4);
}
#[test]
fn nanoid() {
let id = nanoid();
assertEq(id.len(), 21);
}
#[test]
fn nanoid_len() {
let id = nanoid(12);
assertEq(id.len(), 12);
}
#[test]
fn is_number() {
assert(isNumber(32));
assert(isNumber(32.23));
assert(isNumber(32km));
assert(isNumber(box(32)));
assert(isNumber(box(32.2)));
assert(isNumber(box(32km)));
assertNot(isNumber(true));
}
#[test]
fn is_object() {
let object = new {};
assert(isObject(object));
assert(isObject(box(object)));
assertNot(isObject(true));
}
#[test]
fn is_null() {
assert(isNull(null));
assertNot(isNull(32));
}
#[test]
fn is_string() {
assert(isString('hi'));
assert(isString(box('hi')));
assertNot(isString(32));
}
#[test]
fn is_bool() {
assert(isBool(true));
assert(isBool(false));
assert(isBool(box(true)));
assertNot(isBool(32));
}
#[test]
fn isMap() {
assert(isMap(map()));
assert(isMap(box(map())));
assertNot(isMap(32));
}
#[test]
fn is_set() {
assert(isSet(set()));
assert(isSet(box(set())));
assertNot(isSet(32));
}
#[test]
fn is_blob() {
let b = 'hi' as blob;
assert(isBlob(b));
assert(isBlob(box(b)));
assertNot(isBlob(32));
}
#[test]
fn is_vec() {
assert(isVec([1, 2]));
assert(isVec(box([1, 2])));
assert(isArray([1, 2]));
assert(isArray(box([1, 2])));
assertNot(isVec('hi'));
}
#[test]
fn is_func() {
assert(isFunc(() => {}));
assert(isFunc(box(() => {})));
assertNot(isFunc(32));
}
#[test]
fn is_boxed() {
assert(isBox(box(32)));
assert(isBoxed(box(32)));
assertNot(isBox(32));
assertNot(isBoxed(32));
}
}