59 lines
1.8 KiB
Dart
59 lines
1.8 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:swagger_generator_flutter/core/config.dart';
|
|
import 'package:swagger_generator_flutter/core/config_repository.dart';
|
|
import 'package:swagger_generator_flutter/utils/string_helper.dart';
|
|
|
|
void main() {
|
|
final configFile = File('generator_config.yaml');
|
|
final resultFile = File('test_result.txt');
|
|
|
|
try {
|
|
// 1. Setup config file
|
|
configFile.writeAsStringSync('''
|
|
generator:
|
|
name: test
|
|
output:
|
|
models:
|
|
class_prefix: "MyPrefix"
|
|
generation:
|
|
models:
|
|
class_prefix: "MyPrefix"
|
|
''');
|
|
|
|
// 2. Test direct ConfigRepository load
|
|
final config = ConfigRepository.loadSync('generator_config.yaml');
|
|
if (config.modelClassPrefix != 'MyPrefix') {
|
|
throw 'ConfigRepository failed to PARSE prefix. Got: ${config.modelClassPrefix}';
|
|
}
|
|
|
|
// 3. Test SwaggerConfig (static access)
|
|
// Note: ConfigRepository.loadSync() tries to find config file.
|
|
// Since we created generator_config.yaml in CWD, and PathResolver likely checks CWD, this matches.
|
|
if (SwaggerConfig.modelClassPrefix != 'MyPrefix') {
|
|
throw 'SwaggerConfig failed to READ prefix. Got: ${SwaggerConfig.modelClassPrefix}';
|
|
}
|
|
|
|
// 4. Test StringHelper
|
|
final className = StringHelper.generateClassName('User');
|
|
if (className != 'MyPrefixUser') {
|
|
throw 'StringHelper failed to APPLY prefix. Got: $className';
|
|
}
|
|
|
|
// 5. Test Prefix Avoidance (Idempotency)
|
|
final className2 = StringHelper.generateClassName('MyPrefixUser');
|
|
if (className2 != 'MyPrefixUser') {
|
|
throw 'StringHelper double-prefixed. Got: $className2';
|
|
}
|
|
|
|
resultFile.writeAsStringSync('PASS');
|
|
print('Verification Passed');
|
|
} catch (e, stack) {
|
|
resultFile.writeAsStringSync('FAIL: $e\n$stack');
|
|
print('Verification Failed: $e');
|
|
} finally {
|
|
// Cleanup
|
|
if (configFile.existsSync()) configFile.deleteSync();
|
|
}
|
|
}
|