use of com.laytonsmith.core.constructs.Command in project CommandHelper by EngineHub.
the class RandomTests method testJSONEscapeString.
@Test
public void testJSONEscapeString() throws MarshalException {
CArray ca = new CArray(Target.UNKNOWN);
final Target t = Target.UNKNOWN;
ca.push(C.Int(1), t);
ca.push(C.Double(2.2), t);
ca.push(C.String("string"), t);
ca.push(C.String("\"Quote\""), t);
ca.push(C.Boolean(true), t);
ca.push(C.Boolean(false), t);
ca.push(C.Null(), t);
ca.push(C.Void(), t);
ca.push(new Command("/Command", Target.UNKNOWN), t);
ca.push(new CArray(Target.UNKNOWN, new CInt(1, Target.UNKNOWN)), t);
// [1, 2.2, "string", "\"Quote\"", true, false, null, "", "/Command", [1]]
assertEquals("[1,2.2,\"string\",\"\\\"Quote\\\"\",true,false,null,\"\",\"\\/Command\",[1]]", Construct.json_encode(ca, Target.UNKNOWN));
}
use of com.laytonsmith.core.constructs.Command in project CommandHelper by EngineHub.
the class RandomTests method testClone.
@Test
public void testClone() throws CloneNotSupportedException {
CArray c1 = C.Array(C.Void(), C.Void()).clone();
CBoolean c2 = C.Boolean(true).clone();
CDouble c4 = C.Double(1).clone();
CFunction c5 = new CFunction("", Target.UNKNOWN).clone();
CInt c6 = C.Int(1).clone();
CNull c7 = C.Null().clone();
CString c8 = C.String("").clone();
Construct c9 = C.Void().clone();
Command c10 = new Command("/c", Target.UNKNOWN).clone();
IVariable c12 = new IVariable(Auto.TYPE, "@name", C.Null(), Target.UNKNOWN).clone();
Variable c13 = new Variable("$name", "", false, false, Target.UNKNOWN);
}
use of com.laytonsmith.core.constructs.Command in project CommandHelper by EngineHub.
the class RandomTests method testJSONDecodeString.
@Test
public void testJSONDecodeString() throws MarshalException {
CArray ca = new CArray(Target.UNKNOWN);
ca.push(C.Int(1), Target.UNKNOWN);
ca.push(C.Double(2.2), Target.UNKNOWN);
ca.push(C.String("string"), Target.UNKNOWN);
ca.push(C.String("\"Quote\""), Target.UNKNOWN);
ca.push(C.Boolean(true), Target.UNKNOWN);
ca.push(C.Boolean(false), Target.UNKNOWN);
ca.push(C.Null(), Target.UNKNOWN);
ca.push(C.Void(), Target.UNKNOWN);
ca.push(new Command("/Command", Target.UNKNOWN), Target.UNKNOWN);
ca.push(new CArray(Target.UNKNOWN, new CInt(1, Target.UNKNOWN)), Target.UNKNOWN);
StaticTest.assertCEquals(ca, Construct.json_decode("[1, 2.2, \"string\", \"\\\"Quote\\\"\", true, false, null, \"\", \"\\/Command\", [1]]", Target.UNKNOWN));
}
use of com.laytonsmith.core.constructs.Command in project CommandHelper by EngineHub.
the class Script method compileLeft.
private boolean compileLeft() {
cleft = new ArrayList<>();
if (label != null && label.startsWith("!")) {
if (label.length() > 1) {
label = label.substring(1);
}
nolog = true;
}
for (int i = 0; i < left.size(); i++) {
Token t = left.get(i);
if (t.value.startsWith("/")) {
cleft.add(new Command(t.val(), t.target));
} else if (t.type == Token.TType.VARIABLE) {
cleft.add(new Variable(t.val(), null, t.target));
} else if (t.type.equals(TType.FINAL_VAR)) {
Variable v = new Variable(t.val(), null, t.target);
v.setFinal(true);
cleft.add(v);
} else if (t.type.equals(TType.LSQUARE_BRACKET)) {
if (i + 2 < left.size() && left.get(i + 2).type.equals(TType.OPT_VAR_ASSIGN)) {
Variable v = new Variable(left.get(i + 1).val(), left.get(i + 3).val(), t.target);
v.setOptional(true);
if (left.get(i + 1).type.equals(TType.FINAL_VAR)) {
v.setFinal(true);
}
cleft.add(v);
i += 4;
} else {
t = left.get(i + 1);
Variable v = new Variable(t.val(), null, t.target);
v.setOptional(true);
if (t.val().equals("$")) {
v.setFinal(true);
}
cleft.add(v);
i += 2;
}
} else {
cleft.add(new CString(t.val(), t.getTarget()));
}
}
return true;
}
Aggregations