fix tests and add stub function call test
This commit is contained in:
parent
f1d5768b98
commit
02cb89bd5b
@ -646,7 +646,7 @@ public class ZqParser
|
||||
// is function call
|
||||
string fullyQualifiedName = values[0].Substring(0, values[0].IndexOf('('));
|
||||
string parmList = values[0].Substring(values[0].IndexOf('(') + 1, values[0].IndexOf(')') - values[0].IndexOf('(') - 1);
|
||||
val = new ZqMethodCall(new ZqVariableReference(fullyQualifiedName), parmList.Split(new char[] { ',' }));
|
||||
val = new ZqMethodCall(new ZqVariableReference(fullyQualifiedName), ParseParameterList(parmList));
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -670,6 +670,39 @@ public class ZqParser
|
||||
return null;
|
||||
}
|
||||
|
||||
private object[] ParseParameterList(string parmList)
|
||||
{
|
||||
string[] parms = parmList.Split(new char[] { ',' });
|
||||
object[] pp = new object[parms.Length];
|
||||
for (int i = 0; i < parms.Length; i++)
|
||||
{
|
||||
string parm = parms[i];
|
||||
if (parm.StartsWith("[") && parm.EndsWith("]"))
|
||||
{
|
||||
parm = parm.Substring(1, parm.Length - 2);
|
||||
InstanceKey ik = InstanceKey.Parse(parm);
|
||||
pp[i] = ik;
|
||||
}
|
||||
if (parm.StartsWith("'") && parm.EndsWith("'"))
|
||||
{
|
||||
pp[i] = parm.Substring(1, parm.Length - 2);
|
||||
}
|
||||
else if (parm.Equals("true"))
|
||||
{
|
||||
pp[i] = true;
|
||||
}
|
||||
else if (parm.Equals("false"))
|
||||
{
|
||||
pp[i] = false;
|
||||
}
|
||||
else if (Decimal.TryParse(parm, out decimal m))
|
||||
{
|
||||
pp[i] = m;
|
||||
}
|
||||
}
|
||||
return pp;
|
||||
}
|
||||
|
||||
private string ReadBetween(string text, ref int i, char beginChar, char endChar)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@ -25,17 +25,25 @@ public class MethodDefinitionTests
|
||||
CommonInstanceSet.instanceByInstanceID('1$770')
|
||||
|
||||
}
|
||||
static function testStubFunctionCallWithInstanceKey() : Class = {
|
||||
|
||||
CommonInstanceSet.instanceByInstanceID([1$770])
|
||||
|
||||
}
|
||||
|
||||
}");
|
||||
|
||||
Assert.That(obj, Is.TypeOf<ZqClass>());
|
||||
Assert.That(((ZqClass)obj).Functions.Count, Is.EqualTo(2));
|
||||
Assert.That(((ZqClass)obj).Functions.Count, Is.EqualTo(3));
|
||||
Assert.That(((ZqClass)obj).Functions[1], Is.TypeOf<ZqSimpleReturnMethod>());
|
||||
Assert.That(((ZqSimpleReturnMethod)((ZqClass)obj).Functions[1]).ReturnValue, Is.TypeOf<ZqMethodCall>());
|
||||
Assert.That(((ZqMethodCall)((ZqSimpleReturnMethod)((ZqClass)obj).Functions[1]).ReturnValue).ParmValues.Length, Is.EqualTo(1));
|
||||
|
||||
// FIXME: the text literal, once parsed, should not have '' / "" quotes
|
||||
Assert.That(((ZqMethodCall)((ZqSimpleReturnMethod)((ZqClass)obj).Functions[1]).ReturnValue).ParmValues[0], Is.EqualTo("'1$770'"));
|
||||
Assert.That(((ZqMethodCall)((ZqSimpleReturnMethod)((ZqClass)obj).Functions[1]).ReturnValue).ParmValues[0], Is.TypeOf<string>());
|
||||
Assert.That(((ZqMethodCall)((ZqSimpleReturnMethod)((ZqClass)obj).Functions[1]).ReturnValue).ParmValues[0], Is.EqualTo("1$770"));
|
||||
|
||||
Assert.That(((ZqMethodCall)((ZqSimpleReturnMethod)((ZqClass)obj).Functions[2]).ReturnValue).ParmValues[0], Is.TypeOf<InstanceKey>());
|
||||
Assert.That(((ZqMethodCall)((ZqSimpleReturnMethod)((ZqClass)obj).Functions[2]).ReturnValue).ParmValues[0], Is.EqualTo(new InstanceKey(1, 770)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -74,8 +82,8 @@ public class MethodDefinitionTests
|
||||
|
||||
Assert.That(obj, Is.TypeOf<ZqClass>());
|
||||
Assert.That(((ZqClass)obj).Functions.Count, Is.EqualTo(1));
|
||||
Assert.That(((ZqClass)obj).Functions[0], Is.TypeOf<ZqBuildAttributeMethod>());
|
||||
Assert.That(((ZqBuildAttributeMethod)((ZqClass)obj).Functions[0]).InitialValue, Is.EqualTo("Build Attribute Method"));
|
||||
Assert.That(((ZqClass)obj).Functions[0], Is.TypeOf<ZqSimpleReturnMethod>());
|
||||
Assert.That(((ZqSimpleReturnMethod)((ZqClass)obj).Functions[0]).ReturnValue, Is.EqualTo("Build Attribute Method"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user