//
// 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.
//
#[test]
fn null_or() {
let x = null;
x = or(x, 10);
assertEq(x, 10);
x = or(x, 20);
assertEq(x, 10);
}
#[test]
fn null_boxed_or(): void {
let x = box(null);
x = or(x, 10);
assertEq(x, 10);
x = or(x, 22);
assertEq(x, 10);
}
#[test]
fn null_or_many() {
let x = null;
let y = or(x, null, null, null, 10, 100);
assertEq(x, null);
assertEq(y, 10);
}
#[test]
fn number_or() {
let x = null;
x = x.or(null, 42, 10);
x = x.or(4);
assertEq(x, 42);
}
#[test]
fn bool_or() {
let x = null;
x = x.or(null, true, false);
x = x.or(true);
assert(x);
}
#[test]
fn str_or() {
let x = null;
x = x.or(null, 'hi');
x = x.or('ho');
assertEq(x, 'hi');
}
#[test]
fn array_or() {
let x = null;
x = x.or(null, [42, 10]);
x = x.or(['hi']);
assertEq(x, [42, 10]);
}
#[test]
fn blob_or() {
let x = null;
x = x.or(null, [111, 10] as blob);
x = x.or([11] as blob);
assertEq(x, [111, 10] as blob);
}
#[test]
fn fn_or() {
let x = null;
x = x.or(null, (): int => 42);
x = x.or(4);
assertEq(x.call(), 42);
}
#[test]
fn map_or() {
let x = null;
x = x.or(null, map([(42, 10)]));
x = x.or(4);
assertEq(x, map([(42, 10)]));
}
#[test]
fn obj_or() {
let x = null;
x = x.or(null, new { field: true });
x = x.or(4);
assertEq(x.field, true);
}
#[test]
fn set_or() {
let x = null;
x = x.or(null, set(42, 10));
x = x.or(4);
assertEq(x, set(42, 10));
}
#[test]
fn tuple_or() {
let x = null;
x = x.or(null, (42, 10));
x = x.or(4);
assertEq(x, (42, 10));
}
fn return_null(): unknown {
return null;
}
#[test]
fn practical_or() {
let x = self.return_null().or(null, 0, 10, 10, 23);
assertEq(x, 0);
}