A cursor at the end of a file should be inside the compilation unit

Change-Id: I68ff9337af9a416f18573e500a10eec1194adeaa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295400
Auto-Submit: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/utilities/extensions/ast.dart b/pkg/analyzer/lib/src/utilities/extensions/ast.dart
index 581dd2a..6d13b54 100644
--- a/pkg/analyzer/lib/src/utilities/extensions/ast.dart
+++ b/pkg/analyzer/lib/src/utilities/extensions/ast.dart
@@ -46,7 +46,7 @@
     }
 
     if (this is CompilationUnit) {
-      if (offset < 0 || end >= this.end) {
+      if (offset < 0 || end > this.end) {
         return null;
       }
     } else if (!containsOffset(this)) {
diff --git a/pkg/analyzer/test/src/utilities/extensions/ast_test.dart b/pkg/analyzer/test/src/utilities/extensions/ast_test.dart
index c4a8b39..7bf3504 100644
--- a/pkg/analyzer/test/src/utilities/extensions/ast_test.dart
+++ b/pkg/analyzer/test/src/utilities/extensions/ast_test.dart
@@ -42,6 +42,14 @@
     node as CompilationUnit;
   }
 
+  Future<void> test_atEOF() async {
+    var node = await coveringNode('''
+library myLib;
+
+^''');
+    node as CompilationUnit;
+  }
+
   Future<void> test_before_firstNonEOF() async {
     var node = await coveringNode('''
 ^