Jelajahi Sumber

[display] add some tests for the type completion (see #5642)

Dan Korostelev 9 tahun lalu
induk
melakukan
2bacc755f7
1 mengubah file dengan 85 tambahan dan 1 penghapusan
  1. 85 1
      tests/display/src/cases/Toplevel.hx

+ 85 - 1
tests/display/src/cases/Toplevel.hx

@@ -32,7 +32,91 @@ class Toplevel extends DisplayTestCase {
 		eq(true, hasToplevel(toplevel2, "local", "a"));
 	}
 
+	/**
+	class Main {
+		static var myField;
+		static function main() {
+			var a:{-1-}
+	**/
+	function testTypeCompletionLocal() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Main"));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+		eq(false, hasToplevel(typesCompletion, "static", "myField"));
+	}
+
+	/**
+	class Main {
+		var a:{-1-}
+	**/
+	function testTypeCompletionField() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Main"));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+	class Main {
+		static function f(a:{-1-})
+	**/
+	function testTypeCompletionArgument() {
+		// TODO: this currently doesn't work if there's no closing paren for function arguments
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Main"));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+	var a = function(a:{-1-}
+	**/
+	@:funcCode function testTypeCompletionArgumentLocal() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+	import {-1-}
+	**/
+	function testTypeCompletionArgumentImport() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+	using {-1-}
+	**/
+	function testTypeCompletionArgumentUsing() {
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+	class C extends {-1-} {
+	**/
+	function testTypeCompletionArgumentExtends() {
+		// TODO: this currently doesn't work if there's no token after extends
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
+	/**
+	class C implements {-1-} {
+	**/
+	function testTypeCompletionArgumentImplements() {
+		// TODO: this currently doesn't work if there's no token after implements
+		var typesCompletion = toplevel(pos(1));
+		eq(true, hasToplevel(typesCompletion, "type", "Array"));
+		eq(true, hasToplevel(typesCompletion, "package", "haxe"));
+	}
+
 	static function hasToplevel(a:Array<ToplevelElement>, kind:String, name:String):Bool {
 		return a.exists(function(t) return t.kind == kind && t.name == name);
 	}
-}
+}