Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: pkg/analyzer/test/src/util/absolute_path_test.dart

Issue 1511833004: Validate that root paths are absolute and normalized. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analyzer/test/src/util/absolute_path_test.dart
diff --git a/pkg/analyzer/test/src/util/absolute_path_test.dart b/pkg/analyzer/test/src/util/absolute_path_test.dart
index 0f195c2ad98612c01b1056ff98519fd17049c469..420cba9ca8d92d7c3f04d5e8624c1ec934faa1f9 100644
--- a/pkg/analyzer/test/src/util/absolute_path_test.dart
+++ b/pkg/analyzer/test/src/util/absolute_path_test.dart
@@ -18,7 +18,7 @@ main() {
@reflectiveTest
class AbsolutePathContextPosixTest {
- AbsolutePathContext context = new AbsolutePathContext(r'/');
+ AbsolutePathContext context = new AbsolutePathContext(false);
void test_append() {
expect(context.append(r'/path/to', r'foo.dart'), r'/path/to/foo.dart');
@@ -38,6 +38,27 @@ class AbsolutePathContextPosixTest {
expect(context.dirname(r'/'), r'/');
}
+ void test_isValid_absolute() {
+ expect(context.isValid(r'/foo/bar'), isTrue);
+ expect(context.isValid(r'/foo'), isTrue);
+ expect(context.isValid(r'/'), isTrue);
+ expect(context.isValid(r''), isFalse);
+ expect(context.isValid(r'foo/bar'), isFalse);
+ }
+
+ void test_isValid_normalized() {
+ expect(context.isValid(r'/foo/bar'), isTrue);
+ expect(context.isValid(r'/foo/..bar'), isTrue);
+ expect(context.isValid(r'/foo/.bar/baz'), isTrue);
+ expect(context.isValid(r'/foo/...'), isTrue);
+ expect(context.isValid(r'/foo/.../bar'), isTrue);
+ expect(context.isValid(r'/foo/.bar/.'), isFalse);
+ expect(context.isValid(r'/foo/bar/../baz'), isFalse);
+ expect(context.isValid(r'/foo/bar/..'), isFalse);
+ expect(context.isValid(r'/foo/./bar'), isFalse);
+ expect(context.isValid(r'/.'), isFalse);
+ }
+
void test_isWithin() {
expect(context.isWithin(r'/root/path', r'/root/path/a'), isTrue);
expect(context.isWithin(r'/root/path', r'/root/other'), isFalse);
@@ -57,7 +78,7 @@ class AbsolutePathContextPosixTest {
@reflectiveTest
class AbsolutePathContextWindowsTest {
- AbsolutePathContext context = new AbsolutePathContext(r'\');
+ AbsolutePathContext context = new AbsolutePathContext(true);
void test_append() {
expect(context.append(r'C:\path\to', r'foo.dart'), r'C:\path\to\foo.dart');
@@ -77,6 +98,29 @@ class AbsolutePathContextWindowsTest {
expect(context.dirname(r'C:\'), r'C:\');
}
+ void test_isValid_absolute() {
+ expect(context.isValid(r'C:\foo\bar'), isTrue);
+ expect(context.isValid(r'c:\foo\bar'), isTrue);
+ expect(context.isValid(r'D:\foo\bar'), isTrue);
+ expect(context.isValid(r'C:\foo'), isTrue);
+ expect(context.isValid(r'C:\'), isTrue);
+ expect(context.isValid(r''), isFalse);
+ expect(context.isValid(r'foo\bar'), isFalse);
+ }
+
+ void test_isValid_normalized() {
+ expect(context.isValid(r'C:\foo\bar'), isTrue);
+ expect(context.isValid(r'C:\foo\..bar'), isTrue);
+ expect(context.isValid(r'C:\foo\.bar\baz'), isTrue);
+ expect(context.isValid(r'C:\foo\...'), isTrue);
+ expect(context.isValid(r'C:\foo\...\bar'), isTrue);
+ expect(context.isValid(r'C:\foo\.bar\.'), isFalse);
+ expect(context.isValid(r'C:\foo\bar\..\baz'), isFalse);
+ expect(context.isValid(r'C:\foo\bar\..'), isFalse);
+ expect(context.isValid(r'C:\foo\.\bar'), isFalse);
+ expect(context.isValid(r'C:\.'), isFalse);
+ }
+
void test_isWithin() {
expect(context.isWithin(r'C:\root\path', r'C:\root\path\a'), isTrue);
expect(context.isWithin(r'C:\root\path', r'C:\root\other'), isFalse);
« pkg/analyzer/lib/src/util/absolute_path.dart ('K') | « pkg/analyzer/lib/src/util/absolute_path.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698