ITupleNode signature change
This commit is contained in:
@@ -119,7 +119,8 @@ begin
|
||||
if Node.Kind = akBlockExpression then
|
||||
begin
|
||||
block := Node.AsBlockExpression;
|
||||
for child in block.Expressions.ToArray do
|
||||
// Updated: Use Elements instead of ToArray
|
||||
for child in block.Expressions.Elements do
|
||||
begin
|
||||
Result := FindFirstVarName(child);
|
||||
if Result <> '' then
|
||||
|
||||
@@ -23,6 +23,7 @@ type
|
||||
[TestCase('Integer', '42,42')]
|
||||
[TestCase('Negative', '-10,-10')]
|
||||
[TestCase('Zero', '0,0')]
|
||||
[TestCase('Nop', '...')]
|
||||
procedure Parser_Number_Integer(const Source: string; Expected: Int64);
|
||||
|
||||
[Test]
|
||||
@@ -129,6 +130,12 @@ var
|
||||
node: IAstNode;
|
||||
begin
|
||||
node := Parse(Source);
|
||||
if Source = '...' then
|
||||
begin
|
||||
Assert.AreEqual<TAstNodeKind>(TAstNodeKind.akNop, node.Kind);
|
||||
Exit;
|
||||
end;
|
||||
|
||||
Assert.AreEqual<TAstNodeKind>(TAstNodeKind.akConstant, node.Kind);
|
||||
Assert.AreEqual<TScalar.TKind>(TScalar.TKind.Ordinal, node.AsConstant.Value.AsScalar.Kind);
|
||||
Assert.AreEqual<Int64>(Expected, node.AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
@@ -209,11 +216,11 @@ begin
|
||||
call := node.AsFunctionCall;
|
||||
|
||||
Assert.AreEqual<string>('add', call.Callee.AsIdentifier.Name);
|
||||
// Use Count instead of Length
|
||||
Assert.AreEqual<Integer>(2, call.Arguments.Count);
|
||||
// Use Length(Elements) instead of Count
|
||||
Assert.AreEqual<Integer>(2, Length(call.Arguments.Elements));
|
||||
|
||||
Assert.AreEqual<Int64>(1, call.Arguments[0].AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
Assert.AreEqual<Int64>(2, call.Arguments[1].AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
Assert.AreEqual<Int64>(1, call.Arguments.Elements[0].AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
Assert.AreEqual<Int64>(2, call.Arguments.Elements[1].AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_RecordLiteral;
|
||||
@@ -226,14 +233,15 @@ begin
|
||||
Assert.AreEqual<TAstNodeKind>(TAstNodeKind.akRecordLiteral, node.Kind);
|
||||
rec := node.AsRecordLiteral;
|
||||
|
||||
Assert.AreEqual<Integer>(2, rec.Fields.Count);
|
||||
// Use Length(Elements) instead of Count
|
||||
Assert.AreEqual<Integer>(2, Length(rec.Fields.Elements));
|
||||
|
||||
// FIX: Cast elements to RecordField to access Key/Value
|
||||
Assert.AreEqual<string>('a', rec.Fields[0].AsRecordField.Key.Value.Name);
|
||||
Assert.AreEqual<Int64>(1, rec.Fields[0].AsRecordField.Value.AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
Assert.AreEqual<string>('a', rec.Fields.Elements[0].AsRecordField.Key.Value.Name);
|
||||
Assert.AreEqual<Int64>(1, rec.Fields.Elements[0].AsRecordField.Value.AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
|
||||
Assert.AreEqual<string>('b', rec.Fields[1].AsRecordField.Key.Value.Name);
|
||||
Assert.AreEqual<Int64>(2, rec.Fields[1].AsRecordField.Value.AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
Assert.AreEqual<string>('b', rec.Fields.Elements[1].AsRecordField.Key.Value.Name);
|
||||
Assert.AreEqual<Int64>(2, rec.Fields.Elements[1].AsRecordField.Value.AsConstant.Value.AsScalar.Value.AsInt64);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_RecordLiteral_Empty;
|
||||
@@ -242,7 +250,8 @@ var
|
||||
begin
|
||||
node := Parse('{}');
|
||||
Assert.AreEqual<TAstNodeKind>(TAstNodeKind.akRecordLiteral, node.Kind);
|
||||
Assert.AreEqual<Integer>(0, node.AsRecordLiteral.Fields.Count);
|
||||
// Use Length(Elements) instead of Count
|
||||
Assert.AreEqual<Integer>(0, Length(node.AsRecordLiteral.Fields.Elements));
|
||||
end;
|
||||
|
||||
// --- Special Forms ---
|
||||
@@ -271,10 +280,11 @@ begin
|
||||
Assert.AreEqual<TAstNodeKind>(TAstNodeKind.akLambdaExpression, node.Kind);
|
||||
lam := node.AsLambdaExpression;
|
||||
|
||||
Assert.AreEqual<Integer>(2, lam.Parameters.Count);
|
||||
// Use Length(Elements) instead of Count
|
||||
Assert.AreEqual<Integer>(2, Length(lam.Parameters.Elements));
|
||||
// FIX: Cast tuple items to Identifier to access Name
|
||||
Assert.AreEqual<string>('a', lam.Parameters[0].AsIdentifier.Name);
|
||||
Assert.AreEqual<string>('b', lam.Parameters[1].AsIdentifier.Name);
|
||||
Assert.AreEqual<string>('a', lam.Parameters.Elements[0].AsIdentifier.Name);
|
||||
Assert.AreEqual<string>('b', lam.Parameters.Elements[1].AsIdentifier.Name);
|
||||
|
||||
Assert.AreEqual<TAstNodeKind>(TAstNodeKind.akFunctionCall, lam.Body.Kind);
|
||||
end;
|
||||
@@ -322,8 +332,9 @@ begin
|
||||
call := node.AsFunctionCall;
|
||||
|
||||
Assert.AreEqual<string>('quote', call.Callee.AsIdentifier.Name);
|
||||
Assert.AreEqual<Integer>(1, call.Arguments.Count);
|
||||
Assert.AreEqual<string>('foo', call.Arguments[0].AsIdentifier.Name);
|
||||
// Use Length(Elements) instead of Count
|
||||
Assert.AreEqual<Integer>(1, Length(call.Arguments.Elements));
|
||||
Assert.AreEqual<string>('foo', call.Arguments.Elements[0].AsIdentifier.Name);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_Quasiquote_CreatesNode;
|
||||
@@ -360,27 +371,27 @@ end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_Error_UnbalancedParens_MissingRight;
|
||||
begin
|
||||
Assert.WillRaise(procedure begin Parse('(a b'); end);
|
||||
Assert.WillRaise(procedure begin Parse('(a b'); end, EParserException);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_Error_UnbalancedParens_ExtraRight;
|
||||
begin
|
||||
Assert.WillRaise(procedure begin Parse('a )'); end);
|
||||
Assert.WillRaise(procedure begin Parse('a )'); end, EParserException);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_Error_UnterminatedString;
|
||||
begin
|
||||
Assert.WillRaise(procedure begin Parse('"hello'); end);
|
||||
Assert.WillRaise(procedure begin Parse('"hello'); end, EParserException);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_Error_EmptyList;
|
||||
begin
|
||||
Assert.WillRaise(procedure begin Parse('()'); end);
|
||||
Assert.WillRaise(procedure begin Parse('()'); end, EParserException);
|
||||
end;
|
||||
|
||||
procedure TTestMycAstScript.Parser_Error_Record_MissingValue;
|
||||
begin
|
||||
Assert.WillRaise(procedure begin Parse('{:a 1 :b}'); end);
|
||||
Assert.WillRaise(procedure begin Parse('{:a 1 :b}'); end, EParserException);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user