Skip to content

Commit

Permalink
Merge branch 'dev/patch' into patch/merge-within-contains
Browse files Browse the repository at this point in the history
  • Loading branch information
sovdeeth authored Sep 21, 2024
2 parents cd2c078 + 3e3f0a9 commit 15740de
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ public class DefaultOperations {
return left.doubleValue() * right.doubleValue();
});
Arithmetics.registerOperation(Operator.DIVISION, Number.class, (left, right) -> left.doubleValue() / right.doubleValue());
Arithmetics.registerOperation(Operator.EXPONENTIATION, Number.class, (left, right) -> {
if (Utils.isInteger(left, right) && right.longValue() >= 0)
return (long) Math.pow(left.longValue(), right.longValue());
return Math.pow(left.doubleValue(), right.doubleValue());
});
Arithmetics.registerOperation(Operator.EXPONENTIATION, Number.class, (left, right) -> Math.pow(left.doubleValue(), right.doubleValue()));
Arithmetics.registerDifference(Number.class, (left, right) -> {
if (Utils.isInteger(left, right))
return Math.abs(left.longValue() - right.longValue());
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/ch/njol/skript/lang/SkriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1181,7 +1181,15 @@ public static String notOfType(Class<?>... types) {
}
Class<?> c = types[i];
assert c != null;
message.append(Classes.getSuperClassInfo(c).getName().withIndefiniteArticle());
ClassInfo<?> classInfo = Classes.getSuperClassInfo(c);
// if there's a registered class info,
if (classInfo != null) {
// use the article,
message.append(classInfo.getName().withIndefiniteArticle());
} else {
// otherwise fallback to class name
message.append(c.getName());
}
}
return message.toString();
}
Expand Down
45 changes: 20 additions & 25 deletions src/main/java/ch/njol/skript/test/runner/StructParse.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
/**
* This file is part of Skript.
*
* Skript is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Skript is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Skript. If not, see <http://www.gnu.org/licenses/>.
*
* Copyright Peter Güttinger, SkriptLang team and contributors
*/
package ch.njol.skript.test.runner;

import ch.njol.skript.ScriptLoader;
import ch.njol.skript.Skript;
import ch.njol.skript.classes.Changer;
import ch.njol.skript.classes.Changer.ChangeMode;
import ch.njol.skript.classes.Changer.ChangerUtils;
import ch.njol.skript.config.Node;
Expand All @@ -30,6 +11,8 @@
import ch.njol.skript.doc.NoDoc;
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.parser.ParserInstance;
import ch.njol.skript.lang.util.ContextlessEvent;
import ch.njol.skript.log.LogEntry;
import ch.njol.skript.log.RetainingLogHandler;
Expand All @@ -42,9 +25,6 @@
import org.skriptlang.skript.lang.entry.util.ExpressionEntryData;
import org.skriptlang.skript.lang.structure.Structure;

import static ch.njol.skript.lang.SkriptParser.ParseResult;


@Name("Parse Structure")
@Description("Parses the code inside this structure as a structure and use 'parse logs' to grab any logs from it.")
@NoDoc
Expand All @@ -54,7 +34,7 @@ public class StructParse extends Structure {
Skript.registerStructure(StructParse.class, "parse");
}

