summaryrefslogtreecommitdiff
path: root/sw/qa/uitest/librelogo
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2018-11-05 22:50:40 +0100
committerLászló Németh <nemeth@numbertext.org>2018-11-06 08:32:56 +0100
commitb274e879bdbed85c9373e90e6998cabe22b5bd3a (patch)
tree604efbe2d00dc6bd2729fe178e453db4d6e2eb7d /sw/qa/uitest/librelogo
parent97ebc98f0e956712d242e13f15531742f844a738 (diff)
LibreLogo: function calls and definitions can be in any order
with Logo syntax, too. Mutual recursion, for example drawing dragon curve (see in the unit test of the commit) doesn't need Python syntax any more to call the function before its definition. Change-Id: I93426a8c5be394fb4f1203e0490f7fa8d8491597 Reviewed-on: https://gerrit.libreoffice.org/62926 Tested-by: Jenkins Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sw/qa/uitest/librelogo')
-rw-r--r--sw/qa/uitest/librelogo/compile.py4
-rw-r--r--sw/qa/uitest/librelogo/run.py29
2 files changed, 33 insertions, 0 deletions
diff --git a/sw/qa/uitest/librelogo/compile.py b/sw/qa/uitest/librelogo/compile.py
index 73c2e8fbaaa6..79a297ef1593 100644
--- a/sw/qa/uitest/librelogo/compile.py
+++ b/sw/qa/uitest/librelogo/compile.py
@@ -98,6 +98,8 @@ class LibreLogoCompileTest(UITestCase):
("a=(SIN 102) + (COS 102)", "a=(sin(102)) + (cos(102))"),
("a=SIN 103 + COS 103 - SQRT 103", "a=sin(103 + cos(103 - sqrt(103)))"),
("a=(SIN 104 + COS 104) - SQRT 104", "a=(sin(104 + cos(104))) - sqrt(104)"),
+ # SIN(x) is Python-like, SIN (x) is Logo-like syntax
+ ("a=SIN(105) + COS (105) - SQRT 105", "a=sin(105) + cos((105) - sqrt(105))"),
("a=COUNT [1, 2, 3]", "a=len([1, 2, 3])"),
("PRINT COUNT [1, 2, 3]", "Print(len([1, 2, 3]))"),
("PRINT 'TEXT: ' + 'CHAR'[0] + ' TEXT2: ' + variable[-1]", "Print(u'TEXT: ' + u'CHAR'[0] + u' TEXT2: ' + variable[-1])"),
@@ -119,6 +121,8 @@ class LibreLogoCompileTest(UITestCase):
("TO f x y z\nLABEL x+y+z\nEND\nf len [1, cos 2, [65]] sqrt len [1, 2, 3, 4] sin 90 * cos 270", "global f\ndef f(x, y, z):\n __checkhalt__()\n %s\n label(x+y+z)\n %s\n%s\nf(len([1, cos(2), [65]]), sqrt(len([1, 2, 3, 4])), sin(90 * cos(270)))" % (((self.LS),)*3)),
("TO f x y z\nLABEL x+y+z\nEND\nf len([1, cos 2, [65]]) sqrt(len [1, 2, 3, 4]) sin(90) * cos 270", "global f\ndef f(x, y, z):\n __checkhalt__()\n %s\n label(x+y+z)\n %s\n%s\nf(len([1, cos(2), [65]]), sqrt(len([1, 2, 3, 4])), sin(90) * cos(270))" % (((self.LS),)*3)),
("TO f x y z\nLABEL x+y+z\nEND\nf (len [1, cos 2, [65]]) (sqrt len [1, 2, 3, 4]) (sin 90) * (cos 270)", "global f\ndef f(x, y, z):\n __checkhalt__()\n %s\n label(x+y+z)\n %s\n%s\nf((len([1, cos(2), [65]])), (sqrt(len([1, 2, 3, 4]))), (sin(90)) * (cos(270)))" % (((self.LS),)*3)),
+ # arbitrary order of function definitions and calls
+ ("f 1 1 f 2 2\nTO f x y\nPRINT x + y\nEND", "global f\nf(1, 1)\nf(2, 2)\n%s\ndef f(x, y):\n __checkhalt__()\n %s\n Print(x + y)\n %s" % (((self.LS),)*3)),
):
compiled = xCompile.invoke((test[0],), (), ())[0]
self.assertEqual(test[1], re.sub(r'(\n| +\n)+', '\n', re.sub(r'\( ', '(', compiled)).strip())
diff --git a/sw/qa/uitest/librelogo/run.py b/sw/qa/uitest/librelogo/run.py
index 5d36c5d14e7b..5d64e1bea152 100644
--- a/sw/qa/uitest/librelogo/run.py
+++ b/sw/qa/uitest/librelogo/run.py
@@ -69,6 +69,35 @@ class LibreLogoTest(UITestCase):
# first paragraph is empty (for working page break)
self.assertEqual(document.Text.createEnumeration().nextElement().String, "")
+ # function definitions and calls can be in arbitrary order
+ document.Text.String = """
+; dragon curve
+TO x n
+IF n = 0 [ STOP ]
+x n-1
+RIGHT 90
+y n-1 ; it worked only as "y(n-1)"
+FORWARD 10
+END
+
+TO y n
+IF n = 0 [ STOP ]
+FORWARD 10
+x n-1
+LEFT 90
+y n-1
+END
+
+PICTURE ; start new line draw
+x 3 ; draw only a few levels
+"""
+ self.logo("run")
+ # wait for LibreLogo program termination
+ while xIsAlive.invoke((), (), ())[0]:
+ pass
+ # new shape + previous two ones = 3
+ self.assertEqual(document.DrawPage.getCount(), 3)
+
self.ui_test.close_doc()
# vim: set shiftwidth=4 softtabstop=4 expandtab: