Skip to content

Commit 48d645f

Browse files
committed
提交更多的测试修复bug
1 parent 17e2691 commit 48d645f

File tree

13 files changed

+262
-12
lines changed

13 files changed

+262
-12
lines changed

CodeService/src/LuaFormatter.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,12 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatLocalStatement(std::shared_pt
392392
env->AddChild(FormatNode(node));
393393
break;
394394
}
395+
case LuaAstNodeType::Comment:
396+
{
397+
env->AddChild(FormatNode(node));
398+
env->Add<KeepElement>(1);
399+
break;
400+
}
395401
default:
396402
DefaultHandle(node, env);
397403
break;
@@ -428,6 +434,12 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatAssignment(std::shared_ptr<Lu
428434
env->AddChild(FormatNode(node));
429435
}
430436

437+
break;
438+
}
439+
case LuaAstNodeType::Comment:
440+
{
441+
env->AddChild(FormatNode(node));
442+
env->Add<KeepElement>(1);
431443
break;
432444
}
433445
default:
@@ -458,6 +470,12 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatNameDefList(std::shared_ptr<L
458470
env->Add<KeepBlankElement>(1);
459471
break;
460472
}
473+
case LuaAstNodeType::Comment:
474+
{
475+
env->AddChild(FormatNode(node));
476+
env->Add<KeepElement>(1);
477+
break;
478+
}
461479
default:
462480
DefaultHandle(node, env);
463481
break;
@@ -587,7 +605,12 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatReturnStatement(std::shared_p
587605
env->AddChild(FormatNode(child));
588606
break;
589607
}
590-
608+
case LuaAstNodeType::Comment:
609+
{
610+
env->AddChild(FormatNode(child));
611+
env->Add<KeepElement>(1);
612+
break;
613+
}
591614
default:
592615
DefaultHandle(child, env);
593616
break;
@@ -1320,6 +1343,12 @@ std::shared_ptr<FormatElement> LuaFormatter::FormatTableField(std::shared_ptr<Lu
13201343
env->Add<TextElement>(child, TextDefineType::TableFieldNameDefine);
13211344
break;
13221345
}
1346+
case LuaAstNodeType::Comment:
1347+
{
1348+
env->AddChild(FormatNode(child));
1349+
env->Add<KeepElement>(1);
1350+
break;
1351+
}
13231352
default:
13241353
{
13251354
DefaultHandle(child, env);
@@ -1333,10 +1362,6 @@ void LuaFormatter::DefaultHandle(std::shared_ptr<LuaAstNode> node, std::shared_p
13331362
{
13341363
auto childEnv = FormatNode(node);
13351364
envElement->AddChild(childEnv);
1336-
if (node->GetType() == LuaAstNodeType::Comment)
1337-
{
1338-
envElement->Add<KeepElement>(1);
1339-
}
13401365
}
13411366

13421367
std::shared_ptr<FormatElement> LuaFormatter::FormatAlignStatement(LuaAstNode::ChildIterator& it,
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local t = 123 -- 123131
2+
local -- 1313131
3+
t--lnfowjhfjwfiow
4+
=--lkwjoifgjwojgwgw
5+
131231--fgjoiwejgoweijgiope
6+
7+
if aaa --ffff
8+
and --fjwofjiwfiw
9+
cccc or ok then -- heeeeeee
10+
---fff
11+
print("wjfgopwjoifgw"--[[whgwhgiwh]])
12+
end
13+
14+
function ff()
15+
---f2
16+
--[[
17+
aaaabbbb,cccc,eeee,fff
18+
]]
19+
local t = 1231
20+
---@type fff2
21+
local e =1231
22+
end
23+
24+
return --fff
25+
aaa+ccc,bbb
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
local t = -1
2+
local t1 = not a and b or c
3+
local t2 = not a ..b or "" -3 + 4 -5
4+
local t3 = - - 2 + - - - - 5
5+
6+
(function () end)()
7+
call(123,456)(789)
8+
call "12313" (456)
9+
call(123) "456"
10+
print [[
11+
12313
12+
13+
456
14+
15+
789
16+
]]
17+
function f()
18+
aaaa.bbbb.cccc.callllll()
19+
aaaa["awfwfw"].bbbbb:cccccc()
20+
aaaa["wfwfw"]:f()
21+
aaaa[13131].bbbb.ccc:ddd()
22+
aaaaa.bbb
23+
.ccc()
24+
.eeeee()
25+
.fffff()
26+
.jjjjj()
27+
28+
local t = {
29+
aaa,bbbb,cccc
30+
}
31+
local c = { aaa, 13131, 2424242 }
32+
local ddd = call { aaaa, bbb, ccc }
33+
local eee = calll
34+
{ 12313, 35353, fff }
35+
local fff = function() end
36+
dd.e().e().aaa =1231
37+
end
38+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
local t = aaa, bbbb, ccc, dddd
2+
3+
local t1 = aaa,function () end,eee+ccc,dddd
4+
5+
local t2 = c2(function()
6+
end),bbbb,ccc,function()end,
7+
function (
8+
9+
)
10+
end
11+
12+
function ff()
13+
return a,b,c,
14+
d
15+
end
16+
17+
function fff2()
18+
return aaaa and
19+
cc or d,a, function ()end
20+
end
21+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function label()
2+
while true do
3+
if ok then
4+
goto continue
5+
end
6+
7+
::continue::
8+
end
9+
end
10+
11+
goto label2
12+
13+
function f2()
14+
while true do
15+
while true do
16+
if true then
17+
end
18+
19+
end
20+
end
21+
::endloop::
22+
end
23+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
local a = 1231 + 1231.123131 + 0xFFFF + 0.1e-30 + 0.9E-31
2+
+ 1e1 + 1E3
3+
4+
-- luajit
5+
local b =1231ULL
6+

Test/test_script/format_text/while.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ while true do while false do end end
22

33
while false do
44
print("if \z
5-
OK
6-
ok
7-
5+
OK\z
6+
ok\z
7+
\z
88
")
99

1010
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
local t = 123 -- 123131
2+
local -- 1313131
3+
t--lnfowjhfjwfiow
4+
= --lkwjoifgjwojgwgw
5+
131231 --fgjoiwejgoweijgiope
6+
7+
if aaa --ffff
8+
and --fjwofjiwfiw
9+
cccc or ok then -- heeeeeee
10+
---fff
11+
print("wjfgopwjoifgw"--[[whgwhgiwh]] )
12+
end
13+
14+
function ff()
15+
---f2
16+
--[[
17+
aaaabbbb,cccc,eeee,fff
18+
]]
19+
local t = 1231
20+
---@type fff2
21+
local e = 1231
22+
end
23+
24+
return--fff
25+
aaa + ccc, bbb
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
local t = -1
2+
local t1 = not a and b or c
3+
local t2 = not a .. b or "" - 3 + 4 - 5
4+
local t3 = - -2 + - - - -5
5+
6+
(function() end)()
7+
call(123, 456)(789)
8+
call "12313"(456)
9+
call(123)"456"
10+
print [[
11+
12313
12+
13+
456
14+
15+
789
16+
]]
17+
function f()
18+
aaaa.bbbb.cccc.callllll()
19+
aaaa["awfwfw"].bbbbb:cccccc()
20+
aaaa["wfwfw"]:f()
21+
aaaa[13131].bbbb.ccc:ddd()
22+
aaaaa.bbb
23+
.ccc()
24+
.eeeee()
25+
.fffff()
26+
.jjjjj()
27+
28+
local t = {
29+
aaa, bbbb, cccc
30+
}
31+
local c = { aaa, 13131, 2424242 }
32+
local ddd = call { aaaa, bbb, ccc }
33+
local eee = calll
34+
{ 12313, 35353, fff }
35+
local fff = function() end
36+
dd.e().e().aaa = 1231
37+
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
local t = aaa, bbbb, ccc, dddd
2+
3+
local t1 = aaa, function() end, eee + ccc, dddd
4+
5+
local t2 = c2(function()
6+
end), bbbb, ccc, function() end,
7+
function(
8+
9+
)
10+
end
11+
12+
function ff()
13+
return a, b, c,
14+
d
15+
end
16+
17+
function fff2()
18+
return aaaa and
19+
cc or d, a, function() end
20+
end

0 commit comments

Comments
 (0)