소스 검색

add tests for document symbols

Simon Krajewski 9 년 전
부모
커밋
11ed83708a
4개의 변경된 파일148개의 추가작업 그리고 0개의 파일을 삭제
  1. 20 0
      tests/display/src/DisplayTestCase.hx
  2. 4 0
      tests/display/src/DisplayTestContext.hx
  3. 22 0
      tests/display/src/ModuleSymbolEntry.hx
  4. 102 0
      tests/display/src/cases/DocumentSymbols.hx

+ 20 - 0
tests/display/src/DisplayTestCase.hx

@@ -50,6 +50,26 @@ class DisplayTestCase {
 		}
 	}
 
+	function arrayCheck<T>(expected:Array<T>, actual:Array<T>, f : T -> String, ?pos:haxe.PosInfos) {
+		var expected = [for (expected in expected) f(expected) => expected];
+		for (actual in actual) {
+			var key = f(actual);
+			if (!expected.exists(key)) {
+				numFailures++;
+				report("Result not part of expected Array:", pos);
+				report(Std.string(actual), pos);
+			}
+			expected.remove(key);
+		}
+
+		for (expected in expected) {
+			numFailures++;
+			report("Expected result was not part of actual Array:", pos);
+			report(Std.string(expected), pos);
+			return;
+		}
+	}
+
 	function hasField(a:Array<FieldElement>, name:String, type:String):Bool {
 		return a.exists(function(t) return t.type == type && t.name == name);
 	}

+ 4 - 0
tests/display/src/DisplayTestContext.hx

@@ -65,6 +65,10 @@ class DisplayTestContext {
 		return extractPositions(callHaxe('$pos@usage'));
 	}
 
+	public function documentSymbols():Array<ModuleSymbolEntry> {
+		return haxe.Json.parse(callHaxe("0@module-symbols"))[0].symbols;
+	}
+
 	function callHaxe(displayPart:String):String {
 		var args = [
 			"-cp", "src",

+ 22 - 0
tests/display/src/ModuleSymbolEntry.hx

@@ -0,0 +1,22 @@
+// Taken from vshaxe... not ideal to copy it here
+
+@:enum
+private abstract ModuleSymbolKind(Int) {
+    var MClass = 1;
+    var MInterface = 2;
+    var MEnum = 3;
+    var MTypedef = 4;
+    var MAbstract = 5;
+    var MField = 6;
+    var MProperty = 7;
+    var MMethod = 8;
+    var MConstructor = 9;
+    var MFunction = 10;
+    var MVariable = 11;
+}
+
+typedef ModuleSymbolEntry = {
+    var name:String;
+    var kind:ModuleSymbolKind;
+    @:optional var containerName:String;
+}

+ 102 - 0
tests/display/src/cases/DocumentSymbols.hx

@@ -0,0 +1,102 @@
+package cases;
+
+class DocumentSymbols extends DisplayTestCase {
+	/**
+	class Some {
+		function main() { }
+		static var x:String;
+		var y:Int;
+		var z(default, null):Bool;
+		function new() { }
+	}
+	**/
+	function testClassFields() {
+		checkDocumentSymbols([
+			{ name: "Some", kind: MClass, containerName: null },
+			{ name: "main", kind: MMethod, containerName: "Some" },
+			{ name: "x", kind: MField, containerName: "Some" },
+			{ name: "y", kind: MField, containerName: "Some" },
+			{ name: "z", kind: MProperty, containerName: "Some" },
+			{ name: "new", kind: MConstructor, containerName: "Some" }
+		], ctx.documentSymbols());
+	}
+
+	/**
+	interface Some {
+		function test():Void;
+	}
+	**/
+	function testInterface() {
+		checkDocumentSymbols([
+			{ name: "Some", kind: MInterface, containerName: null },
+			{ name: "test", kind: MMethod, containerName: "Some" }
+		], ctx.documentSymbols());
+	}
+
+	/**
+	enum E {
+		A;
+		B(s:String);
+	}
+	**/
+	function testEnum() {
+		checkDocumentSymbols([
+			{ name: "E", kind: MEnum, containerName: null },
+			{ name: "A", kind: MMethod, containerName: "E" },
+			{ name: "B", kind: MMethod, containerName: "E" }
+		], ctx.documentSymbols());
+	}
+
+	/**
+	typedef T = {
+		x:Int,
+	}
+	**/
+	function testTypedef() {
+		checkDocumentSymbols([
+			{ name: "T", kind: MTypedef, containerName: null },
+			{ name: "x", kind: MField, containerName: "T" }
+		], ctx.documentSymbols());
+	}
+
+	/**
+	abstract A(Int) {
+		public function new() { }
+		function f() { }
+	}
+	**/
+	function testAbstract() {
+		checkDocumentSymbols([
+			{ name: "A", kind: MAbstract, containerName: null },
+			{ name: "new", kind: MConstructor, containerName: "A" },
+			{ name: "f", kind: MMethod, containerName: "A" }
+		], ctx.documentSymbols());
+	}
+
+	/**
+	class Main {
+		static function main() {
+			var a = 12;
+			var b, c = 13;
+			var d = 1, e;
+			function f() { }
+		}
+	}
+	**/
+	function testExpression() {
+		checkDocumentSymbols([
+			{ name: "Main", kind: MClass, containerName: null },
+			{ name: "main", kind: MMethod, containerName: "Main" },
+			{ name: "a", kind: MVariable, containerName: "main" },
+			{ name: "b", kind: MVariable, containerName: "main" },
+			{ name: "c", kind: MVariable, containerName: "main" },
+			{ name: "d", kind: MVariable, containerName: "main" },
+			{ name: "e", kind: MVariable, containerName: "main" },
+			{ name: "f", kind: MFunction, containerName: "main" }
+		], ctx.documentSymbols());
+	}
+
+	function checkDocumentSymbols(expected:Array<ModuleSymbolEntry>, actual:Array<ModuleSymbolEntry>, ?pos:haxe.PosInfos) {
+		arrayCheck(expected, actual, function(entry) return entry.kind + ":" + entry.name + ":" + entry.containerName);
+	}
+}