Skip to content

Commit c4d85cc

Browse files
committed
Added sequals_ic
1 parent 7cc7c48 commit c4d85cc

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/main/java/com/laytonsmith/core/functions/BasicLogic.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,75 @@ public ExampleScript[] examples() throws ConfigCompileException {
11851185
}
11861186
}
11871187

1188+
@api
1189+
public static class sequals_ic extends AbstractFunction implements Optimizable {
1190+
1191+
@Override
1192+
public ExceptionType[] thrown() {
1193+
return null;
1194+
}
1195+
1196+
@Override
1197+
public boolean isRestricted() {
1198+
return false;
1199+
}
1200+
1201+
@Override
1202+
public Boolean runAsync() {
1203+
return null;
1204+
}
1205+
1206+
@Override
1207+
public Construct exec(Target t, Environment environment, Construct... args) throws ConfigRuntimeException {
1208+
Construct v1 = args[0];
1209+
Construct v2 = args[1];
1210+
if(!v2.getClass().equals(v1.getClass())){
1211+
return CBoolean.FALSE;
1212+
}
1213+
return new equals_ic().exec(t, environment, v1, v2);
1214+
}
1215+
1216+
@Override
1217+
public String getName() {
1218+
return "sequals_ic";
1219+
}
1220+
1221+
@Override
1222+
public Integer[] numArgs() {
1223+
return new Integer[]{2};
1224+
}
1225+
1226+
@Override
1227+
public String docs() {
1228+
return "boolean {value1, value2} Returns true if the values are the same type, as well as equal, according to equals_ic."
1229+
+ " Generally, equals_ic will suffice, because usually you will be comparing two strings, however, this function"
1230+
+ " may be useful in various other cases, perhaps where the datatypes are unknown, but could be strings.";
1231+
}
1232+
1233+
@Override
1234+
public Version since() {
1235+
return CHVersion.V3_3_1;
1236+
}
1237+
1238+
@Override
1239+
public Set<OptimizationOption> optimizationOptions() {
1240+
return EnumSet.of(
1241+
OptimizationOption.CONSTANT_OFFLINE,
1242+
OptimizationOption.CACHE_RETURN
1243+
);
1244+
}
1245+
1246+
@Override
1247+
public ExampleScript[] examples() throws ConfigCompileException {
1248+
return new ExampleScript[]{
1249+
new ExampleScript("Basic usage", "sequals_ic(1, 1)"),
1250+
new ExampleScript("False result", "sequals_ic('1', 1)"),
1251+
new ExampleScript("False result", "sequals_ic('false', true)")
1252+
};
1253+
}
1254+
1255+
}
1256+
11881257
@api
11891258
@seealso({equals_ic.class})
11901259
public static class nequals_ic extends AbstractFunction implements Optimizable {

src/test/java/com/laytonsmith/core/functions/BasicLogicTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,19 @@ public void testRefEquals5() throws Exception {
455455
+ "msg(ref_equals(@a, @b))", fakePlayer);
456456
verify(fakePlayer).sendMessage("false");
457457
}
458+
459+
public void testSEqualsic1() throws Exception {
460+
SRun("msg(sequals_ic(1, '1'))", fakePlayer);
461+
verify(fakePlayer).sendMessage("false");
462+
}
463+
464+
public void testSEqualsic2() throws Exception {
465+
SRun("msg(sequals_ic('hello', 'HELLO'))", fakePlayer);
466+
verify(fakePlayer).sendMessage("true");
467+
}
468+
469+
public void testSEqualsic3() throws Exception {
470+
SRun("msg(sequals_ic('false', true))", fakePlayer);
471+
verify(fakePlayer).sendMessage("false");
472+
}
458473
}

0 commit comments

Comments
 (0)