-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed branching for module _init zone
- Loading branch information
Showing
7 changed files
with
142 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package mihailris.oiscript; | ||
|
||
import mihailris.oiscript.exceptions.ParsingException; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class OiScriptTest { | ||
@Test | ||
public void evalTest() throws ParsingException { | ||
assertEquals(OiScript.eval("20 - 5 * 3.2"), 4.0); | ||
assertEquals(OiScript.eval("2 * 3 == 6"), true); | ||
assertTrue(OiScript.eval("[]") instanceof List); | ||
assertEquals(OiScript.eval("sqrt(81)"), 9.0); | ||
} | ||
|
||
@Test | ||
public void scriptTest() throws ParsingException { | ||
String sourceCode = | ||
"a = 5\n" + | ||
"b = 12\n" + | ||
"if a > b:\n" + | ||
" print(a)\n" + | ||
"else:\n" + | ||
" print(b)\n"; | ||
OiObject globals = new OiObject(); | ||
OiObject scripts = new OiObject(); | ||
Script script = OiScript.load("test.oi", sourceCode, globals, scripts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,7 @@ | ||
func tostr(self): | ||
return "User(name: "+cat(self.name)+", age: "+self.age+")" | ||
a = 5 | ||
b = 10 | ||
|
||
func User_init(self, name, age): | ||
self.name = name | ||
self.age = age | ||
|
||
# define prototype User | ||
User = {"_init": User_init, "_str": tostr} | ||
|
||
# define object that use User as prototype | ||
# using default $new(...) implementation | ||
print(new User("unknown", 45)._str()) | ||
|
||
func custom_new(prototype, *args): | ||
obj = {"_proto": prototype} | ||
obj._init(*args) | ||
print("CUSTOM NEW USED with prototype", prototype, "args:", args) | ||
return obj | ||
script._included["$new"] = custom_new | ||
|
||
# using user-defined $new(...) implementation | ||
print(new User("Tester", 90)._str()) | ||
if a > b: | ||
print(a) | ||
else: | ||
print(b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters