-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add unit test file generator and imporve performance
- Loading branch information
Showing
5 changed files
with
137 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,6 @@ | ||
## 0.1.1 (2023-10-06) | ||
## 0.1.2 (2023-10-07) | ||
|
||
### Added | ||
|
||
- Add `example` folder | ||
- update docs intruction | ||
|
||
### Fixed | ||
|
||
- None. | ||
|
||
### Changed | ||
|
||
- None. | ||
|
||
### Deprecated | ||
|
||
- None. | ||
|
||
### Removed | ||
|
||
- None. | ||
- Improve documentation and performance | ||
- Add unit test generate file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,39 @@ | ||
import 'dart:io'; | ||
|
||
/// Generates a file with the given [name]. | ||
/// Method to generate a file | ||
void generateFile(String name) { | ||
File fileName = File('$name/$name.dart'); | ||
// Create a File object with the given name and path | ||
File fileName = File('$name/index.dart'); | ||
|
||
// Initialize a variable to store the content of the file | ||
String content = ""; | ||
|
||
// Check the value of the name parameter using a switch statement | ||
switch (name) { | ||
// If name is 'app', set the content variable with specific comments | ||
case 'app': | ||
content = | ||
"// export 'repository/name_file.dart';\n// export 'modules/name_file.dart';\n// export 'data/name_file.dart';"; | ||
break; | ||
|
||
// For any other name, set the content variable with a generic comment | ||
default: | ||
content = "// export 'file_name.dart' "; | ||
} | ||
|
||
// Check if the file already exists | ||
if (!fileName.existsSync()) { | ||
var content = "// export '${fileName.path}' "; | ||
fileName.createSync(); | ||
// If the file doesn't exist, create it and its parent directories | ||
fileName.createSync(recursive: true); | ||
|
||
// Write the content to the file | ||
fileName.writeAsStringSync(content); | ||
|
||
// Print a success message | ||
print('File $fileName created successfully'); | ||
} else { | ||
print('File $fileName already exits'); | ||
// If the file already exists, print a message | ||
print('File $fileName already exists'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,50 @@ | ||
import 'dart:io'; | ||
|
||
import 'package:init_folder_architecture/files.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
test('calculate', () { | ||
// expect(calculate(), 42); | ||
// Group of unit tests for generating a file | ||
group('unit test generate file', () { | ||
// Test case: create a new file successfully | ||
test('generateFile create a new file successfully', () { | ||
// Create a test directory | ||
final directoryName = 'test_directory'; | ||
|
||
// Create a file path within the test directory | ||
final fileName = '$directoryName/$directoryName.dart'; | ||
|
||
// Create the file | ||
File(fileName).createSync(recursive: true); | ||
|
||
// Insert file content | ||
File(fileName).writeAsStringSync("// export '$fileName' "); | ||
|
||
// Create the test directory | ||
Directory(directoryName).createSync(recursive: true); | ||
|
||
// Call the generateFile function | ||
generateFile(directoryName); | ||
|
||
// Assert that the file exists | ||
expect(File(fileName).existsSync(), isTrue); | ||
}); | ||
|
||
// Test case: prints a message if the file already exists | ||
test('generateFile prints a message if the file already exists', () async { | ||
// Set up test data | ||
final directoryName = 'test_directory'; | ||
final fileName = '$directoryName/$directoryName.dart'; | ||
|
||
// Create the file and directory | ||
File(fileName).createSync(recursive: true); | ||
|
||
// Call the method being tested | ||
generateFile(directoryName); | ||
|
||
// Check if the file contains the expected message | ||
expect(await File(fileName).readAsString(), | ||
contains("// export '$fileName' ")); | ||
}); | ||
}); | ||
} |