Skip to content
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

[dartdoc_test] add documentation samples analyzer #242

Merged
merged 23 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add new analyzer test
  • Loading branch information
takumma committed Jul 1, 2024
commit 381007dfa757d70489259e11f0612bbc66b93fad
23 changes: 12 additions & 11 deletions dartdoc_test/lib/src/analyzer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ void getAnalysisResult(
final result = await context.currentSession.getErrors(file.path);
if (result is ErrorsResult) {
for (final e in result.errors) {
print(e.toString());
final span = toOriginalFileSpanFromSampleError(file, e);
if (span != null) print(span.toString());
print(e.message);
// print(e.message);
}
}
}
Expand All @@ -49,14 +50,14 @@ FileSpan? toOriginalFileSpanFromSampleError(
return originSpan;
}

class AnalyzeResult {
final String filePath;
final FileSpan span;
final List<String> errors;

AnalyzeResult({
required this.filePath,
required this.span,
required this.errors,
});
// get original file span from sample file span
SourceSpan? getOriginalSubSpan({
required SourceSpan sample,
required SourceSpan original,
}) {
final offset = original.text.indexOf(sample.text);
if (offset == -1) {
return null;
}
return original.subspan(offset, offset + sample.length - 1);
}
54 changes: 54 additions & 0 deletions dartdoc_test/test/analyzer_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:dartdoc_test/src/analyzer.dart';
import 'package:source_span/source_span.dart';
import 'package:test/test.dart';

void main() {
group('getOriginalSubSpan', () {
test('should return SourceSpan if sample is found in original', () {
final sample = SourceSpan(
SourceLocation(5),
SourceLocation(11),
'main()',
);
final original = SourceSpan(
SourceLocation(20),
SourceLocation(38),
'/// void main() {}',
);
final result = getOriginalSubSpan(sample: sample, original: original);
print(result);
expect(result, isNotNull);
});

test('should return null if sample is not found in original', () {
final sample = SourceSpan(
SourceLocation(0),
SourceLocation(17),
'import "dart:io";',
);
final original = SourceSpan(
SourceLocation(20),
SourceLocation(38),
'/// void main() {}',
);
final result = getOriginalSubSpan(sample: original, original: sample);
expect(result, isNull);
});
});

// TODO: add emoji offset test
}
Loading