Skip to content

Commit

Permalink
Update build and test and fix parens issue
Browse files Browse the repository at this point in the history
  • Loading branch information
glesica committed Sep 11, 2022
1 parent ba4fd9c commit 08b11a2
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 43 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dcdg-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
check:
runs-on: ubuntu-20.04
container:
image: glesica/dcdg_build
image: google/dart:2.14
volumes:
- ${{ github.workspace }}:/code
steps:
Expand All @@ -16,7 +16,7 @@ jobs:
check-format:
runs-on: ubuntu-20.04
container:
image: glesica/dcdg_build
image: google/dart:2.14
volumes:
- ${{ github.workspace }}:/code
steps:
Expand Down
30 changes: 0 additions & 30 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions lib/src/builders/mermaid_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:dcdg/src/builders/diagram_builder.dart';
import 'package:dcdg/src/type_name.dart';
import 'package:dcdg/src/type_namespace.dart';

/*
TODO: Build the diagrams in the functional tests to verify that
we're generating valid markup for the given builder.
TODO: Consider adding a field to DiagramBuilder that knows how
to invoke the relevant compiler to produce an image
FIXME: Fields with a function type appear as methods because the
type ends with ()
*/

class MermaidBuilder implements DiagramBuilder {
Expand All @@ -36,7 +32,12 @@ class MermaidBuilder implements DiagramBuilder {
final staticSuffix = element.isStatic ? '\$' : '';
final abstractSuffix = element.isAbstract ? '*' : '';
final name = element.name;
final type = typeName(element, leftBracket: '~', rightBracket: '~');
final type = typeName(
element,
leftBracket: '~',
rightBracket: '~',
stripParens: true,
);
_lines.add(
'$_currentClass : $visibilityPrefix$name$staticSuffix$abstractSuffix $type');
}
Expand Down
10 changes: 7 additions & 3 deletions lib/src/type_namespace.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ import 'package:dcdg/src/constants.dart';

/// Build a namespace for the given element based on the definition
/// of its type.
String typeNamespace(final Element element,
{String separator = namespaceSeparator}) {
String typeNamespace(
final Element element, {
String separator = namespaceSeparator,
bool stripFileExtension = false,
}) {
var library = element.library;

// If we're building a has-a relationship then we get the
Expand All @@ -17,7 +20,8 @@ String typeNamespace(final Element element,

final namespace = library?.identifier
.replaceFirst('package:', '')
.replaceFirst('dart:', 'dart::')
.replaceFirst('dart:', 'dart$separator')
.replaceAll('.dart', stripFileExtension ? '' : '.dart')
.split('/')
.join(separator);
return '$namespace$separator';
Expand Down
17 changes: 17 additions & 0 deletions test/functional/aggregation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,22 @@ void main() {
expect(result.stdout, isNot(contains('[int]')));
expect(result.stdout, isNot(contains('[bool]')));
});

test('should include user-defined types and exclude core types in mermaid',
() {
final result = runWith(
[
'-b',
'mermaid',
],
'test/fixtures/aggregation/',
);
expect(result.stderr, '');
expect(result.exitCode, 0);
expect(result.stdout, contains('Bar o-- Foo0'));
expect(result.stdout, contains('Bar o-- Foo1'));
expect(result.stdout, isNot(contains('Bar o-- int')));
expect(result.stdout, isNot(contains('Bar o-- bool')));
});
});
}
18 changes: 18 additions & 0 deletions test/functional/success_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ void main() {
expect(result.stdout, contains('_PrivatePartInternalPartPrivate'));
});

test('should produce mermaid output', () {
final result = runWith(
[
'-b',
'mermaid',
],
'test/fixtures/simple/',
);
expect(result.stderr, '');
expect(result.exitCode, 0);
expect(result.stdout, contains('PublicExternalPublic'));
expect(result.stdout, contains('_PrivateExternalPrivate'));
expect(result.stdout, contains('PublicInternalPublic'));
expect(result.stdout, contains('_PrivateInternalPrivate'));
expect(result.stdout, contains('PublicPartInternalPartPublic'));
expect(result.stdout, contains('_PrivatePartInternalPartPrivate'));
});

test('should not yield empty namespaces', () {
final result = runWith(
[
Expand Down
19 changes: 18 additions & 1 deletion test/unit/type_namespace_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void main() {
);
});

test('should convert a dart:core prefix to dart::core', () {
test('should convert a dart:core prefix to dart::core by default', () {
final library = FakeLibraryElement('dart:core/entry.dart');
final element = FakeElement('class', library);

Expand All @@ -37,6 +37,23 @@ void main() {
);
});

test('should convert a dart:core prefix to dart.core by with . separator',
() {
final library = FakeLibraryElement('dart:core/entry.dart');
final element = FakeElement('class', library);

final namespace = typeNamespace(element, separator: '.');
expect(
namespace,
[
'dart',
'core',
'entry.dart',
].join('.') +
'.',
);
});

test('should allow a custom namespace separator', () {
final library = FakeLibraryElement('package:pkg/entry.dart');
final element = FakeElement('class', library);
Expand Down
3 changes: 2 additions & 1 deletion tool/binary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ set -e

mkdir -p build/
PLATFORM=$(uname -s | tr '[:upper:]' '[:lower:]')
dart2native -o "build/dcdg-$PLATFORM" bin/dcdg.dart
dart pub get
dart compile exe -o "build/dcdg-$PLATFORM" bin/dcdg.dart
3 changes: 3 additions & 0 deletions tool/check-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

docker run --rm -v "$PWD":/code -w /code google/dart:2.14 ./tool/check.sh "$@"
1 change: 0 additions & 1 deletion tool/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@

dart pub get
dart run test -j 1 "$@"

1 change: 1 addition & 0 deletions tool/docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
awk '/version: / {print "const version = " "'\''" $2 "'\''" ";"}' pubspec.yaml > lib/src/version.dart

# Generate example outputs
dart pub get
dart run dcdg -o example/dcdg.puml --exclude-private=field,method
plantuml example/dcdg.puml

Expand Down
1 change: 1 addition & 0 deletions tool/format.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh

dart pub get
dart format --fix --set-exit-if-changed .

0 comments on commit 08b11a2

Please sign in to comment.