//
// 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.
//
values: {
int_int: {
int stof_field: 20
int json_field: 20
int yaml_field: 20
int xml_field: 20
int url_field: 20
int toml_field: 20
#[test]
fn collide_stof_ints() {
let stof = '
int stof_field: 40
';
parse(stof, 'stof', 'self');
assertEq(self.stof_field, [20, 40]);
}
#[test]
fn collide_json_ints() {
let json = '
{
"json_field": 40
}';
parse(json, 'json', 'self');
assertEq(self.json_field, [20, 40]);
}
#[test]
fn collide_yaml_ints() {
let yaml = '
yaml_field: 40
';
parse(yaml, 'yaml', 'self');
assertEq(self.yaml_field, [20, 40]);
}
#[test]
fn collide_xml_ints() {
let xml = '<xml_field>40</xml_field>';
parse(xml, 'xml', 'self');
assertEq(self.xml_field, [20, '40']);
}
#[test]
fn collide_uml_ints() {
let url = 'url_field=40';
parse(url, 'urlencoded', 'self');
assertEq(self.url_field, [20, 40]);
}
#[test]
fn collide_toml_ints() {
let toml = 'toml_field = 40';
parse(toml, 'toml', 'self');
assertEq(self.toml_field, [20, 40]);
}
}
}
arrays: {
array_value: {
field: ['hi', true, { child: true }, 'hello']
#[test]
fn collision() {
let stof = 'field: 50';
parse(stof, 'stof', 'self');
assertEq(self.field.at(4), 50);
}
}
array_obj: {
field: ['hi', true, { child: true }, 'hello']
#[test]
fn collision() {
let stof = 'field: { added: true }';
parse(stof, 'stof', 'self');
let obj = self.field.at(4);
assertEq(obj.added, true);
}
}
}
objects: {
obj_obj: {
field: { first: true }
#[test]
fn collision() {
let stof = 'field: { second: true }';
parse(stof, 'stof', 'self');
let str = stringify(self, 'json');
assertEq(str, '{"field":[{"first":true},{"second":true}]}');
}
}
obj_array: {
field: { first: true }
#[test]
fn collision() {
let stof = 'field: ["hi", 42]';
parse(stof, 'stof', 'self');
let str = stringify(self, 'json');
assertEq(str, '{"field":[{"first":true},"hi",42]}');
}
}
obj_value: {
field: { first: true }
#[test]
fn collision() {
let stof = 'field: 42';
parse(stof, 'stof', 'self');
let str = stringify(self, 'json');
assertEq(str, '{"field":[{"first":true},42]}');
}
}
}
override: {
#[merge('override')]
value: 10
other: 10
#[test]
fn value_overridden() {
let stof = 'value: 42';
parse(stof, 'stof', 'self');
assertEq(self.value, 42);
}
#[test]
fn other_overridden() {
let stof = '#[merge("override")] other: 42';
parse(stof, 'stof', 'self');
assertEq(self.other, 42);
}
}
none: {
#[merge('none')]
value: 10
other: 10
#[test]
fn value_overridden() {
let stof = 'value: 42';
parse(stof, 'stof', 'self');
assertEq(self.value, 10);
}
#[test]
fn other_overridden() {
let stof = '#[merge("none")] other: 42';
parse(stof, 'stof', 'self');
assertEq(self.other, 10);
}
}
errors: {
#[merge('error')]
value: 10
other: 10
#[test]
#[errors]
fn value_overridde_error() {
let stof = 'value: 42';
parse(stof, 'stof', 'self');
}
#[test]
#[errors]
fn other_overridde_error() {
let stof = '#[merge("error")] other: 42';
parse(stof, 'stof', 'self');
}
}