Browse Source

[display] add various tests for parser error diagnostics

closes #7938
closes #7939
closes #7940
Jens Fischer 6 years ago
parent
commit
81a217827c

+ 38 - 0
tests/display/src/cases/Issue5306.hx

@@ -0,0 +1,38 @@
+package cases;
+
+class Issue5306 extends DisplayTestCase {
+	/**
+		{-1-}import {-3-}InvalidType{-4-};{-2-}
+
+		class Main {
+			static function main() {
+				var ib:Array<Int>;
+				ib[0] = 0; ib[1] = 1; ib[2]
+				{-5-}trace{-6-}("test");
+			}
+		}
+	**/
+	function test() {
+		var expected:Array<Diagnostic<Dynamic>> = [
+			{
+				kind: DKUnusedImport,
+				range: diagnosticsRange(pos(1), pos(2)),
+				severity: Warning,
+				args: []
+			},
+			{
+				kind: DKCompilerError,
+				range: diagnosticsRange(pos(3), pos(4)),
+				severity: Error,
+				args: "Type not found : InvalidType"
+			},
+			{
+				kind: DKParserError,
+				range: diagnosticsRange(pos(5), pos(6)),
+				severity: Error,
+				args: "Missing ;"
+			}
+		];
+		arrayEq(expected, diagnostics());
+	}
+}

+ 19 - 0
tests/display/src/cases/Issue7938.hx

@@ -0,0 +1,19 @@
+package cases;
+
+class Issue7938 extends DisplayTestCase {
+	/**
+		class Main {
+			public static {-1-}fuction{-2-} main() {}
+		}
+	**/
+	function test() {
+		arrayEq([
+			{
+				kind: DKParserError,
+				range: diagnosticsRange(pos(1), pos(2)),
+				severity: Error,
+				args: "Unexpected fuction"
+			}
+		], diagnostics());
+	}
+}

+ 17 - 0
tests/display/src/cases/Issue7939.hx

@@ -0,0 +1,17 @@
+package cases;
+
+class Issue7939 extends DisplayTestCase {
+	/**
+		typedef Struct {-1-}{{-2-}}
+	**/
+	function test() {
+		arrayEq([
+			{
+				kind: DKParserError,
+				range: diagnosticsRange(pos(1), pos(2)),
+				severity: Error,
+				args: "Unexpected {"
+			}
+		], diagnostics());
+	}
+}

+ 21 - 0
tests/display/src/cases/Issue7940.hx

@@ -0,0 +1,21 @@
+package cases;
+
+class Issue7940 extends DisplayTestCase {
+	/**
+		class Main {
+			static function main() {
+				{-1-}"Hello World
+			}
+		}
+	**/
+	function test() {
+		arrayEq([
+			{
+				kind: DKParserError,
+				range: diagnosticsRange(pos(1), pos(1)),
+				severity: Error,
+				args: "Unterminated string"
+			}
+		], diagnostics());
+	}
+}