code = new WactCodeWriter(); // preparing tree nodes with runtime $this->root = new WactCompileTreeRootNode(); $this->context = new WactCompileTreeNode(); $this->context->setServerId('child'); $this->context->parent = $this->root; $this->parser = new WactExpressionValueParser($this->context); } function tearDown() { unset($this->parser); } function _parseAndReturnGeneratedCode($expression) { $expr = $this->parser->parse($expression); $expr->generatePreStatement($this->code); $expr->generateExpression($this->code); $expr->generatePostStatement($this->code); return $this->code->getCode(); } function testNull() { $code = $this->_parseAndReturnGeneratedCode('null'); $this->assertEqual($code, '_parseAndReturnGeneratedCode('true'); $this->assertEqual($code, '_parseAndReturnGeneratedCode('false'); $this->assertEqual($code, '_parseAndReturnGeneratedCode('1'); $this->assertEqual($code, '_parseAndReturnGeneratedCode('0'); $this->assertEqual($code, '_parseAndReturnGeneratedCode('1.2'); $this->assertEqual($code, 'parser->parse('"hello"'); $this->assertIdentical($expr->getValue(), "hello"); } function testZeroDoubleQuotes() { $expr = $this->parser->parse('"0"'); $this->assertIdentical($expr->getValue(), "0"); } function testStringSingleQuotes() { $expr = $this->parser->parse("'hello'"); $this->assertIdentical($expr->getValue(), "hello"); } function testSeveralDots() { $expr = $this->parser->parse('"..."'); $this->assertIdentical($expr->getValue(), '...'); } function testAddition() { $code = $this->_parseAndReturnGeneratedCode('1+2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('1-2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('2*3'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('8/2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('5%2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('-2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('"head" & "tail"'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('true && false'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('true || false'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('!false'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('1 == 1'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('1!=2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('1 < 2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('2 <= 2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('3 > 2'); $this->assertEqual($code, "2"); } function testLogicalGreaterThanOrEqual() { $code = $this->_parseAndReturnGeneratedCode('3 >= 2'); $this->assertEqual($code, "=2"); } function testMyDearAuntSally() { $code = $this->_parseAndReturnGeneratedCode('1+2*3'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('2*3+1'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('2*3+4*5'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('8-4-2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('24*6*2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('24/6/2'); $this->assertEqual($code, "_parseAndReturnGeneratedCode('8-(4-2)'); $this->assertEqual($code, "context->registerProperty('Test', $property); $expr = $this->parser->parse('Test'); $this->assertIdentical($expr->getValue(),'hello'); } function testConstantPropertyWithNewSyntax() { $property = new WactConstantProperty('hello'); $this->root->registerProperty('Test', $property); $expr = $this->parser->parse(':Test'); $this->assertIdentical($expr->getValue(),'hello'); } function testConstantPropertyFromRootContext() { $property = new WactConstantProperty('hello'); $this->root->registerProperty('Test', $property); $expr = $this->parser->parse('#Test'); $this->assertIdentical($expr->getValue(),'hello'); } function testConstantPropertyFromParentContext() { $property = new WactConstantProperty('hello'); $this->root->registerProperty('Test', $property); $expr = $this->parser->parse('^Test'); $this->assertIdentical($expr->getValue(),'hello'); } function testConstantPropertyFromParentContextWithNewSyntax() { $property = new WactConstantProperty('hello'); $this->root->registerProperty('Test', $property); $expr = $this->parser->parse('^:Test'); $this->assertIdentical($expr->getValue(),'hello'); } function testLocalVariableModifier() { $expr = $this->parser->parse('$Test'); $code_writer = new WactCodeWriter(); $root = new WactCompileTreeRootNode(); $context = new WactCompileTreeNode(); $context->parent = $root; $expr->generatePreStatement($code_writer); $expr->generateExpression($code_writer); $expr->generatePostStatement($code_writer); $this->assertEqual($code_writer->getCode(), '