Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 6193589

Browse files
committed
[[ Tests ]] Add script editor indentation tests
1 parent f2f3a92 commit 6193589

8 files changed

Lines changed: 246 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
repeat \
2+
forever
3+
-- code
4+
end repeat
5+
6+
switch \
7+
tVar
8+
case "foo"
9+
-- code
10+
break
11+
case \
12+
"foo"
13+
-- code
14+
break
15+
default
16+
-- code
17+
break
18+
end switch
19+
20+
try
21+
-- code
22+
catch \
23+
tError
24+
-- code
25+
end try
26+
27+
if something \
28+
then
29+
-- code
30+
end if
31+
32+
put "foo" &\
33+
"bar"
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
if (gDatf[tPost,i] <> "") and \
2+
(((gPoly[tPost] = "") and (gSurf[tPost] = gSurg[tPost,i])) or ((gPoly[tPost] <> "") and (gPoly[tPost] = gPolz[tPost,i]))) and \
3+
(gFra1[tPost,i] <> "") and (gFra2[tPost,i] <> "") and \
4+
((gPos2[tPost,i] <> "") or (quote is in gPos2[tPost,i])) and ((gPos3[tPost,i] <> "") or (quote is in gPos3[tPost,i])) and ((gPos4[tPost,i] <> "") or (quote is in gPos4[tPost,i])) and ((gPos5[tPost,i] <> "") or (quote is in gPos5[tPost,i])) and \
5+
(abs(gDist[tPost]) - abs(gDisu[tPost,i]) <= 0) and \ -- (abs(abs(gDist[tPost]) - abs(gDisu[tPost,i])) <= 440)
6+
(gBea5[tPost,i] <= 2.0) then
7+
put tab & gDatf[tPost,i] & tab & gPos2[tPost,i] & gPos3[tPost,i] & gPos4[tPost,i] & gPos5[tPost,i] & tab & gSco1[tPost,i] & tab & gSco2[tPost,i] & tab & gSco3[tPost,i] & tab & gOdds[tPost] & return after fld "Indey"
8+
end if
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
on Foo pParam
2+
-- code
3+
end Foo
4+
5+
command Foo pParam
6+
-- code
7+
end Foo
8+
9+
private command Foo pParam
10+
-- code
11+
end Foo
12+
13+
private on Foo pParam
14+
-- code
15+
end Foo
16+
17+
before Foo pParam
18+
-- code
19+
end Foo
20+
21+
after Foo pParam
22+
-- code
23+
end Foo
24+
25+
function Foo pParam
26+
-- code
27+
end Foo
28+
29+
private function Foo pParam
30+
-- code
31+
end Foo
32+
33+
setProp Foo pParam
34+
-- code
35+
end Foo
36+
37+
getProp Foo pParam
38+
-- code
39+
end Foo
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
if foo() then
2+
-- code
3+
else if bar() then
4+
-- code
5+
else
6+
-- code
7+
end if
8+
9+
if foo()
10+
then -- code
11+
else if bar() then
12+
-- code
13+
else
14+
-- code
15+
end if
16+
17+
if foo()
18+
then code
19+
else if bar() then
20+
-- code
21+
else code
22+
23+
if foo()
24+
then code
25+
else code
26+
27+
if foo() then code else code
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
repeat forever
2+
-- code
3+
end repeat
4+
5+
repeat while foo()
6+
-- code
7+
end repeat
8+
9+
repeat until foo()
10+
-- code
11+
end repeat
12+
13+
repeat 3
14+
-- code
15+
end repeat
16+
17+
repeat for 3
18+
-- code
19+
end repeat
20+
21+
repeat for 3 times
22+
-- code
23+
end repeat
24+
25+
repeat 3 times
26+
-- code
27+
end repeat
28+
29+
repeat with X = 1 to 5
30+
-- code
31+
end repeat
32+
33+
repeat with X = 1 to 5 step 2
34+
-- code
35+
end repeat
36+
37+
repeat with X = 5 down to 1
38+
-- code
39+
end repeat
40+
41+
repeat with X = 5 down to 1 step 2
42+
-- code
43+
end repeat
44+
45+
repeat for each line tLine in tFoo
46+
-- code
47+
end repeat
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
switch tFoo
2+
case "foo"
3+
-- code
4+
break
5+
default
6+
-- code
7+
break
8+
end switch
9+
10+
switch
11+
case tFoo begins with "foo"
12+
-- code
13+
break
14+
default
15+
-- code
16+
break
17+
end switch
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
try
2+
-- code
3+
catch tError
4+
-- code
5+
finally
6+
-- code
7+
end try
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
script "ScriptEditorIndentation"
2+
/*
3+
Copyright (C) 2017 LiveCode Ltd.
4+
5+
This file is part of LiveCode.
6+
7+
LiveCode is free software; you can redistribute it and/or modify it under
8+
the terms of the GNU General Public License v3 as published by the Free
9+
Software Foundation.
10+
11+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
12+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
18+
19+
local sStack
20+
21+
on TestSetup
22+
local tBehavior
23+
put TestGetIDERepositoryPath() & "/Toolset/palettes/script editor/behaviors/revsecommoneditorbehavior.livecodescript" into tBehavior
24+
put the name of stack tBehavior into sStack
25+
end TestSetup
26+
27+
on TestIndents
28+
set the itemDelimiter to slash
29+
local tPath
30+
put item 1 to -2 of the effective filename of me & "/_indentation_tests" into tPath
31+
set the itemDelimiter to "."
32+
repeat for each line tFile in files(tPath)
33+
if tFile begins with "." then
34+
next repeat
35+
end if
36+
37+
local tScript
38+
put textDecode(url ("binfile:" & tPath & "/" & tFile),"UTF8") into tScript
39+
-- normalise the snippet
40+
if the last char of tScript is not return then
41+
put return after tScript
42+
end if
43+
replace tab with " " in tScript
44+
45+
-- strip leading whitespace
46+
local tUnindented
47+
put replaceText(tScript, "\n +", return) into tUnindented
48+
put replaceText(tUnindented, "^ +", "") into tUnindented
49+
50+
dispatch "scriptFormatSnippet" to sStack with tUnindented
51+
local tResult
52+
put the result into tResult
53+
if the last char of tResult is not return then
54+
put return after tResult
55+
end if
56+
TestAssert "script snippet indented correctly:" && item 1 of tFile, tResult is tScript
57+
if tResult is not tScript then
58+
repeat with tIndex=1 to the number of lines of tResult
59+
if line tIndex of tResult is not line tIndex of tScript then
60+
put "* " before line tIndex of tResult
61+
else
62+
put " " before line tIndex of tResult
63+
end if
64+
end repeat
65+
TestDiagnostic tResult
66+
end if
67+
end repeat
68+
end TestIndents

0 commit comments

Comments
 (0)