Skip to content

Commit 023fd9e

Browse files
committed
Continue with individual tests.
1 parent 6720fbd commit 023fd9e

File tree

6 files changed

+59
-18
lines changed

6 files changed

+59
-18
lines changed

src/main/java/org/byteskript/skript/runtime/internal/Member.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,24 @@ public Class<? extends CompiledScript> owner() {
177177
""")
178178
public Future<?> run(Skript skript, Object... arguments) {
179179
final ScriptRunner runner = new ScriptRunner() {
180-
180+
181181
private Object value;
182-
182+
183183
@Override
184184
public Object result() {
185185
synchronized (this) {
186186
return value;
187187
}
188188
}
189-
189+
190190
@Override
191191
public void start() {
192192
final Object result = invoker.invoke(arguments);
193193
synchronized (this) {
194194
this.value = result;
195195
}
196196
}
197-
197+
198198
@Override
199199
public Class<? extends CompiledScript> owner() {
200200
return script.mainClass();

src/main/java/org/byteskript/skript/runtime/internal/OperatorHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ public static Number root(Object a) {
209209
}
210210
//endregion
211211

212-
public static Boolean equals(Object a, Object b) {
213-
if (Objects.equals(a, b)) return true;
214-
if (isArray(a) && isArray(b)) return Arrays.equals((Object[]) a, (Object[]) b);
215-
if (!(a instanceof Number x) || !(b instanceof Number y)) return false;
216-
return Double.compare(x.doubleValue(), y.doubleValue()) == 0;
217-
}
218-
219212
public static Boolean gt(Object a, Object b) {
220213
if (!(a instanceof Number x) || !(b instanceof Number y)) {
221214
throw new ScriptRuntimeError("Provided inputs must be numerical.");
@@ -309,6 +302,13 @@ public static Boolean matches(Object a, Object b) {
309302
return equals(a, b); // probably a mistaken use?
310303
}
311304

305+
public static Boolean equals(Object a, Object b) {
306+
if (Objects.equals(a, b)) return true;
307+
if (isArray(a) && isArray(b)) return Arrays.equals((Object[]) a, (Object[]) b);
308+
if (!(a instanceof Number x) || !(b instanceof Number y)) return false;
309+
return Double.compare(x.doubleValue(), y.doubleValue()) == 0;
310+
}
311+
312312
//region Comparisons
313313
public static Boolean isArray(Object a) {
314314
if (a == null) return false;

src/main/java/org/byteskript/skript/runtime/threading/ScriptRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ default void run() {
2121
thread.variables.clear();
2222
}
2323

24+
void start();
25+
2426
default Object result() {
2527
return null;
2628
}
2729

28-
void start();
29-
3030
Class<? extends CompiledScript> owner();
3131

3232
}

src/test/java/org/byteskript/skript/test/GenericTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,18 @@ public void all() throws Throwable {
5252
final String part = file.toString().substring(file.toString().indexOf("/tests/") + 7);
5353
final String name = part.substring(0, part.length() - 4).replace(File.separatorChar, '.');
5454
try (final InputStream stream = Files.newInputStream(file)) {
55-
final PostCompileClass cls;
55+
final PostCompileClass[] classes;
5656
synchronized (this) {
5757
try {
58-
cls = skript.compileScript(stream, "skript." + name);
58+
classes = skript.compileComplexScript(stream, "skript." + name);
5959
} catch (Throwable ex) {
6060
System.err.println("Error in '" + name + "':");
6161
ex.printStackTrace(System.err);
6262
failure++;
6363
continue;
6464
}
6565
try {
66-
final Script script = skript.loadScript(cls);
66+
final Script script = skript.loadScripts(classes).iterator().next();
6767
final boolean result = (boolean) script.getFunction("test").run(skript).get();
6868
assert result : "Test failed.";
6969
} catch (Throwable ex) {
@@ -72,11 +72,11 @@ public void all() throws Throwable {
7272
failure++;
7373
}
7474
}
75-
final File test = new File("target/test-scripts/" + cls.name() + ".class");
75+
final File test = new File("target/test-scripts/" + classes[0].name() + ".class");
7676
test.getParentFile().mkdirs();
7777
if (!test.exists()) test.createNewFile();
7878
try (final OutputStream output = new FileOutputStream(test)) {
79-
output.write(cls.code());
79+
output.write(classes[0].code());
8080
}
8181
}
8282
}

src/test/resources/tests/isoftype.bsk

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
template type Legume:
3+
function empty_func:
4+
5+
template type Pulse:
6+
template: Legume
7+
8+
type Bean:
9+
template: Pulse
10+
11+
function test:
12+
trigger:
13+
assert "hello" is a string: "Type check failed."
14+
assert "hello" is an object: "Type check failed."
15+
assert 1 is a number: "Type check failed."
16+
assert 1 is an integer: "Type check failed."
17+
assert -1 is an integer: "Type check failed."
18+
assert 1.0 is a number: "Type check failed."
19+
assert 1.0 is a double: "Type check failed."
20+
set {var} to "hello"
21+
assert {var} is a string: "Type check failed."
22+
set {bean} to a new bean
23+
assert {bean} is a bean: "Type check failed."
24+
assert {bean} is a pulse: "Type check failed."
25+
assert {bean} is a legume: "Type check failed."
26+
return true

src/test/resources/tests/matches.bsk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
function test:
3+
trigger:
4+
assert "hello" matches /hello/
5+
assert "hello" matches /.+/
6+
assert "hello" matches /h.llo/
7+
assert "hello" matches /[a-z]{5}/
8+
assert "there" matches /[a-z]{5}/
9+
assert ("hello" matches /[a-z]{6}/) is false
10+
set {var} to "hello there"
11+
assert ({var} matches /hello/) is false
12+
assert {var} matches /hello there/
13+
assert {var} matches /hello .+/
14+
assert {var} matches /[a-z]{5} [a-z]{5}/
15+
return true

0 commit comments

Comments
 (0)