private static EntryValidator validator = EntryValidator.builder()
private static final EntryValidator validator = EntryValidator.builder()
.addEntryData(new ExpressionEntryData<>("results", null, false, Object.class))
.addSection("code", false)
.build();
Expand All @@ -64,26 +44,33 @@ public class StructParse extends Structure {
private Expression<?> resultsExpression;

@Override
public boolean init(Literal<?>[] args, int matchedPattern, ParseResult parseResult, EntryContainer entryContainer) {
public boolean init(Literal<?>[] args, int matchedPattern,
ParseResult parseResult, EntryContainer entryContainer) {
SectionNode parseStructureSectionNode = entryContainer.getSource();

Class<? extends Event>[] originalEvents = getParser().getCurrentEvents();
getParser().setCurrentEvent("parse", ContextlessEvent.class);
EntryContainer validatedEntries = validator.validate(parseStructureSectionNode);
getParser().setCurrentEvents(originalEvents);

if (validatedEntries == null) {
Skript.error("A parse structure must have a result entry and a code section");
return false;
}

Expression<?> maybeResultsExpression = (Expression<?>) validatedEntries.get("results", false);
if (!ChangerUtils.acceptsChange(maybeResultsExpression, ChangeMode.SET, String[].class)) {
Skript.error(maybeResultsExpression.toString(null, false) + " cannot be set to strings");
return false;
}

SectionNode codeSectionNode = (SectionNode) validatedEntries.get("code", false);
Node maybeStructureSectionNodeToParse = Iterables.getFirst(codeSectionNode, null);
if (Iterables.size(codeSectionNode) != 1 || !(maybeStructureSectionNodeToParse instanceof SectionNode)) {
Skript.error("The code section must contain a single section to parse as a structure");
return false;
}

resultsExpression = maybeResultsExpression;
structureSectionNodeToParse = (SectionNode) maybeStructureSectionNodeToParse;
return true;
Expand All @@ -100,7 +87,15 @@ public boolean load() {
try (RetainingLogHandler handler = SkriptLogger.startRetainingLog()) {
String structureSectionNodeKey = ScriptLoader.replaceOptions(structureSectionNodeToParse.getKey());
String error = "Can't understand this structure: " + structureSectionNodeKey;
Structure.parse(structureSectionNodeKey, structureSectionNodeToParse, error);
Structure structure = Structure.parse(structureSectionNodeKey, structureSectionNodeToParse, error);

getParser().setCurrentStructure(structure);
if (structure != null && structure.preLoad() && structure.load()) {
structure.postLoad();
}

getParser().setCurrentStructure(null);

logs = handler.getLog().stream()
.map(LogEntry::getMessage)
.toArray(String[]::new);
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/org/skriptlang/skript/bukkit/SkriptMetrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,14 @@ public static void setupMetrics(Metrics metrics) {

metrics.addCustomChart(new DrilldownPie("drilldownLogVerbosity", () -> {
String verbosity = SkriptConfig.verbosity.value().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
return isDefaultMap(verbosity, SkriptConfig.verbosity.defaultValue());
String defaultValue = SkriptConfig.verbosity.defaultValue().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
return isDefaultMap(verbosity, defaultValue);
}));

metrics.addCustomChart(new DrilldownPie("drilldownPluginPriority", () -> {
String priority = SkriptConfig.defaultEventPriority.value().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
return isDefaultMap(priority, SkriptConfig.defaultEventPriority.defaultValue());
String defaultValue = SkriptConfig.defaultEventPriority.defaultValue().name().toLowerCase(Locale.ENGLISH).replace('_', ' ');
return isDefaultMap(priority, defaultValue);
}));
metrics.addCustomChart(new SimplePie("cancelledByDefault", () ->
SkriptConfig.listenCancelledByDefault.value().toString()
Expand All @@ -143,10 +145,10 @@ public static void setupMetrics(Metrics metrics) {
SkriptConfig.caseSensitive.value().toString()
));
metrics.addCustomChart(new SimplePie("caseSensitiveVariables", () ->
SkriptConfig.caseInsensitiveVariables.value().toString()
String.valueOf(!SkriptConfig.caseInsensitiveVariables.value())
));
metrics.addCustomChart(new SimplePie("caseSensitiveCommands", () ->
SkriptConfig.caseInsensitiveCommands.value().toString()
String.valueOf(!SkriptConfig.caseInsensitiveCommands.value())
));

metrics.addCustomChart(new SimplePie("disableSaveWarnings", () ->
Expand Down
2 changes: 2 additions & 0 deletions src/test/skript/tests/regressions/7059-exponent overflow.sk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test "overflow exponents":
assert 10 ^ 25 is 10000000000000000000000000 with "exponentiation was unexpectedly capped"
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ test "EffHealth item mutation fix":

set {_item1} to diamond sword with damage 100
set {_item2} to diamond with damage 10
repair {_item1}, {_item2}
repair {_item1} and {_item2}
assert {_item1} is diamond sword with damage 0 with "{_item1} was incorrectly repaired"
assert {_item2} is diamond with "{_item2} was no longer a diamond"
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parse:
results: {StructEvent::parse::*}
code:
on script load:
stop

test "events in structs":
assert {StructEvent::parse::*} is not set with "using event in struct caused an error"
14 changes: 7 additions & 7 deletions src/test/skript/tests/syntaxes/conditions/CondCompare.sk
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ test "compare":
assert 1 is greater than or equal to 0 and 1 with "Number is not greater than or equal to two smaller/equal numbers"
assert 1 is less than or equal to 1 and 2 with "Number is not smaller than or equal to two greater/equal numbers"

assert 1, 2 is 1, 2 with "direct list comparison of equal numbers failed"
assert 1, 2, 3 is not 1, 2 with "direct list comparison of non-equal numbers succeeded"
assert 1, 2 is 1, 2, or 3 with "comparison between AND list of numbers and OR list of superset of numbers failed"
assert 1, 2, 3 is 1 or 2 to fail with "comparison between AND list of numbers and OR list of subset of numbers succeeded"
assert 1 and 2 is 1 and 2 with "direct list comparison of equal numbers failed"
assert 1, 2, and 3 is not 1 and 2 with "direct list comparison of non-equal numbers succeeded"
assert 1 and 2 is 1, 2, or 3 with "comparison between AND list of numbers and OR list of superset of numbers failed"
assert 1, 2, and 3 is 1 or 2 to fail with "comparison between AND list of numbers and OR list of subset of numbers succeeded"

assert 1, 2, 3 is greater than -1, -2, -3 with "Numbers are not larger than smaller numbers"
assert 1, 2, 3 is less than 5, 6, 7 with "Numbers are not smaller than larger numbers"
assert 1, 2, 3 is between -1, 1 and 3, 3.5 with "Numbers are not between smaller/equal numbers and larger/equal numbers"
assert 1, 2, and 3 is greater than -1, -2, and -3 with "Numbers are not larger than smaller numbers"
assert 1, 2, and 3 is less than 5, 6, and 7 with "Numbers are not smaller than larger numbers"
assert 1, 2, and 3 is between (-1 and 1) and (3 and 3.5) with "Numbers are not between smaller/equal numbers and larger/equal numbers"

assert 10 is between 5 and 15 with "Number isn't between smaller and larger"
assert 10 is between 9 and 11 with "Number isn't between smaller and larger"
Expand Down
6 changes: 3 additions & 3 deletions src/test/skript/tests/syntaxes/expressions/ExprRepeat.sk
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,23 @@ test "repeat expression":
then:
assert false is true with "ExprRepeat Multi - 1) 'aa' and 'b' repeated 3 times is not 'aaaaaa' and 'bbb'"

set {_strings::*} to "aa", "b"
set {_strings::*} to "aa" and "b"
set {_strings::*} to {_strings::*} repeated {_repeat} times
if any:
{_strings::1} is not "aaaaaa"
{_strings::2} is not "bbb"
then:
assert false is true with "ExprRepeat Multi - 2) 'aa' and 'b' repeated 3 times is not 'aaaaaa' and 'bbb'"

set {_strings::*} to "aa", "b"
set {_strings::*} to "aa" and "b"
set {_strings::*} to {_strings::*} repeated 3 times
if any:
{_strings::1} is not "aaaaaa"
{_strings::2} is not "bbb"
then:
assert false is true with "ExprRepeat Multi - 3) 'aa' and 'b' repeated 3 times is not 'aaaaaa' and 'bbb'"

set {_strings::*} to "aa", "b" repeated {_repeat} times
set {_strings::*} to "aa" and "b" repeated {_repeat} times
if any:
{_strings::1} is not "aaaaaa"
{_strings::2} is not "bbb"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test "string cases":
assert caseEquals("Oops!" in lowercase, "oops!") is true with "lowercase failed"
assert caseEquals("Oops!" in uppercase, "OOPS!") is true with "uppercase failed"
assert caseEquals(capitalised "Oops!", "OOPS!") is true with "capitalised failed"
assert caseEquals((capitalised "Oops!"), "OOPS!") is true with "capitalised failed"
assert caseEquals("hellO i'm steve!" in proper case, "HellO I'm Steve!") is true with "lenient proper case failed"
assert caseEquals("hellO i'm steve!" in strict proper case, "Hello I'm Steve!") is true with "strict proper case failed"
assert caseEquals("spAwn neW boSs ()" in camel case, "spAwnNeWBoSs()") is true with "lenient camel case failed"
Expand Down

0 comments on commit 15740de

Please sign in to comment.