Search in sources :

Example 1 with Command

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));
}
Also used : Target(com.laytonsmith.core.constructs.Target) CInt(com.laytonsmith.core.constructs.CInt) Command(com.laytonsmith.core.constructs.Command) CArray(com.laytonsmith.core.constructs.CArray) Test(org.junit.Test)

Example 2 with Command

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);
}
Also used : CInt(com.laytonsmith.core.constructs.CInt) IVariable(com.laytonsmith.core.constructs.IVariable) Variable(com.laytonsmith.core.constructs.Variable) Command(com.laytonsmith.core.constructs.Command) CBoolean(com.laytonsmith.core.constructs.CBoolean) IVariable(com.laytonsmith.core.constructs.IVariable) CArray(com.laytonsmith.core.constructs.CArray) CDouble(com.laytonsmith.core.constructs.CDouble) CFunction(com.laytonsmith.core.constructs.CFunction) Construct(com.laytonsmith.core.constructs.Construct) CNull(com.laytonsmith.core.constructs.CNull) CString(com.laytonsmith.core.constructs.CString) Test(org.junit.Test)

Example 3 with Command

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));
}
Also used : CInt(com.laytonsmith.core.constructs.CInt) Command(com.laytonsmith.core.constructs.Command) CArray(com.laytonsmith.core.constructs.CArray) Test(org.junit.Test)

Example 4 with Command

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;
}
Also used : IVariable(com.laytonsmith.core.constructs.IVariable) Variable(com.laytonsmith.core.constructs.Variable) Command(com.laytonsmith.core.constructs.Command) Token(com.laytonsmith.core.constructs.Token) ProfilePoint(com.laytonsmith.core.profiler.ProfilePoint) CString(com.laytonsmith.core.constructs.CString)

Aggregations

Command (com.laytonsmith.core.constructs.Command)4 CArray (com.laytonsmith.core.constructs.CArray)3 CInt (com.laytonsmith.core.constructs.CInt)3 Test (org.junit.Test)3 CString (com.laytonsmith.core.constructs.CString)2 IVariable (com.laytonsmith.core.constructs.IVariable)2 Variable (com.laytonsmith.core.constructs.Variable)2 CBoolean (com.laytonsmith.core.constructs.CBoolean)1 CDouble (com.laytonsmith.core.constructs.CDouble)1 CFunction (com.laytonsmith.core.constructs.CFunction)1 CNull (com.laytonsmith.core.constructs.CNull)1 Construct (com.laytonsmith.core.constructs.Construct)1 Target (com.laytonsmith.core.constructs.Target)1 Token (com.laytonsmith.core.constructs.Token)1 ProfilePoint (com.laytonsmith.core.profiler.ProfilePoint)1