From aea8bd88144501aeda26ef05402acd442d6a5e74 Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Sun, 4 Feb 2024 13:08:49 +0100 Subject: [PATCH] adding tests for indent formatting rules --- CHANGELOG.md | 4 + .../plugins/haxe/lang/HaxeFormatterTest.java | 13 +++ .../testData/formatter/IndentSpaces.hx | 91 +++++++++++++++++++ .../testData/formatter/IndentSpaces.txt | 90 ++++++++++++++++++ .../testData/formatter/IndentTabs.hx | 91 +++++++++++++++++++ .../testData/formatter/IndentTabs.txt | 90 ++++++++++++++++++ 6 files changed, 379 insertions(+) create mode 100644 src/test/resources/testData/formatter/IndentSpaces.hx create mode 100644 src/test/resources/testData/formatter/IndentSpaces.txt create mode 100644 src/test/resources/testData/formatter/IndentTabs.hx create mode 100644 src/test/resources/testData/formatter/IndentTabs.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 7328bbfb7..5756c2f51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog ## 1.4.30 +* Fixed: Issue where classes with identical names as Enum values would resolve to enum value +* Added: Indent options under haxe code style (PR #1148 from virtulis) +* +## 1.4.30 * Fixed: Resolver bug ## 1.4.29 diff --git a/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java b/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java index abb18b0ba..574549d14 100644 --- a/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java +++ b/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java @@ -255,6 +255,19 @@ public void testCommentAlignmentKeepLeft() throws Exception { myTestStyleSettings.KEEP_FIRST_COLUMN_COMMENT = true; doTest(); } + @Test + public void testIndentTabs() throws Exception { + myTestStyleSettings.getIndentOptions().USE_TAB_CHARACTER = true; + myTestStyleSettings.getIndentOptions().INDENT_SIZE = 1; + myTestStyleSettings.getIndentOptions().TAB_SIZE = 1; + doTest(); + } + @Test + public void testIndentSpaces() throws Exception { + myTestStyleSettings.getIndentOptions().USE_TAB_CHARACTER = false; + myTestStyleSettings.getIndentOptions().INDENT_SIZE = 3; + doTest(); + } @Test public void testLineFeedsWithComments() throws Exception { diff --git a/src/test/resources/testData/formatter/IndentSpaces.hx b/src/test/resources/testData/formatter/IndentSpaces.hx new file mode 100644 index 000000000..5cad0a73d --- /dev/null +++ b/src/test/resources/testData/formatter/IndentSpaces.hx @@ -0,0 +1,91 @@ +import com.Foo;using com.utils.MathUtil;class Foo{ +// function fBar (x,y); + function fOne(argA:Int, + argB, argC, argD, + argE, argF, argG, argH ){ + var numbers:Array< String> = ['one', + 'two', + 'three', 'four', 'five', 'six']; + var x = ("" + argA) + argB + + argC + argD + argE + argF + argG + argH; + try { + this.fTwo (argA, argB, argC, + this.fThree( "", argE, argF, argG, argH)); + } catch (ignored:String) { + + } + var z = argA == 'Some string' ? 'yes' : 'no'; + var colors = ['red', 'green', 'blue', 'black', 'white', 'gray']; + for (colorIndex in 0...colors.length) { + var colorString = numbers[colorIndex]; + } + do { + colors.pop (); + } + while (colors. length > 0); + } + + function fTwo(strA, strB, strC, strD) { + if (true) + return strC; + if (strA == 'one' || strB == 'two') { + return strA + strB; + }else + if (true) + return strD; + throw strD; + } + + function fThree ( strA , strB, strC, strD, strE ){ + return strA + strB + strC + strD + strE; + } + public function new ( ) { + switch( v ) { + case 0: + e1(); + case foo(1): + break; + case 65, 90: + e3(); + default: + return; + } + } + + + static public function getBrowser(browserAgent:String):String { + if (browserAgent != null) + { + if (browserAgent.indexOf("Firefox") + >= 0) { + + _browser = Browser_firefox; + } + + else + if (browserAgent.indexOf("Safari") >= 0) { + _browser = Browser_safari; + } + + else + if (browserAgent.indexOf("MSIE") >= 0) { + _browser = Browser_ie; + } + + else if (browserAgent.indexOf("Opera") >= 0) { + _browser = Browser_opera; + } + + else { + _browser = Browser_unknown; + } + + } + + else { + _browser = Browser_unknown; + } + + return browser; + } + } \ No newline at end of file diff --git a/src/test/resources/testData/formatter/IndentSpaces.txt b/src/test/resources/testData/formatter/IndentSpaces.txt new file mode 100644 index 000000000..05474aa4b --- /dev/null +++ b/src/test/resources/testData/formatter/IndentSpaces.txt @@ -0,0 +1,90 @@ +import com.Foo; +using com.utils.MathUtil; +class Foo { + // function fBar (x,y); + function fOne(argA:Int, + argB, argC, argD, + argE, argF, argG, argH) { + var numbers:Array< String> = ['one', + 'two', + 'three', 'four', 'five', 'six']; + var x = ("" + argA) + argB + + argC + argD + argE + argF + argG + argH; + try { + this.fTwo(argA, argB, argC, + this.fThree("", argE, argF, argG, argH)); + } catch (ignored:String) { + + } + var z = argA == 'Some string' ? 'yes' : 'no'; + var colors = ['red', 'green', 'blue', 'black', 'white', 'gray']; + for (colorIndex in 0...colors.length) { + var colorString = numbers[colorIndex]; + } + do { + colors.pop(); + } + while (colors. length > 0); + } + + function fTwo(strA, strB, strC, strD) { + if (true) + return strC; + if (strA == 'one' || strB == 'two') { + return strA + strB; + } else if (true) + return strD; + throw strD; + } + + function fThree(strA, strB, strC, strD, strE) { + return strA + strB + strC + strD + strE; + } + + public function new() { + switch( v ) { + case 0: + e1(); + case foo(1): + break; + case 65, 90: + e3(); + default: + return; + } + } + + + static public function getBrowser(browserAgent:String):String { + if (browserAgent != null) { + if (browserAgent.indexOf("Firefox") + >= 0) { + + _browser = Browser_firefox; + } + + else if (browserAgent.indexOf("Safari") >= 0) { + _browser = Browser_safari; + } + + else if (browserAgent.indexOf("MSIE") >= 0) { + _browser = Browser_ie; + } + + else if (browserAgent.indexOf("Opera") >= 0) { + _browser = Browser_opera; + } + + else { + _browser = Browser_unknown; + } + + } + + else { + _browser = Browser_unknown; + } + + return browser; + } +} \ No newline at end of file diff --git a/src/test/resources/testData/formatter/IndentTabs.hx b/src/test/resources/testData/formatter/IndentTabs.hx new file mode 100644 index 000000000..5cad0a73d --- /dev/null +++ b/src/test/resources/testData/formatter/IndentTabs.hx @@ -0,0 +1,91 @@ +import com.Foo;using com.utils.MathUtil;class Foo{ +// function fBar (x,y); + function fOne(argA:Int, + argB, argC, argD, + argE, argF, argG, argH ){ + var numbers:Array< String> = ['one', + 'two', + 'three', 'four', 'five', 'six']; + var x = ("" + argA) + argB + + argC + argD + argE + argF + argG + argH; + try { + this.fTwo (argA, argB, argC, + this.fThree( "", argE, argF, argG, argH)); + } catch (ignored:String) { + + } + var z = argA == 'Some string' ? 'yes' : 'no'; + var colors = ['red', 'green', 'blue', 'black', 'white', 'gray']; + for (colorIndex in 0...colors.length) { + var colorString = numbers[colorIndex]; + } + do { + colors.pop (); + } + while (colors. length > 0); + } + + function fTwo(strA, strB, strC, strD) { + if (true) + return strC; + if (strA == 'one' || strB == 'two') { + return strA + strB; + }else + if (true) + return strD; + throw strD; + } + + function fThree ( strA , strB, strC, strD, strE ){ + return strA + strB + strC + strD + strE; + } + public function new ( ) { + switch( v ) { + case 0: + e1(); + case foo(1): + break; + case 65, 90: + e3(); + default: + return; + } + } + + + static public function getBrowser(browserAgent:String):String { + if (browserAgent != null) + { + if (browserAgent.indexOf("Firefox") + >= 0) { + + _browser = Browser_firefox; + } + + else + if (browserAgent.indexOf("Safari") >= 0) { + _browser = Browser_safari; + } + + else + if (browserAgent.indexOf("MSIE") >= 0) { + _browser = Browser_ie; + } + + else if (browserAgent.indexOf("Opera") >= 0) { + _browser = Browser_opera; + } + + else { + _browser = Browser_unknown; + } + + } + + else { + _browser = Browser_unknown; + } + + return browser; + } + } \ No newline at end of file diff --git a/src/test/resources/testData/formatter/IndentTabs.txt b/src/test/resources/testData/formatter/IndentTabs.txt new file mode 100644 index 000000000..8d84615a3 --- /dev/null +++ b/src/test/resources/testData/formatter/IndentTabs.txt @@ -0,0 +1,90 @@ +import com.Foo; +using com.utils.MathUtil; +class Foo { + // function fBar (x,y); + function fOne(argA:Int, + argB, argC, argD, + argE, argF, argG, argH) { + var numbers:Array< String> = ['one', + 'two', + 'three', 'four', 'five', 'six']; + var x = ("" + argA) + argB + + argC + argD + argE + argF + argG + argH; + try { + this.fTwo(argA, argB, argC, + this.fThree("", argE, argF, argG, argH)); + } catch (ignored:String) { + + } + var z = argA == 'Some string' ? 'yes' : 'no'; + var colors = ['red', 'green', 'blue', 'black', 'white', 'gray']; + for (colorIndex in 0...colors.length) { + var colorString = numbers[colorIndex]; + } + do { + colors.pop(); + } + while (colors. length > 0); + } + + function fTwo(strA, strB, strC, strD) { + if (true) + return strC; + if (strA == 'one' || strB == 'two') { + return strA + strB; + } else if (true) + return strD; + throw strD; + } + + function fThree(strA, strB, strC, strD, strE) { + return strA + strB + strC + strD + strE; + } + + public function new() { + switch( v ) { + case 0: + e1(); + case foo(1): + break; + case 65, 90: + e3(); + default: + return; + } + } + + + static public function getBrowser(browserAgent:String):String { + if (browserAgent != null) { + if (browserAgent.indexOf("Firefox") + >= 0) { + + _browser = Browser_firefox; + } + + else if (browserAgent.indexOf("Safari") >= 0) { + _browser = Browser_safari; + } + + else if (browserAgent.indexOf("MSIE") >= 0) { + _browser = Browser_ie; + } + + else if (browserAgent.indexOf("Opera") >= 0) { + _browser = Browser_opera; + } + + else { + _browser = Browser_unknown; + } + + } + + else { + _browser = Browser_unknown; + } + + return browser; + } +} \ No newline at end of file