getValueUnitTest method
Implementation
String getValueUnitTest(
String key,
dynamic value,
String suffix,
String parent,
String asImport, [
String? parentList,
]) {
final variable = key.camelCase;
if (value is Map) {
final keys = value.keys;
final apiClassName = ModelClassNameHelper.getClassName(
listClassNameUnitTest,
suffix,
key.pascalCase,
false,
true,
parent,
parentList,
);
for (var e in keys) {
if (value[e] is Map) {
ModelClassNameHelper.getClassName(listClassNameUnitTest, suffix,
e.toString().pascalCase, false, false, apiClassName, parentList);
}
}
for (var e in keys) {
final list = value[e];
if (list is List && list.isNotEmpty && list.first is Map) {
ModelClassNameHelper.getClassName(listClassNameUnitTest, suffix,
e.toString().pascalCase, false, false, apiClassName, parentList);
}
}
return '$variable: $asImport.$apiClassName(${keys.map((e) => getValueUnitTest(e.toString(), value[e], suffix, apiClassName, asImport, parentList)).join(',')})';
}
if (value is List) {
if (value.isNotEmpty) {
if (value.first is Map) {
String list = '[';
final apiClassName = ModelClassNameHelper.getClassName(
listClassNameUnitTest,
suffix,
key.pascalCase,
false,
true,
parent,
parentList != null ? parentList + parent : parent,
);
final parentOfChild =
parentList != null ? parentList + apiClassName : apiClassName;
for (var e in value.first.keys) {
if (value.first[e] is Map) {
ModelClassNameHelper.getClassName(
listClassNameUnitTest,
suffix,
e.toString().pascalCase,
false,
false,
apiClassName,
parentOfChild,
);
}
}
for (var e in value.first.keys) {
final list = value.first[e];
if (list is List && list.isNotEmpty && list.first is Map) {
ModelClassNameHelper.getClassName(
listClassNameUnitTest,
suffix,
e.toString().pascalCase,
false,
false,
apiClassName,
parentOfChild,
);
}
}
for (var element in value) {
final item = element as Map;
final keys = item.keys;
list +=
'$asImport.$apiClassName(${keys.map((e) => getValueUnitTest(e.toString(), element[e], suffix, apiClassName, asImport, parentOfChild)).join(',')}),';
}
list += ']';
return '$variable: $list';
} else if (value.first is String) {
return '$variable: [${value.map((e) => "'$e'").join(',')}]';
} else {
return '$variable: [${value.join(',')}]';
}
} else {
return '$variable: []';
}
}
if (value is String) {
if (RegExp(r'^\d{4}-\d{2}-\d{2}(\s|T)?(\d{2}:\d{2}(:\d{2})?)?(\.\d+)?Z?$')
.hasMatch(value)) {
return '$variable: ${"DateTime.tryParse('$value')"}';
}
return "$variable: '$value'";
}
return '$variable: ${value.toString()}';
}