-
Notifications
You must be signed in to change notification settings - Fork 124
Fix line number cache #1939
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
Closed
Closed
Fix line number cache #1939
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5cffc0d
Fix line number cache and add tests
jcollins-g 4d85b81
dartfmt
jcollins-g f6e19e8
Merge branch 'master' into fix-line-number-cache
jcollins-g 0ad75e0
remove accidental minus 0
jcollins-g 0f6433b
Merge from head
jcollins-g 234b423
Review comments and lint fixup for modern Dart
jcollins-g 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 hidden or 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 hidden or 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,65 @@ | ||
// Copyright (c) 2019, 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. | ||
|
||
library dartdoc.cache_test; | ||
|
||
import 'dart:io'; | ||
|
||
import 'package:dartdoc/src/line_number_cache.dart'; | ||
import 'package:dartdoc/src/tuple.dart'; | ||
import 'package:path/path.dart' as path; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('Verify basic line cache behavior', () { | ||
Directory _tempDir; | ||
|
||
setUp(() { | ||
_tempDir = Directory.systemTemp.createTempSync('line_number_cache'); | ||
}); | ||
|
||
tearDown(() { | ||
_tempDir.deleteSync(recursive: true); | ||
}); | ||
|
||
test('validate empty file behavior', () { | ||
File emptyFile = File(path.join(_tempDir.path, 'empty_file')) | ||
..writeAsStringSync(''); | ||
LineNumberCache cache = LineNumberCache(); | ||
expect(cache.lineAndColumn(emptyFile.path, 0), equals(Tuple2(1, 0))); | ||
}); | ||
|
||
test('single line without newline', () { | ||
File singleLineWithoutNewline = | ||
File(path.join(_tempDir.path, 'single_line')) | ||
..writeAsStringSync('a single line'); | ||
LineNumberCache cache = LineNumberCache(); | ||
expect(cache.lineAndColumn(singleLineWithoutNewline.path, 2), | ||
equals(Tuple2(1, 2))); | ||
expect(cache.lineAndColumn(singleLineWithoutNewline.path, 0), | ||
equals(Tuple2(1, 0))); | ||
}); | ||
|
||
test('multiple line without trailing newline', () { | ||
File multipleLine = File(path.join(_tempDir.path, 'multiple_line')) | ||
..writeAsStringSync('This is the first line\nThis is the second line'); | ||
LineNumberCache cache = LineNumberCache(); | ||
expect(cache.lineAndColumn(multipleLine.path, 60), equals(Tuple2(2, 38))); | ||
expect(cache.lineAndColumn(multipleLine.path, 30), equals(Tuple2(2, 8))); | ||
expect(cache.lineAndColumn(multipleLine.path, 5), equals(Tuple2(1, 5))); | ||
expect(cache.lineAndColumn(multipleLine.path, 0), equals(Tuple2(1, 0))); | ||
}); | ||
|
||
test('multiple lines with trailing newline', () { | ||
File multipleLine = File(path.join(_tempDir.path, 'multiple_line')) | ||
..writeAsStringSync( | ||
'This is the first line\nThis is the second line\n'); | ||
LineNumberCache cache = LineNumberCache(); | ||
expect(cache.lineAndColumn(multipleLine.path, 60), equals(Tuple2(3, 14))); | ||
expect(cache.lineAndColumn(multipleLine.path, 30), equals(Tuple2(2, 8))); | ||
expect(cache.lineAndColumn(multipleLine.path, 5), equals(Tuple2(1, 5))); | ||
expect(cache.lineAndColumn(multipleLine.path, 0), equals(Tuple2(1, 0))); | ||
}); | ||
}); | ||
} |
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.
Sort up?
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.
done