1818import org .junit .BeforeClass ;
1919import org .junit .Test ;
2020
21+ import java .io .ByteArrayInputStream ;
2122import java .lang .reflect .Method ;
23+ import java .nio .charset .StandardCharsets ;
2224
2325public class SyntaxCreationTest extends SkriptTest {
2426
2527 private static final Skript skript = new Skript ();
2628 private static Script script ;
29+ private static Script use ;
2730
2831 @ BeforeClass
2932 public static void start () throws Throwable {
3033 final PostCompileClass cls = skript .compileScript (SyntaxCreationTest .class .getClassLoader ()
3134 .getResourceAsStream ("syntax.bsk" ), "skript.syntax" );
3235 script = skript .loadScript (cls );
36+ skript .registerLibraryClass (cls .code ());
37+ use = skript .loadScript (skript .compileScript (new ByteArrayInputStream ("""
38+ function run_syntax:
39+ trigger:
40+ assert true
41+ my cool "hello" and 5
42+ set {var} to a "bean?"
43+ assert {var} exists
44+ assert {var} is "hello"
45+ """ .getBytes (StandardCharsets .UTF_8 )), "skript.syntax_test" ));
46+ }
47+
48+ @ Test
49+ public void run_syntax () throws Throwable {
50+ final Member function = use .getFunction ("run_syntax" );
51+ function .run (skript ).get ();
3352 }
3453
3554 @ Test
@@ -71,7 +90,7 @@ public void test_expression() throws Throwable {
7190 public void test_set_property () throws Throwable {
7291 final Member function = script .getFunction ("test_set_property" );
7392 assert function != null ;
74- final Method method = script .mainClass ().getDeclaredMethod ("test_set_property" , Object .class );
93+ final Method method = script .mainClass ().getDeclaredMethod ("test_set_property" , Object .class , Object . class );
7594 assert !method .isAnnotationPresent (Expression .class );
7695 assert method .isAnnotationPresent (Property .class );
7796 final Property annotation = method .getAnnotation (Property .class );
@@ -84,7 +103,7 @@ public void test_set_property() throws Throwable {
84103 public void test_get_property () throws Throwable {
85104 final Member function = script .getFunction ("test_get_property" );
86105 assert function != null ;
87- final Method method = script .mainClass ().getDeclaredMethod ("test_get_property" );
106+ final Method method = script .mainClass ().getDeclaredMethod ("test_get_property" , Object . class );
88107 assert !method .isAnnotationPresent (Expression .class );
89108 assert method .isAnnotationPresent (Property .class );
90109 final Property annotation = method .getAnnotation (Property .class );
@@ -93,4 +112,34 @@ public void test_get_property() throws Throwable {
93112 assert annotation .type () == StandardHandlers .GET ;
94113 }
95114
115+ @ Test
116+ public void composite () throws Throwable {
117+ final String first = """
118+ function test_eff (name):
119+ syntax:
120+ effect: hello %String%
121+ trigger:
122+ print "hello"
123+ print {name}
124+ """ ;
125+ final String test = """
126+ function test_eff (name):
127+ syntax:
128+ effect: hello %String%
129+ trigger:
130+ assert true
131+
132+ on load:
133+ trigger:
134+ assert true
135+ hello "hi"
136+
137+ """ ;
138+ final Skript skript = new Skript ();
139+ final PostCompileClass syntax = skript .compileScript (first , "skript.test_blob" );
140+ skript .registerLibraryClass (syntax .code ());
141+ final PostCompileClass output = skript .compileScript (test , "skript.test_blob" );
142+ final Script script = skript .loadScript (output );
143+ }
144+
96145}
0 commit comments