mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 11:38:21 +02:00
Fixed some indenting issues, added indenting test
This commit is contained in:
parent
df4573dca1
commit
e5de09488e
7 changed files with 213 additions and 14 deletions
|
@ -1548,7 +1548,19 @@ namespace Beefy.widgets
|
||||||
int lineChar;
|
int lineChar;
|
||||||
GetLineCharAtIdx(textPos, out line, out lineChar);
|
GetLineCharAtIdx(textPos, out line, out lineChar);
|
||||||
|
|
||||||
bool wasLineEnd = mData.mText[textPos].mChar == '\n';
|
bool wasLineEnd = false;
|
||||||
|
for (int i = textPos; i < mData.mTextLength; i++)
|
||||||
|
{
|
||||||
|
char8 c = mData.mText[i].mChar;
|
||||||
|
if (c == '\n')
|
||||||
|
{
|
||||||
|
wasLineEnd = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (!c.IsWhiteSpace)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
String lineText = scope String();
|
String lineText = scope String();
|
||||||
GetLineText(line, lineText);
|
GetLineText(line, lineText);
|
||||||
|
|
||||||
|
|
9
IDE/Tests/IndentTest/BeefProj.toml
Normal file
9
IDE/Tests/IndentTest/BeefProj.toml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
FileVersion = 1
|
||||||
|
|
||||||
|
[Project]
|
||||||
|
Name = "IDETest"
|
||||||
|
TargetType = "BeefWindowsApplication"
|
||||||
|
StartupObject = "IDETest.Program"
|
||||||
|
|
||||||
|
[Configs.Debug.Win64]
|
||||||
|
BeefLibType = "DynamicDebug"
|
12
IDE/Tests/IndentTest/BeefSpace.toml
Normal file
12
IDE/Tests/IndentTest/BeefSpace.toml
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
FileVersion = 1
|
||||||
|
Projects = {IDETest = {Path = "."}}
|
||||||
|
Unlocked = ["corlib"]
|
||||||
|
|
||||||
|
[Workspace]
|
||||||
|
StartupProject = "IDETest"
|
||||||
|
|
||||||
|
[Configs.Debug.Win64]
|
||||||
|
IntermediateType = "ObjectAndIRCode"
|
||||||
|
|
||||||
|
[Configs.Debug.Win32]
|
||||||
|
IntermediateType = "ObjectAndIRCode"
|
46
IDE/Tests/IndentTest/scripts/Indent01.txt
Normal file
46
IDE/Tests/IndentTest/scripts/Indent01.txt
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
ShowFile("src/Indent01.bf")
|
||||||
|
|
||||||
|
GotoText("//Test01")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 17)
|
||||||
|
|
||||||
|
GotoText("//Test02")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 21)
|
||||||
|
|
||||||
|
GotoText("//Test03")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 21)
|
||||||
|
|
||||||
|
GotoText("//Test04")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 25)
|
||||||
|
|
||||||
|
GotoText("//Test05")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 25)
|
||||||
|
|
||||||
|
GotoText("//Test06")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 21)
|
||||||
|
|
||||||
|
GotoText("//Test07")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 25)
|
||||||
|
|
||||||
|
GotoText("//Test08")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 21)
|
||||||
|
|
||||||
|
GotoText("//Test09")
|
||||||
|
AdjustCursor(0, -1)
|
||||||
|
CursorToLineEnd()
|
||||||
|
AssertIsAtColumn("Indent01.bf", 17)
|
100
IDE/Tests/IndentTest/src/Indent01.bf
Normal file
100
IDE/Tests/IndentTest/src/Indent01.bf
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
namespace IDETest
|
||||||
|
{
|
||||||
|
class Indent01
|
||||||
|
{
|
||||||
|
static void Test01()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
|
||||||
|
//Test01
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test02()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
|
||||||
|
//Test02
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test03()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
;
|
||||||
|
else
|
||||||
|
|
||||||
|
//Test03
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test04()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
for ()
|
||||||
|
|
||||||
|
//Test04
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test05()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
;
|
||||||
|
else
|
||||||
|
for ()
|
||||||
|
|
||||||
|
//Test05
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test06()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
;
|
||||||
|
else if (true)
|
||||||
|
|
||||||
|
//Test06
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test07()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
;
|
||||||
|
else if (true)
|
||||||
|
for (int i < 10)
|
||||||
|
|
||||||
|
//Test07
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test08()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
;
|
||||||
|
else if (true)
|
||||||
|
for (int i < 10)
|
||||||
|
;
|
||||||
|
else
|
||||||
|
|
||||||
|
//Test08
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Test09()
|
||||||
|
{
|
||||||
|
if (true)
|
||||||
|
if (true)
|
||||||
|
;
|
||||||
|
else if (true)
|
||||||
|
for (int i < 10)
|
||||||
|
;
|
||||||
|
else
|
||||||
|
;
|
||||||
|
|
||||||
|
for (int i < 20)
|
||||||
|
|
||||||
|
//Test09
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -828,6 +828,7 @@ namespace IDE.ui
|
||||||
int ifDepth = 0;
|
int ifDepth = 0;
|
||||||
bool isDoingCtl = false;
|
bool isDoingCtl = false;
|
||||||
bool justFinishedCtlCond = false;
|
bool justFinishedCtlCond = false;
|
||||||
|
bool justFinishedCtl = false;
|
||||||
int ctlDepth = 0; // for, while, using
|
int ctlDepth = 0; // for, while, using
|
||||||
|
|
||||||
int extraTab = 1;
|
int extraTab = 1;
|
||||||
|
@ -906,10 +907,7 @@ namespace IDE.ui
|
||||||
{
|
{
|
||||||
if (blockDepth == 0)
|
if (blockDepth == 0)
|
||||||
{
|
{
|
||||||
switch (keywordStr)
|
if (((justFinishedIf) || (justFinishedCtl)) && (keywordStr != "else"))
|
||||||
{
|
|
||||||
case "if":
|
|
||||||
if (justFinishedIf)
|
|
||||||
{
|
{
|
||||||
// This catches the case of:
|
// This catches the case of:
|
||||||
// if (a) Thing();
|
// if (a) Thing();
|
||||||
|
@ -918,8 +916,16 @@ namespace IDE.ui
|
||||||
justFinishedIf = false;
|
justFinishedIf = false;
|
||||||
ifCtlDepthStack.Clear();
|
ifCtlDepthStack.Clear();
|
||||||
ctlDepth = 0;
|
ctlDepth = 0;
|
||||||
|
|
||||||
|
isDoingCtl = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
justFinishedCtl = false;
|
||||||
|
justFinishedIf = false;
|
||||||
|
|
||||||
|
switch (keywordStr)
|
||||||
|
{
|
||||||
|
case "if":
|
||||||
if (isDoingCtl)
|
if (isDoingCtl)
|
||||||
{
|
{
|
||||||
ctlDepth++;
|
ctlDepth++;
|
||||||
|
@ -947,7 +953,11 @@ namespace IDE.ui
|
||||||
caseStartPos = checkIdx - 4;
|
caseStartPos = checkIdx - 4;
|
||||||
inCaseExpr = true;
|
inCaseExpr = true;
|
||||||
}
|
}
|
||||||
|
case "switch":
|
||||||
|
ifDepth = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doingElse = keywordStr == "else";
|
||||||
}
|
}
|
||||||
|
|
||||||
keywordStr.Clear();
|
keywordStr.Clear();
|
||||||
|
@ -1052,6 +1062,9 @@ namespace IDE.ui
|
||||||
startedWithType = false;
|
startedWithType = false;
|
||||||
checkedStartedWithType = false;
|
checkedStartedWithType = false;
|
||||||
|
|
||||||
|
if (isDoingCtl)
|
||||||
|
justFinishedCtl = true;
|
||||||
|
|
||||||
if (ifDepth == 0)
|
if (ifDepth == 0)
|
||||||
{
|
{
|
||||||
isDoingCtl = false;
|
isDoingCtl = false;
|
||||||
|
@ -1075,7 +1088,6 @@ namespace IDE.ui
|
||||||
doingElse = false;
|
doingElse = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (justFinishedIf)
|
if (justFinishedIf)
|
||||||
{
|
{
|
||||||
// We had a non-else statement
|
// We had a non-else statement
|
||||||
|
@ -1092,7 +1104,6 @@ namespace IDE.ui
|
||||||
if (ifDepth > 0)
|
if (ifDepth > 0)
|
||||||
justFinishedIf = true;
|
justFinishedIf = true;
|
||||||
|
|
||||||
//NEW
|
|
||||||
inCaseExpr = false;
|
inCaseExpr = false;
|
||||||
inCaseExprNext = false;
|
inCaseExprNext = false;
|
||||||
inCaseExprNextLine = false;
|
inCaseExprNextLine = false;
|
||||||
|
@ -1147,6 +1158,7 @@ namespace IDE.ui
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((ctlDepth > 0) && ((!justFinishedIf) || (insertingElseStmt)))
|
if ((ctlDepth > 0) && ((!justFinishedIf) || (insertingElseStmt)))
|
||||||
extraTab += ctlDepth;
|
extraTab += ctlDepth;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,14 @@ PUSHD %~dp0..\
|
||||||
@CALL :TEST
|
@CALL :TEST
|
||||||
@IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
|
@IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
|
||||||
|
|
||||||
|
@SET TESTPATH=IDE\Tests\BugW002
|
||||||
|
@CALL :TEST
|
||||||
|
@IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
|
||||||
|
|
||||||
|
@SET TESTPATH=IDE\Tests\IndentTest
|
||||||
|
@CALL :TEST
|
||||||
|
@IF !ERRORLEVEL! NEQ 0 GOTO HADERROR
|
||||||
|
|
||||||
@GOTO :EMPTYTEST
|
@GOTO :EMPTYTEST
|
||||||
|
|
||||||
:TEST
|
:TEST
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue