28 using System.Collections.Generic;
29 using System.Text.RegularExpressions;
30 using NUnit.Framework;
31 using OpenSim.Region.ScriptEngine.Shared.CodeTools;
32 using OpenSim.Tests.Common;
34 namespace OpenSim.
Region.ScriptEngine.Shared.CodeTools.Tests
47 TestHelpers.InMethod();
49 string input =
@"default
57 "\n public void default_event_state_entry()" +
62 string output = cg.Convert(input);
63 Assert.AreEqual(expected, output);
69 TestHelpers.InMethod();
71 string input =
@"default
86 "\n public void default_event_state_entry()" +
89 "\n public void another_state_event_no_sensor()" +
94 string output = cg.Convert(input);
95 Assert.AreEqual(expected, output);
101 TestHelpers.InMethod();
103 string input =
@"default
105 at_rot_target(integer tnum, rotation targetrot, rotation ourrot)
111 "\n public void default_event_at_rot_target(LSL_Types.LSLInteger tnum, LSL_Types.Quaternion targetrot, LSL_Types.Quaternion ourrot)" +
116 string output = cg.Convert(input);
117 Assert.AreEqual(expected, output);
123 TestHelpers.InMethod();
125 string input =
@"default
127 touch_start(integer num_detected)
134 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
136 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" +
140 string output = cg.Convert(input);
141 Assert.AreEqual(expected, output);
147 TestHelpers.InMethod();
151 string input =
@"default
153 touch_start(integer num_detected)
161 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
163 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" +
168 string output = cg.Convert(input);
169 Assert.AreEqual(expected, output);
175 TestHelpers.InMethod();
177 string input =
@"default
179 touch_start(integer num_detected)
188 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
190 "\n LSL_Types.LSLString y = new LSL_Types.LSLString(\"\");" +
191 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14);" +
192 "\n y = new LSL_Types.LSLString(\"Hello\");" +
196 string output = cg.Convert(input);
197 Assert.AreEqual(expected, output);
203 TestHelpers.InMethod();
205 string input =
@"default
207 touch_start(integer num_detected)
211 y = 12 +45+20+x + 23 + 1 + x + y;
212 y = 12 + -45 + - 20 + x + 23 + -1 + x + y;
217 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)\n" +
219 " LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);\n" +
220 " LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);\n" +
221 " y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1) + x + y;\n" +
222 " y = new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23) + -new LSL_Types.LSLInteger(1) + x + y;\n" +
226 string output = cg.Convert(input);
227 Assert.AreEqual(expected, output);
233 TestHelpers.InMethod();
235 string input =
@"default
237 touch_start(integer num_detected)
239 llOwnerSay(""Testing, 1, 2, 3"");
240 llSay(0, ""I can hear you!"");
241 some_custom_function(1, 2, 3 +x, 4, ""five"", ""arguments"");
246 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
248 "\n llOwnerSay(new LSL_Types.LSLString(\"Testing, 1, 2, 3\"));" +
249 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"I can hear you!\"));" +
250 "\n some_custom_function(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3) + x, new LSL_Types.LSLInteger(4), new LSL_Types.LSLString(\"five\"), new LSL_Types.LSLString(\"arguments\"));" +
255 string output = cg.Convert(input);
256 Assert.AreEqual(expected, output);
262 TestHelpers.InMethod();
264 string input =
@"default
266 touch_start(integer num_detected)
278 y = 12 + 45 - 20 * x / 23 | 1 & x + y;
283 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
285 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
286 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" +
287 "\n y = new LSL_Types.LSLInteger(12) - new LSL_Types.LSLInteger(3);" +
288 "\n y = ((bool)(new LSL_Types.LSLInteger(12))) & ((bool)(new LSL_Types.LSLInteger(3)));" +
289 "\n y = ((bool)(new LSL_Types.LSLInteger(12))) | ((bool)(new LSL_Types.LSLInteger(3)));" +
290 "\n y = new LSL_Types.LSLInteger(12) * new LSL_Types.LSLInteger(3);" +
291 "\n y = new LSL_Types.LSLInteger(12) / new LSL_Types.LSLInteger(3);" +
292 "\n y = new LSL_Types.LSLInteger(12) | new LSL_Types.LSLInteger(3);" +
293 "\n y = new LSL_Types.LSLInteger(12) & new LSL_Types.LSLInteger(3);" +
294 "\n y = new LSL_Types.LSLInteger(12) % new LSL_Types.LSLInteger(3);" +
295 "\n y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) - new LSL_Types.LSLInteger(20) * x / new LSL_Types.LSLInteger(23) | new LSL_Types.LSLInteger(1) & x + y;" +
299 string output = cg.Convert(input);
300 Assert.AreEqual(expected, output);
306 TestHelpers.InMethod();
308 string input =
@"default
310 touch_start(integer num_detected)
327 y = 12.3 + -1.45E3 - 1.20e-2;
332 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
334 "\n LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.1);" +
335 "\n y = new LSL_Types.LSLFloat(1.123E3);" +
336 "\n y = new LSL_Types.LSLFloat(1.123e3);" +
337 "\n y = new LSL_Types.LSLFloat(1.123E+3);" +
338 "\n y = new LSL_Types.LSLFloat(1.123e+3);" +
339 "\n y = new LSL_Types.LSLFloat(1.123E-3);" +
340 "\n y = new LSL_Types.LSLFloat(1.123e-3);" +
341 "\n y = new LSL_Types.LSLFloat(.4);" +
342 "\n y = -new LSL_Types.LSLFloat(1.123E3);" +
343 "\n y = -new LSL_Types.LSLFloat(1.123e3);" +
344 "\n y = -new LSL_Types.LSLFloat(1.123E+3);" +
345 "\n y = -new LSL_Types.LSLFloat(1.123e+3);" +
346 "\n y = -new LSL_Types.LSLFloat(1.123E-3);" +
347 "\n y = -new LSL_Types.LSLFloat(1.123e-3);" +
348 "\n y = -new LSL_Types.LSLFloat(.4);" +
349 "\n y = new LSL_Types.LSLFloat(12.3) + -new LSL_Types.LSLFloat(1.45E3) - new LSL_Types.LSLFloat(1.20e-2);" +
353 string output = cg.Convert(input);
354 Assert.AreEqual(expected, output);
360 TestHelpers.InMethod();
362 string input =
@"// this test tests comments
365 touch_start(integer num_detected) // this should be stripped
367 // fill in code here...
372 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
377 string output = cg.Convert(input);
378 Assert.AreEqual(expected, output);
384 TestHelpers.InMethod();
386 string input =
@"// this test tests strings, with escaped quotes and comments in strings
389 touch_start(integer num_detected)
391 string s1 = ""this is a string."";
392 string s2 = ""this is a string ""+""with an escaped \"" inside it."";
393 s1 = s2+"" and this ""+""is a string with // comments."";
395 string onemore = ""[\^@]"";
397 string multiline = ""Good evening Sir,
399 I come from a rough area.
400 I used to be addicted to crack
401 but now I am off it and trying to stay clean.
402 That is why I am selling magazine subscriptions.""; // http://www.imdb.com/title/tt0151804/quotes
408 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
410 "\n LSL_Types.LSLString s1 = new LSL_Types.LSLString(\"this is a string.\");" +
411 "\n LSL_Types.LSLString s2 = new LSL_Types.LSLString(\"this is a string \") + new LSL_Types.LSLString(\"with an escaped \\\" inside it.\");" +
412 "\n s1 = s2 + new LSL_Types.LSLString(\" and this \") + new LSL_Types.LSLString(\"is a string with // comments.\");" +
413 "\n LSL_Types.LSLString onemore = new LSL_Types.LSLString(\"[\\^@]\");" +
414 "\n LSL_Types.LSLString multiline = new LSL_Types.LSLString(\"Good evening Sir,\\n my name is Steve.\\n I come from a rough area.\\n I used to be addicted to crack\\n but now I am off it and trying to stay clean.\\n That is why I am selling magazine subscriptions.\");" +
418 string output = cg.Convert(input);
419 Assert.AreEqual(expected, output);
425 TestHelpers.InMethod();
427 string input =
@"/* this test tests comments
432 touch_start(integer /* you can't see me! */ num_detected) /* this should be stripped */
444 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
449 string output = cg.Convert(input);
450 Assert.AreEqual(expected, output);
456 TestHelpers.InMethod();
458 string input =
@"// this test tests custom defined functions
462 return ""Hi from onefunc()!"";
472 touch_start(integer num_detected)
474 llSay(2000, onefunc());
480 "\n LSL_Types.LSLString onefunc()" +
482 "\n return new LSL_Types.LSLString(\"Hi from onefunc()!\");" +
484 "\n void twofunc(LSL_Types.LSLString s)" +
486 "\n llSay(new LSL_Types.LSLInteger(1000), s);" +
488 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
490 "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" +
495 string output = cg.Convert(input);
496 Assert.AreEqual(expected, output);
502 TestHelpers.InMethod();
504 string input =
@"// this test tests custom defined functions and global variables
507 integer globalInt = 14;
508 integer anotherGlobal = 20 * globalInt;
512 globalString = "" ...and the global!"";
515 ""onefunc()!"" + globalString;
525 touch_start(integer num_detected)
527 llSay(2000, onefunc());
533 "\n LSL_Types.LSLString globalString = new LSL_Types.LSLString(\"\");" +
534 "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" +
535 "\n LSL_Types.LSLInteger anotherGlobal = new LSL_Types.LSLInteger(20) * globalInt;" +
536 "\n LSL_Types.LSLString onefunc()" +
538 "\n globalString = new LSL_Types.LSLString(\" ...and the global!\");" +
539 "\n return new LSL_Types.LSLString(\"Hi \") + new LSL_Types.LSLString(\"from \") + new LSL_Types.LSLString(\"onefunc()!\") + globalString;" +
541 "\n void twofunc(LSL_Types.LSLString s)" +
543 "\n llSay(new LSL_Types.LSLInteger(1000), s);" +
545 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
547 "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" +
552 string output = cg.Convert(input);
553 Assert.AreEqual(expected, output);
559 TestHelpers.InMethod();
561 string input =
@"// this test tests +=, -=, *=, /=, %=
564 integer globalInt = 14;
566 string onefunc(string addition)
570 globalString += addition;
573 ""onefunc()! "" + globalString;
578 touch_start(integer num_detected)
580 llSay(2000, onefunc());
590 "\n LSL_Types.LSLString globalString = new LSL_Types.LSLString(\"\");" +
591 "\n LSL_Types.LSLInteger globalInt = new LSL_Types.LSLInteger(14);" +
592 "\n LSL_Types.LSLString onefunc(LSL_Types.LSLString addition)" +
594 "\n globalInt -= new LSL_Types.LSLInteger(2);" +
595 "\n globalString += addition;" +
596 "\n return new LSL_Types.LSLString(\"Hi \") + new LSL_Types.LSLString(\"from \") + new LSL_Types.LSLString(\"onefunc()! \") + globalString;" +
598 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
600 "\n llSay(new LSL_Types.LSLInteger(2000), onefunc());" +
601 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2);" +
602 "\n x *= new LSL_Types.LSLInteger(3);" +
603 "\n x /= new LSL_Types.LSLInteger(14) + -new LSL_Types.LSLInteger(2);" +
604 "\n x %= new LSL_Types.LSLInteger(10);" +
608 string output = cg.Convert(input);
609 Assert.AreEqual(expected, output);
615 TestHelpers.InMethod();
617 string input =
@"default
619 touch_start(integer num_detected)
621 vector y = <1.2, llGetMeAFloat(), 4.4>;
622 rotation x = <0.1, 0.1, one + 2, 0.9>;
624 y = <0.1, 0.1, 1.1 - three - two+eight*8>;
629 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
631 "\n LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4));" +
632 "\n LSL_Types.Quaternion x = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.1), one + new LSL_Types.LSLInteger(2), new LSL_Types.LSLFloat(0.9));" +
633 "\n y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(1.1) - three - two + eight * new LSL_Types.LSLInteger(8));" +
637 string output = cg.Convert(input);
638 Assert.AreEqual(expected, output);
644 TestHelpers.InMethod();
646 string input =
@"default
648 touch_start(integer num_detected)
650 vector y = <1.2, llGetMeAFloat(), 4.4>;
657 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
659 "\n LSL_Types.Vector3 y = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.2), llGetMeAFloat(), new LSL_Types.LSLFloat(4.4));" +
660 "\n x = y.x + new LSL_Types.LSLFloat(1.1);" +
661 "\n y.x = new LSL_Types.LSLFloat(1.1);" +
665 string output = cg.Convert(input);
666 Assert.AreEqual(expected, output);
672 TestHelpers.InMethod();
674 string input =
@"default
676 touch_start(integer num_detected)
680 y = 12 +45+20+x + (23 + 1) + x + y;
681 y = (12 + -45 + -20 + x + 23 )+ -1 + x + y;
686 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
688 "\n LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);" +
689 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" +
690 "\n y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x + (new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1)) + x + y;" +
691 "\n y = (new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x + new LSL_Types.LSLInteger(23)) + -new LSL_Types.LSLInteger(1) + x + y;" +
695 string output = cg.Convert(input);
696 Assert.AreEqual(expected, output);
702 TestHelpers.InMethod();
704 string input =
@"// here we'll test the ++ and -- operators
708 touch_start(integer num_detected)
712 y = 12 +45+20+x++ + (23 + 1) + ++x + -- y;
713 y = (12 + -45 + -20 + x-- + 23 )+ -1 + x -- + ++y;
718 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
720 "\n LSL_Types.LSLInteger y = -new LSL_Types.LSLInteger(3);" +
721 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(14) + new LSL_Types.LSLInteger(6);" +
722 "\n y = new LSL_Types.LSLInteger(12) + new LSL_Types.LSLInteger(45) + new LSL_Types.LSLInteger(20) + x++ + (new LSL_Types.LSLInteger(23) + new LSL_Types.LSLInteger(1)) + ++x + --y;" +
723 "\n y = (new LSL_Types.LSLInteger(12) + -new LSL_Types.LSLInteger(45) + -new LSL_Types.LSLInteger(20) + x-- + new LSL_Types.LSLInteger(23)) + -new LSL_Types.LSLInteger(1) + x-- + ++y;" +
727 string output = cg.Convert(input);
728 Assert.AreEqual(expected, output);
734 TestHelpers.InMethod();
736 string input =
@"// testing lists
740 touch_start(integer num_detected)
743 list m = [1, two, ""three"", <4.0, 4.0, 4.0>, 5 + 5];
744 llCallSomeFunc(1, llAnotherFunc(), [1, 2, 3]);
749 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
751 "\n LSL_Types.list l = new LSL_Types.list();" +
752 "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), two, new LSL_Types.LSLString(\"three\"), new LSL_Types.Vector3(new LSL_Types.LSLFloat(4.0), new LSL_Types.LSLFloat(4.0), new LSL_Types.LSLFloat(4.0)), new LSL_Types.LSLInteger(5) + new LSL_Types.LSLInteger(5));" +
753 "\n llCallSomeFunc(new LSL_Types.LSLInteger(1), llAnotherFunc(), new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3)));" +
757 string output = cg.Convert(input);
758 Assert.AreEqual(expected, output);
764 TestHelpers.InMethod();
767 string input =
@"// let's test if statements
771 touch_start(integer num_detected)
775 if (x) llSay(0, ""Hello"");
783 if (f(x)) llSay(0, ""f(x) is true"");
784 else llSay(0, ""f(x) is false"");
786 if (x + y) llSay(0, ""x + y is true"");
787 else if (y - x) llSay(0, ""y - x is true"");
788 else llSay(0, ""Who needs x and y anyway?"");
790 if (x * y) llSay(0, ""x * y is true"");
793 llSay(0, ""uh-oh, y / x is true, exiting"");
796 else llSay(0, ""Who needs x and y anyway?"");
798 // and now for my last trick
799 if (x % y) llSay(0, ""x is true"");
800 else if (y & x) llSay(0, ""y is true"");
801 else if (z | x) llSay(0, ""z is true"");
802 else if (a * (b + x)) llSay(0, ""a is true"");
803 else if (b) llSay(0, ""b is true"");
804 else if (v) llSay(0, ""v is true"");
805 else llSay(0, ""Everything is lies!"");
810 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
812 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
814 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" +
815 "\n if (new LSL_Types.LSLInteger(1))" +
817 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" +
818 "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" +
822 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"f(x) is true\"));" +
824 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"f(x) is false\"));" +
826 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x + y is true\"));" +
829 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y - x is true\"));" +
831 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
833 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x * y is true\"));" +
837 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"uh-oh, y / x is true, exiting\"));" +
841 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
843 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
846 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" +
849 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" +
851 "\n if (a * (b + x))" +
852 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" +
855 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"b is true\"));" +
858 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"v is true\"));" +
860 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Everything is lies!\"));" +
864 string output = cg.Convert(input);
865 Assert.AreEqual(expected, output);
871 TestHelpers.InMethod();
873 string input =
@"// let's test complex logical expressions
877 touch_start(integer num_detected)
882 if (x && y) llSay(0, ""Hello"");
890 if (x && y || z) llSay(0, ""x is true"");
891 else llSay(0, ""x is false"");
893 if (x == y) llSay(0, ""x is true"");
894 else if (y < x) llSay(0, ""y is true"");
895 else llSay(0, ""Who needs x and y anyway?"");
897 if (x > y) llSay(0, ""x is true"");
900 llSay(0, ""uh-oh, y is true, exiting"");
903 else llSay(0, ""Who needs x and y anyway?"");
905 // and now for my last trick
906 if (x >= y) llSay(0, ""x is true"");
907 else if (y != x) llSay(0, ""y is true"");
908 else if (!z) llSay(0, ""z is true"");
909 else if (!(a && b)) llSay(0, ""a is true"");
910 else if (b) llSay(0, ""b is true"");
911 else if (v) llSay(0, ""v is true"");
912 else llSay(0, ""Everything is lies!"");
917 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
919 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
920 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
921 "\n if (((bool)(x)) & ((bool)(y)))" +
922 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hello\"));" +
923 "\n if (((bool)(x)) | ((bool)(y)))" +
925 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Hi\"));" +
926 "\n LSL_Types.LSLInteger r = new LSL_Types.LSLInteger(3);" +
929 "\n if (((bool)(((bool)(x)) & ((bool)(y)))) | ((bool)(z)))" +
930 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
932 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is false\"));" +
934 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
937 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" +
939 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
941 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
945 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"uh-oh, y is true, exiting\"));" +
949 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Who needs x and y anyway?\"));" +
951 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"x is true\"));" +
954 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"y is true\"));" +
957 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"z is true\"));" +
959 "\n if (!(((bool)(a)) & ((bool)(b))))" +
960 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"a is true\"));" +
963 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"b is true\"));" +
966 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"v is true\"));" +
968 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Everything is lies!\"));" +
972 string output = cg.Convert(input);
973 Assert.AreEqual(expected, output);
979 TestHelpers.InMethod();
981 string input =
@"// let's test while loops
985 touch_start(integer num_detected)
990 while (x) llSay(0, ""To infinity, and beyond!"");
991 while (0 || (x && 0))
993 llSay(0, ""Never say never."");
1000 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1002 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
1003 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
1005 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"To infinity, and beyond!\"));" +
1006 "\n while (((bool)(new LSL_Types.LSLInteger(0))) | ((bool)((((bool)(x)) & ((bool)(new LSL_Types.LSLInteger(0)))))))" +
1008 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Never say never.\"));" +
1014 string output = cg.Convert(input);
1015 Assert.AreEqual(expected, output);
1021 TestHelpers.InMethod();
1023 string input =
@"// let's test do-while loops
1027 touch_start(integer num_detected)
1032 do llSay(0, ""And we're doing..."");
1037 llSay(0, ""I like it here. I wish we could stay here forever."");
1044 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1046 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
1047 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
1049 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"And we're doing...\"));" +
1053 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"I like it here. I wish we could stay here forever.\"));" +
1060 string output = cg.Convert(input);
1061 Assert.AreEqual(expected, output);
1067 TestHelpers.InMethod();
1069 string input =
@"// let's test for loops
1073 touch_start(integer num_detected)
1078 for (x = 10; x >= 0; x--)
1080 llOwnerSay(""Launch in T minus "" + x);
1081 IncreaseRocketPower();
1084 for (x = 0, y = 6; y > 0 && x != y; x++, y--) llOwnerSay(""Hi "" + x + "", "" + y);
1085 for (x = 0, y = 6; ! y; x++,y--) llOwnerSay(""Hi "" + x + "", "" + y);
1090 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1092 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
1093 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
1094 "\n for (x = new LSL_Types.LSLInteger(10); x >= new LSL_Types.LSLInteger(0); x--)" +
1096 "\n llOwnerSay(new LSL_Types.LSLString(\"Launch in T minus \") + x);" +
1097 "\n IncreaseRocketPower();" +
1099 "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); ((bool)(y > new LSL_Types.LSLInteger(0))) & ((bool)(x != y)); x++, y--)" +
1100 "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" +
1101 "\n for (x = new LSL_Types.LSLInteger(0), y = new LSL_Types.LSLInteger(6); !y; x++, y--)" +
1102 "\n llOwnerSay(new LSL_Types.LSLString(\"Hi \") + x + new LSL_Types.LSLString(\", \") + y);" +
1106 string output = cg.Convert(input);
1107 Assert.AreEqual(expected, output);
1113 TestHelpers.InMethod();
1115 string input =
@"// a curious feature of LSL that allows floats to be defined with a trailing dot
1119 touch_start(integer num_detected)
1134 y = 12. + -1.E3 - 1.e-2;
1135 vector v = <0.,0.,0.>;
1140 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1142 "\n LSL_Types.LSLFloat y = new LSL_Types.LSLFloat(1.0);" +
1143 "\n y = new LSL_Types.LSLFloat(1.0E3);" +
1144 "\n y = new LSL_Types.LSLFloat(1.0e3);" +
1145 "\n y = new LSL_Types.LSLFloat(1.0E+3);" +
1146 "\n y = new LSL_Types.LSLFloat(1.0e+3);" +
1147 "\n y = new LSL_Types.LSLFloat(1.0E-3);" +
1148 "\n y = new LSL_Types.LSLFloat(1.0e-3);" +
1149 "\n y = -new LSL_Types.LSLFloat(1.0E3);" +
1150 "\n y = -new LSL_Types.LSLFloat(1.0e3);" +
1151 "\n y = -new LSL_Types.LSLFloat(1.0E+3);" +
1152 "\n y = -new LSL_Types.LSLFloat(1.0e+3);" +
1153 "\n y = -new LSL_Types.LSLFloat(1.0E-3);" +
1154 "\n y = -new LSL_Types.LSLFloat(1.0e-3);" +
1155 "\n y = new LSL_Types.LSLFloat(12.0) + -new LSL_Types.LSLFloat(1.0E3) - new LSL_Types.LSLFloat(1.0e-2);" +
1156 "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" +
1160 string output = cg.Convert(input);
1161 Assert.AreEqual(expected, output);
1167 TestHelpers.InMethod();
1169 string input =
@"// let's test a few more operators
1173 touch_start(integer num_detected)
1186 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1188 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(2);" +
1189 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(1);" +
1190 "\n LSL_Types.LSLInteger z = x ^ y;" +
1192 "\n x = ~(((bool)(y)) & ((bool)(z)));" +
1198 string output = cg.Convert(input);
1199 Assert.AreEqual(expected, output);
1205 TestHelpers.InMethod();
1207 string input =
@"// let's test typecasts
1211 touch_start(integer num_detected)
1218 s = (string) <0., 0., 0.>;
1219 s = (string) <1., 1., 1., 1.>;
1220 s = (integer) ""1"";
1221 s = (string) llSomethingThatReturnsInteger();
1223 s = (string) (x ^ y | (z && l)) + (string) (x + y - 13);
1224 llOwnerSay(""s is: "" + s);
1229 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1231 "\n LSL_Types.LSLString s = new LSL_Types.LSLString(\"\");" +
1232 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(1);" +
1233 "\n s = (LSL_Types.LSLString) (x++);" +
1234 "\n s = (LSL_Types.LSLString) (x);" +
1235 "\n s = (LSL_Types.LSLString) (new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0)));" +
1236 "\n s = (LSL_Types.LSLString) (new LSL_Types.Quaternion(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(1.0)));" +
1237 "\n s = (LSL_Types.LSLInteger) (new LSL_Types.LSLString(\"1\"));" +
1238 "\n s = (LSL_Types.LSLString) (llSomethingThatReturnsInteger());" +
1239 "\n s = (LSL_Types.LSLString) (new LSL_Types.LSLInteger(134));" +
1240 "\n s = (LSL_Types.LSLString) (x ^ y | (((bool)(z)) & ((bool)(l)))) + (LSL_Types.LSLString) (x + y - new LSL_Types.LSLInteger(13));" +
1241 "\n llOwnerSay(new LSL_Types.LSLString(\"s is: \") + s);" +
1245 string output = cg.Convert(input);
1246 Assert.AreEqual(expected, output);
1252 TestHelpers.InMethod();
1254 string input =
@"// let's test states
1258 touch_start(integer num_detected)
1260 llSay(0, ""Going to state 'statetwo'"");
1269 llSay(0, ""Going to the default state"");
1275 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1277 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Going to state 'statetwo'\"));" +
1278 "\n state(\"statetwo\");" +
1280 "\n public void statetwo_event_state_entry()" +
1282 "\n llSay(new LSL_Types.LSLInteger(0), new LSL_Types.LSLString(\"Going to the default state\"));" +
1283 "\n state(\"default\");" +
1287 string output = cg.Convert(input);
1288 Assert.AreEqual(expected, output);
1294 TestHelpers.InMethod();
1296 string input =
@"// let's test hex integers
1300 touch_start(integer num_detected)
1303 integer x = 0x2f34B;
1304 integer x = 0x2F34b;
1305 integer x = 0x2F34B;
1306 integer x = 0x2f34b;
1311 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1313 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x23);" +
1314 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34B);" +
1315 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34b);" +
1316 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2F34B);" +
1317 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0x2f34b);" +
1321 string output = cg.Convert(input);
1322 Assert.AreEqual(expected, output);
1328 TestHelpers.InMethod();
1330 string input =
@"// let's test jumps
1334 touch_start(integer num_detected)
1337 llOwnerSay(""Uh oh, the jump didn't work"");
1339 llOwnerSay(""After the jump"");
1344 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1347 "\n llOwnerSay(new LSL_Types.LSLString(\"Uh oh, the jump didn't work\"));" +
1348 "\n here: NoOp();" +
1349 "\n llOwnerSay(new LSL_Types.LSLString(\"After the jump\"));" +
1353 string output = cg.Convert(input);
1354 Assert.AreEqual(expected, output);
1360 TestHelpers.InMethod();
1362 string input =
@"// let's test implicitly initializing variables
1366 touch_start(integer num_detected)
1368 integer i; integer j = 14;
1369 float f; float g = 14.0;
1370 string s; string t = ""Hi there"";
1371 list l; list m = [1, 2, 3];
1372 vector v; vector w = <1.0, 0.1, 0.5>;
1373 rotation r; rotation u = <0.8, 0.7, 0.6, llSomeFunc()>;
1374 key k; key n = ""ping"";
1379 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1381 "\n LSL_Types.LSLInteger i = new LSL_Types.LSLInteger(0);" +
1382 "\n LSL_Types.LSLInteger j = new LSL_Types.LSLInteger(14);" +
1383 "\n LSL_Types.LSLFloat f = new LSL_Types.LSLFloat(0.0);" +
1384 "\n LSL_Types.LSLFloat g = new LSL_Types.LSLFloat(14.0);" +
1385 "\n LSL_Types.LSLString s = new LSL_Types.LSLString(\"\");" +
1386 "\n LSL_Types.LSLString t = new LSL_Types.LSLString(\"Hi there\");" +
1387 "\n LSL_Types.list l = new LSL_Types.list();" +
1388 "\n LSL_Types.list m = new LSL_Types.list(new LSL_Types.LSLInteger(1), new LSL_Types.LSLInteger(2), new LSL_Types.LSLInteger(3));" +
1389 "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" +
1390 "\n LSL_Types.Vector3 w = new LSL_Types.Vector3(new LSL_Types.LSLFloat(1.0), new LSL_Types.LSLFloat(0.1), new LSL_Types.LSLFloat(0.5));" +
1391 "\n LSL_Types.Quaternion r = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0), new LSL_Types.LSLFloat(0.0));" +
1392 "\n LSL_Types.Quaternion u = new LSL_Types.Quaternion(new LSL_Types.LSLFloat(0.8), new LSL_Types.LSLFloat(0.7), new LSL_Types.LSLFloat(0.6), llSomeFunc());" +
1393 "\n LSL_Types.LSLString k = new LSL_Types.LSLString(\"\");" +
1394 "\n LSL_Types.LSLString n = new LSL_Types.LSLString(\"ping\");" +
1398 string output = cg.Convert(input);
1399 Assert.AreEqual(expected, output);
1405 TestHelpers.InMethod();
1407 string input =
@"// let's test x = y = 5 type expressions
1411 touch_start(integer num_detected)
1417 llOwnerSay(""x is: "" + (string) x + "", y is: "" + (string) y);
1422 "\n public void default_event_touch_start(LSL_Types.LSLInteger num_detected)" +
1424 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" +
1425 "\n LSL_Types.LSLInteger y = new LSL_Types.LSLInteger(0);" +
1426 "\n x = y = new LSL_Types.LSLInteger(5);" +
1427 "\n x += y -= new LSL_Types.LSLInteger(5);" +
1428 "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x) + new LSL_Types.LSLString(\", y is: \") + (LSL_Types.LSLString) (y));" +
1432 string output = cg.Convert(input);
1433 Assert.AreEqual(expected, output);
1439 TestHelpers.InMethod();
1441 string input =
@"// let's test unary expressions some more
1447 vector v = <x,y,-0.5>;
1452 "\n public void default_event_state_entry()" +
1454 "\n LSL_Types.Vector3 v = new LSL_Types.Vector3(x, y, -new LSL_Types.LSLFloat(0.5));" +
1458 string output = cg.Convert(input);
1459 Assert.AreEqual(expected, output);
1465 TestHelpers.InMethod();
1467 string input =
@"// let's test unary expressions some more
1473 vector v = llGetPos();
1483 "\n public void default_event_state_entry()" +
1485 "\n LSL_Types.Vector3 v = llGetPos();" +
1486 "\n v.z += new LSL_Types.LSLInteger(4);" +
1487 "\n v.z -= new LSL_Types.LSLInteger(4);" +
1488 "\n v.z *= new LSL_Types.LSLInteger(4);" +
1489 "\n v.z /= new LSL_Types.LSLInteger(4);" +
1490 "\n v.z %= new LSL_Types.LSLInteger(4);" +
1494 string output = cg.Convert(input);
1495 Assert.AreEqual(expected, output);
1501 TestHelpers.InMethod();
1503 string input =
@"default
1512 "\n public void default_event_state_entry()" +
1514 "\n while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" +
1519 string output = cg.Convert(input);
1520 Assert.AreEqual(expected, output);
1526 TestHelpers.InMethod();
1528 string input =
@"default
1538 "\n public void default_event_state_entry()" +
1542 "\n while (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0));" +
1546 string output = cg.Convert(input);
1547 Assert.AreEqual(expected, output);
1553 TestHelpers.InMethod();
1555 string input =
@"default
1564 "\n public void default_event_state_entry()" +
1566 "\n if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" +
1571 string output = cg.Convert(input);
1572 Assert.AreEqual(expected, output);
1578 TestHelpers.InMethod();
1580 string input =
@"default
1590 "\n public void default_event_state_entry()" +
1592 "\n if (new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0))" +
1599 string output = cg.Convert(input);
1600 Assert.AreEqual(expected, output);
1606 TestHelpers.InMethod();
1608 string input =
@"default
1612 for (x = 4; 1<0; x += 2);
1617 "\n public void default_event_state_entry()" +
1619 "\n for (x = new LSL_Types.LSLInteger(4); new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" +
1624 string output = cg.Convert(input);
1625 Assert.AreEqual(expected, output);
1631 TestHelpers.InMethod();
1633 string input =
@"default
1638 for (; 1<0; x += 2);
1643 "\n public void default_event_state_entry()" +
1645 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(4);" +
1646 "\n for (; new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" +
1651 string output = cg.Convert(input);
1652 Assert.AreEqual(expected, output);
1658 TestHelpers.InMethod();
1660 string input =
@"default
1665 for (x; 1<0; x += 2);
1670 "\n public void default_event_state_entry()" +
1672 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(4);" +
1673 "\n for (; new LSL_Types.LSLInteger(1) < new LSL_Types.LSLInteger(0); x += new LSL_Types.LSLInteger(2))" +
1678 string output = cg.Convert(input);
1679 Assert.AreEqual(expected, output);
1685 TestHelpers.InMethod();
1687 string input =
@"default
1693 while (x = 14) llOwnerSay(""x is: "" + (string) x);
1695 if (x = 24) llOwnerSay(""x is: "" + (string) x);
1698 llOwnerSay(""x is: "" + (string) x);
1704 "\n public void default_event_state_entry()" +
1706 "\n LSL_Types.LSLInteger x = new LSL_Types.LSLInteger(0);" +
1707 "\n while (x = new LSL_Types.LSLInteger(14))" +
1708 "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" +
1709 "\n if (x = new LSL_Types.LSLInteger(24))" +
1710 "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" +
1712 "\n llOwnerSay(new LSL_Types.LSLString(\"x is: \") + (LSL_Types.LSLString) (x));" +
1713 "\n while (x = new LSL_Types.LSLInteger(44));" +
1717 string output = cg.Convert(input);
1718 Assert.AreEqual(expected, output);
1724 TestHelpers.InMethod();
1726 string input =
@"default
1730 list l = [""hello""];
1731 l = (l=[]) + l + ""world"";
1736 "\n public void default_event_state_entry()" +
1738 "\n LSL_Types.list l = new LSL_Types.list(new LSL_Types.LSLString(\"hello\"));" +
1739 "\n l = (l = new LSL_Types.list()) + l + new LSL_Types.LSLString(\"world\");" +
1743 string output = cg.Convert(input);
1744 Assert.AreEqual(expected, output);
1750 TestHelpers.InMethod();
1752 bool gotException =
false;
1754 string input =
@"default
1767 catch (System.Exception e)
1771 Assert.AreEqual(
"(5,4) syntax error", e.Message);
1772 gotException =
true;
1775 Assert.That(gotException, Is.True);
1781 TestHelpers.InMethod();
1783 bool gotException =
false;
1785 string input =
@"default
1789 for (integer x = 0; x < 10; x++) llOwnerSay(""x is: "" + (string) x);
1798 catch (System.Exception e)
1801 Assert.AreEqual(
"(4,13) syntax error", e.Message);
1803 gotException =
true;
1806 Assert.That(gotException, Is.True);