Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master 1.19 lts #1440

Merged
merged 3 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,17 @@ public IValue evaluate(OperatorBase.SafeVariablesGetter variables) throws Evalua
variables -> ValueTypeString.ValueString.of(ValueTypes.CATEGORY_UNIQUELY_NAMED.getUniqueName(variables.getVariables()[0]))
).build());

/**
* Throw a custom error
*/
public static final IOperator STRING_ERROR = REGISTRY.register(OperatorBuilders.STRING_2.symbol("error").operatorName("string_error").interactName("stringError")
.inputType(ValueTypes.STRING).renderPattern(IConfigRenderPattern.SUFFIX_1_LONG)
.function(
(variables) -> {
throw new EvaluationException(Component.translatable(variables.getValue(0, ValueTypes.STRING).getRawValue()));
}
).build());

/**
* ----------------------------------- NUMBER OPERATORS -----------------------------------
*/
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/assets/integrateddynamics/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@
"valuetype.integrateddynamics.named.info": "Something that has a name, such as display names of items and blocks.",
"valuetype.integrateddynamics.uniquely_named": "Uniquely Named",
"valuetype.integrateddynamics.uniquely_named.info": "Something that has a unique name, such as items and blocks.",
"operator.integrateddynamics.string.string_error": "Error",
"operator.integrateddynamics.string.string_error.info": "Throw a custom error",


"valuetype.integrateddynamics.boolean": "Boolean",
"valuetype.integrateddynamics.integer": "Integer",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,32 @@ public void testInvalidInputTypeNamedName() throws EvaluationException {
Operators.NAMED_NAME.evaluate(new IVariable[]{DUMMY_VARIABLE});
}

/**
* ----------------------------------- STRING_ERROR -----------------------------------
*/

@Test(expected = EvaluationException.class)
public void testStringErrorWithSymbols() throws EvaluationException {
Operators.STRING_ERROR.evaluate(sregex);
}

@Test(expected = EvaluationException.class)
public void testStringErrorWithSpaces() throws EvaluationException {
Operators.STRING_ERROR.evaluate(shelloWorld);
}

@Test(expected = EvaluationException.class)
public void testInvalidInputSizeErrorLong() throws EvaluationException {
Operators.STRING_ERROR.evaluate(new IVariable[]{sabc, sabc});
}

@Test(expected = EvaluationException.class)
public void testInvalidInputSizeErrorSmall() throws EvaluationException {
Operators.STRING_ERROR.evaluate(new IVariable[]{});
}

@Test(expected = EvaluationException.class)
public void testInvalidInputTypeError() throws EvaluationException {
Operators.STRING_ERROR.evaluate(new IVariable[]{DUMMY_VARIABLE, DUMMY_VARIABLE});
}
}
Loading