@@ -373,12 +373,20 @@ class ParserTests: XCTestCase {
373
373
"""
374
374
375
375
let parser = Parser ( program)
376
- _ = parser. parse ( )
376
+ let result = parser. parse ( )
377
+ let compound = Compound ( children: [ Assignment ( left: Variable ( name: " result " ) , right: FunctionCall ( name: " Factorial " , actualParameters: [ Number . integer ( 6 ) ] ) ) , NoOp ( ) ] )
378
+ let resultDeclaration = VariableDeclaration ( variable: Variable ( name: " result " ) , type: VariableType ( type: . integer) )
379
+ let ifelse = IfElse ( condition: Condition ( type: . greaterThan, leftSide: Variable ( name: " number " ) , rightSide: Number . integer ( 1 ) ) , trueExpression: Assignment ( left: Variable ( name: " Factorial " ) , right: BinaryOperation ( left: Variable ( name: " number " ) , operation: . mult, right: FunctionCall ( name: " Factorial " , actualParameters: [ BinaryOperation ( left: Variable ( name: " number " ) , operation: . minus, right: Number . integer ( 1 ) ) ] ) ) ) , falseExpression: Assignment ( left: Variable ( name: " Factorial " ) , right: Number . integer ( 1 ) ) )
380
+ let factorialBlock = Block ( declarations: [ ] , compound: Compound ( children: [ ifelse] ) )
381
+ let factorialDeclarion = Function ( name: " Factorial " , params: [ Param ( name: " number " , type: VariableType ( type: . integer) ) ] , block: factorialBlock, returnType: VariableType ( type: . integer) )
382
+ let block = Block ( declarations: [ resultDeclaration, factorialDeclarion] , compound: compound)
383
+ let node = Program ( name: " Main " , block: block)
384
+ XCTAssertEqual ( result, node)
377
385
}
378
386
379
387
func testProgramWithStringConstants( ) {
380
388
let program =
381
- """
389
+ """
382
390
program Main;
383
391
var s: String;
384
392
a: Boolean;
@@ -390,6 +398,10 @@ class ParserTests: XCTestCase {
390
398
"""
391
399
392
400
let parser = Parser ( program)
393
- _ = parser. parse ( )
401
+ let result = parser. parse ( )
402
+ let compound = Compound ( children: [ Assignment ( left: Variable ( name: " s " ) , right: " Test " ) , Assignment ( left: Variable ( name: " a " ) , right: false ) , FunctionCall ( name: " writeln " , actualParameters: [ Variable ( name: " s " ) , Variable ( name: " a " ) ] ) , NoOp ( ) ] )
403
+ let block = Block ( declarations: [ VariableDeclaration ( variable: Variable ( name: " s " ) , type: VariableType ( type: . string) ) , VariableDeclaration ( variable: Variable ( name: " a " ) , type: VariableType ( type: . boolean) ) ] , compound: compound)
404
+ let node = Program ( name: " Main " , block: block)
405
+ XCTAssertEqual ( result, node)
394
406
}
395
407
}
0 commit comments