-
Notifications
You must be signed in to change notification settings - Fork 125
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
Fix line number cache #1939
Changes from 3 commits
5cffc0d
4d85b81
f6e19e8
0ad75e0
0f6433b
234b423
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2016, 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:path/path.dart' as pathLib; | ||
import 'package:test/test.dart'; | ||
import 'package:dartdoc/src/tuple.dart'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
|
||
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(pathLib.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(pathLib.join(_tempDir.path, 'single_line')) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It hardly matters but I'm a little surprised to see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
..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(pathLib.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(pathLib.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))); | ||
}); | ||
}); | ||
} |
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.
Update to 2019?
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