[code_builder] Expand code coverage#2409
Conversation
1. **`TypeReference` (100.0% Coverage)** in `test/specs/type_reference_test.dart`:
* Added test for **generic bounds formatting** (e.g., `T extends num`).
* Added robust tests for **`newInstance`**, **`newInstanceNamed`**, **`constInstance`**, and **`constInstanceNamed`** constructor calls.
* Added tests ensuring that AST property bindings (`url`, `symbol`, and `type`) are correctly exposed.
2. **`RecordType` (100.0% Coverage)** in `test/specs/record_type_test.dart`:
* Added API contract tests to verify that calling instantiation methods (`newInstance`, `newInstanceNamed`, `constInstance`, `constInstanceNamed`) correctly throws `UnsupportedError` as record types cannot be directly instantiated as objects.
* Ensured standard properties (`url` and `symbol` returning null, `type` returning self) are fully asserted.
3. **`FunctionType` (100.0% Coverage)** in `test/specs/function_type_test.dart` (New File):
* Created a dedicated test suite validating all properties and instantiation restrictions.
* Added targeted verification of the **`toTypeDef`** AST conversion utility, ensuring it generates perfect typedef structures (e.g., `typedef MyFunc = String Function(int);`).
---
| File | Original Coverage | New Coverage | Hit Lines / Total Lines |
| :--- | :---: | :---: | :---: |
| `lib/src/specs/type_reference.dart` | 29.4% | **100.0%** 🚀 | 17 / 17 |
| `lib/src/specs/type_record.dart` | 26.7% | **100.0%** 🚀 | 15 / 15 |
| `lib/src/specs/type_function.dart` | 37.5% | **100.0%** 🚀 | 16 / 16 |
Package publishing
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
PR HealthLicense Headers ✔️
All source files should start with a license header. Unrelated files missing license headers
This check can be disabled by tagging the PR with Breaking changes ✔️
This check can be disabled by tagging the PR with Coverage ✔️
This check for test coverage is informational (issues shown here will not fail the PR). This check can be disabled by tagging the PR with API leaks ✔️The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.
This check can be disabled by tagging the PR with Unused Dependencies ✔️
For details on how to fix these, see dependency_validator. This check can be disabled by tagging the PR with Changelog Entry ✔️
Changes to files need to be accounted for in their respective changelogs. This check can be disabled by tagging the PR with |
There was a problem hiding this comment.
Code Review
This pull request introduces comprehensive unit tests for FunctionType, RecordType, and TypeReference to verify their API contracts and code generation capabilities. The feedback suggests using .add() instead of .addAll() for single elements to be more idiomatic, refactoring redundant variable declarations in tests to improve maintainability, and expanding test coverage to include typeArguments while utilizing raw strings for better readability in expectations.
TypeReference(100.0% Coverage) intest/specs/type_reference_test.dart:T extends num).newInstance,newInstanceNamed,constInstance, andconstInstanceNamedconstructor calls.url,symbol, andtype) are correctly exposed.RecordType(100.0% Coverage) intest/specs/record_type_test.dart:newInstance,newInstanceNamed,constInstance,constInstanceNamed) correctly throwsUnsupportedErroras record types cannot be directly instantiated as objects.urlandsymbolreturning null,typereturning self) are fully asserted.FunctionType(100.0% Coverage) intest/specs/function_type_test.dart(New File):toTypeDefAST conversion utility, ensuring it generates perfect typedef structures (e.g.,typedef MyFunc = String Function(int);).lib/src/specs/type_reference.dartlib/src/specs/type_record.dartlib/src/specs/type_function.dart