-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preserve newline following {@endtemplate}
.
#2289
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Tests | ||
|
||
Most of dartdoc's tests are large end-to-end tests which read real files in | ||
real packages, in the `testing/` directory. Unit tests exist in `test/unit/`. | ||
|
||
Many of the end-to-end test cases should be rewritten as unit tests. | ||
|
||
At some point, the distinction should flip, such that unit tests are generally | ||
located in `test/`, and end-to-end tests are found in a specific directory, or | ||
in files whose names signify the distinction. |
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
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 |
---|---|---|
@@ -0,0 +1,195 @@ | ||
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:io' show Directory; | ||
|
||
import 'package:dartdoc/src/dartdoc_options.dart'; | ||
import 'package:dartdoc/src/model/model.dart'; | ||
import 'package:dartdoc/src/package_meta.dart'; | ||
import 'package:dartdoc/src/warnings.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
_Processor processor; | ||
setUp(() { | ||
processor = _Processor(_FakeDartdocOptionContext()); | ||
processor.href = '/project/a.dart'; | ||
}); | ||
|
||
test('removes triple slashes', () async { | ||
var doc = await processor.processComment(''' | ||
/// Text. | ||
/// More text. | ||
'''); | ||
expect(doc, equals(''' | ||
Text. | ||
More text.''')); | ||
}); | ||
|
||
test('removes space after triple slashes', () async { | ||
var doc = await processor.processComment(''' | ||
/// Text. | ||
/// More text. | ||
'''); | ||
// TODO(srawlins): Actually, the three spaces before 'More' is perhaps not | ||
// the best fit. Should it only be two, to match the indent from the first | ||
// line's "Text"? | ||
expect(doc, equals(''' | ||
Text. | ||
More text.''')); | ||
}); | ||
|
||
test('leaves blank lines', () async { | ||
var doc = await processor.processComment(''' | ||
/// Text. | ||
/// | ||
/// More text. | ||
'''); | ||
expect(doc, equals(''' | ||
Text. | ||
|
||
More text.''')); | ||
}); | ||
|
||
test('processes @template', () async { | ||
var doc = await processor.processComment(''' | ||
/// Text. | ||
/// | ||
/// {@template abc} | ||
/// Template text. | ||
/// {@endtemplate} | ||
/// | ||
/// End text. | ||
'''); | ||
expect(doc, equals(''' | ||
Text. | ||
|
||
{@macro abc} | ||
|
||
End text.''')); | ||
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1); | ||
}); | ||
|
||
test('processes leading @template', () async { | ||
var doc = await processor.processComment(''' | ||
/// {@template abc} | ||
/// Template text. | ||
/// {@endtemplate} | ||
/// | ||
/// End text. | ||
'''); | ||
expect(doc, equals(''' | ||
{@macro abc} | ||
|
||
End text.''')); | ||
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1); | ||
}); | ||
|
||
test('processes trailing @template', () async { | ||
var doc = await processor.processComment(''' | ||
/// Text. | ||
/// | ||
/// {@template abc} | ||
/// Template text. | ||
/// {@endtemplate} | ||
'''); | ||
expect(doc, equals(''' | ||
Text. | ||
|
||
{@macro abc}''')); | ||
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1); | ||
}); | ||
|
||
test('processes @template w/o blank line following', () async { | ||
var doc = await processor.processComment(''' | ||
/// Text. | ||
/// | ||
/// {@template abc} | ||
/// Template text. | ||
/// {@endtemplate} | ||
/// End text. | ||
'''); | ||
expect(doc, equals(''' | ||
Text. | ||
|
||
{@macro abc} | ||
End text.''')); | ||
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1); | ||
}); | ||
|
||
test('allows whitespace around @template name', () async { | ||
var doc = await processor.processComment(''' | ||
/// {@template abc } | ||
/// Template text. | ||
/// {@endtemplate} | ||
'''); | ||
expect(doc, equals(''' | ||
{@macro abc}''')); | ||
verify(processor.packageGraph.addMacro('abc', 'Template text.')).called(1); | ||
}); | ||
|
||
// TODO(srawlins): More unit tests: @example, @youtube, @animation, | ||
// @inject-html, @tool. | ||
} | ||
|
||
/// In order to mix in [CommentProcessable], we must first implement | ||
/// the super-class constraints. | ||
abstract class __Processor extends Fake | ||
implements Documentable, Warnable, Locatable, SourceCodeMixin {} | ||
|
||
/// A simple comment processor for testing [CommentProcessable]. | ||
class _Processor extends __Processor with CommentProcessable { | ||
@override | ||
final _FakeDartdocOptionContext config; | ||
|
||
@override | ||
final _FakePackage package; | ||
|
||
@override | ||
final _MockPackageGraph packageGraph; | ||
|
||
@override | ||
String href; | ||
|
||
_Processor(this.config) | ||
: package = _FakePackage(), | ||
packageGraph = _MockPackageGraph() { | ||
throwOnMissingStub(packageGraph); | ||
when(packageGraph.addMacro(any, any)).thenReturn(null); | ||
} | ||
} | ||
|
||
class _FakeDirectory extends Fake implements Directory { | ||
@override | ||
final String path; | ||
|
||
_FakeDirectory() : path = '/project'; | ||
} | ||
|
||
class _FakePackage extends Fake implements Package { | ||
@override | ||
final PackageMeta packageMeta; | ||
|
||
_FakePackage() : packageMeta = _FakePackageMeta(); | ||
} | ||
|
||
class _FakePackageMeta extends Fake implements PackageMeta { | ||
@override | ||
final Directory dir; | ||
|
||
_FakePackageMeta() : dir = _FakeDirectory(); | ||
} | ||
|
||
class _FakeDartdocOptionContext extends Fake implements DartdocOptionContext { | ||
@override | ||
final bool allowTools; | ||
|
||
@override | ||
final bool injectHtml; | ||
|
||
_FakeDartdocOptionContext({this.allowTools = false, this.injectHtml = false}); | ||
} | ||
|
||
class _MockPackageGraph extends Mock implements PackageGraph {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: copyright