Skip to content

Commit 1169dd8

Browse files
committed
Add dictionary tests.
1 parent a2e74f4 commit 1169dd8

File tree

9 files changed

+62
-10
lines changed

9 files changed

+62
-10
lines changed

src/main/java/org/byteskript/skript/compiler/Context.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ public void setStoredVariableName(String storedVariableName) {
4949

5050
public abstract Map<String, Type> getTypeMap();
5151

52-
public abstract Type getType(String name);
53-
5452
public abstract void setIndentUnit(String string);
5553

5654
public abstract ClassBuilder getBuilder();
@@ -269,4 +267,11 @@ public String expectedIndent() {
269267

270268
public abstract int indent();
271269

270+
public Type findType(String internal) {
271+
final Type type = this.getType(internal);
272+
if (type != null) return type;
273+
return new Type(internal);
274+
}
275+
276+
public abstract Type getType(String name);
272277
}

src/main/java/org/byteskript/skript/compiler/FileContext.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,6 @@ public Map<String, Type> getTypeMap() {
143143
return types;
144144
}
145145

146-
@Override
147-
public Type getType(String name) {
148-
return types.get(name);
149-
}
150-
151146
@Override
152147
public void setIndentUnit(String string) {
153148
this.indentUnit = string;
@@ -465,4 +460,9 @@ public String indentUnit() {
465460
public int indent() {
466461
return indent;
467462
}
463+
464+
@Override
465+
public Type getType(String name) {
466+
return types.get(name);
467+
}
468468
}

src/main/java/org/byteskript/skript/lang/syntax/function/ExternalFunctionExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public void compile(Context context, Pattern.Match match) throws Throwable {
114114
final MethodBuilder method = context.getMethod();
115115
final FunctionDetails details = match.meta();
116116
assert details != null : "No details found, parsing errored.";
117-
final Type location = new Type(details.location);
117+
final Type location = context.findType(details.location);
118118
final Function function = new Function(details.name, location, CommonTypes.OBJECT, details.arguments);
119119
method.writeCode(function.invoke(context.getType().internalName()));
120120
}

src/main/java/org/byteskript/skript/lang/syntax/type/TypeExpression.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import org.byteskript.skript.compiler.SkriptLangSpec;
1818
import org.byteskript.skript.lang.element.StandardElements;
1919

20-
import java.util.Locale;
2120
import java.util.Map;
2221
import java.util.regex.Matcher;
2322

@@ -82,7 +81,7 @@ public Type getReturnType() {
8281

8382
public Type getType(String string, Context context) {
8483
for (final Map.Entry<String, Type> entry : context.getTypeMap().entrySet()) {
85-
if (!entry.getKey().toLowerCase(Locale.ROOT).equals(string.toLowerCase(Locale.ROOT))) continue;
84+
if (!entry.getKey().equalsIgnoreCase(string)) continue;
8685
return entry.getValue();
8786
}
8887
if (string.contains("/")) return new Type(string);

src/test/resources/dictionary.bsk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
dictionary:
22
import type skript/generic
33
import function "to_be_imported" from skript/generic
4+
import type java/lang/System
5+
import function "nanoTime" from System
46

57
function test:
68
trigger:
79
set {var} to to_be_imported()
810
assert {var} is "hello": "Imported function returned incorrectly."
11+
set {var} to nanoTime() from System
12+
assert {var} > 0
913

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dictionary:
2+
import type java/util/Objects
3+
import type java/lang/System
4+
import function "equals" from java/util/Objects
5+
6+
function test:
7+
trigger:
8+
set {var} to nanoTime() from System
9+
assert {var} > 0
10+
set {var} to equals("hello", "there") from Objects
11+
assert {var} is false
12+
set {var} to equals("hello", "hello") from Objects
13+
assert {var} is true
14+
return true
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
dictionary:
2+
import type java/util/Objects
3+
import function "equals" from java/util/Objects
4+
import type java/lang/System
5+
import function "nanoTime" from System
6+
7+
function test:
8+
trigger:
9+
set {var} to nanoTime()
10+
assert {var} > 0
11+
set {var} to equals("hello", "there")
12+
assert {var} is false
13+
set {var} to equals("hello", "hello")
14+
assert {var} is true
15+
return true
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
dictionary:
2+
import type java/util/Objects
3+
import type java/lang/System
4+
import function "equals" from java/util/Objects
5+
6+
function test:
7+
trigger:
8+
set {var} to nanoTime() from System
9+
assert {var} > 0
10+
set {var} to equals("hello", "there") from Objects
11+
assert {var} is false
12+
set {var} to equals("hello", "hello") from Objects
13+
assert {var} is true
14+
return true

src/test/resources/tests/isequal.bsk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ function test:
1414
assert {var} is "hello": "Equality check failed."
1515
assert ({var} is "there") is false: "Equality check failed."
1616
assert ({var} is {x}) is false: "Equality check failed."
17+
assert 1 = 1
1718
return true

0 commit comments

Comments
 (0)