Pastakhov has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/58453


Change subject: add not case sensitive false and true (version 0.0.8)
......................................................................

add not case sensitive false and true (version 0.0.8)

example:

echo tRuE; // out 1

Change-Id: Ib34e590480b47cff17f65c3c55fc07daabae16a8
---
M Foxway.php
M includes/Interpreter.php
M tests/phpunit/includes/InterpreterTest.php
3 files changed, 57 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Foxway 
refs/changes/53/58453/1

diff --git a/Foxway.php b/Foxway.php
index ca305de..cd71152 100644
--- a/Foxway.php
+++ b/Foxway.php
@@ -15,7 +15,7 @@
        die( 'This file is an extension to MediaWiki and thus not a valid entry 
point.' );
 }
 
-define( 'Foxway_VERSION' , '0.0.7' );
+define( 'Foxway_VERSION' , '0.0.8' );
 
 // Register this extension on Special:Version
 $wgExtensionCredits['parserhook'][] = array(
diff --git a/includes/Interpreter.php b/includes/Interpreter.php
index b9abcb6..dab7d7d 100644
--- a/includes/Interpreter.php
+++ b/includes/Interpreter.php
@@ -243,6 +243,16 @@
                                                        );
                                        }
                                        break;
+                               case T_STRING:
+                                       if( strcasecmp($text, 'true') == 0 ) {
+                                               $runtime->addParam( true );
+                                       } elseif( strcasecmp($text, 'false') == 
0 ) {
+                                               $runtime->addParam( false );
+                                       } else {
+                                               $return .= '<br><span 
class="error">' . wfMessage( 'foxway-php-syntax-error-unexpected', "'$text'", 
$line )->escaped() . '</span>';
+                                               break 2;
+                                       }
+                                       break;
                        }
                        if( $id != T_VARIABLE && $id != T_INC && $id != T_DEC ) 
{
                                $incrementVariable = false;
@@ -266,6 +276,7 @@
                                case T_CONSTANT_ENCAPSED_STRING:
                                case T_LNUMBER:
                                case T_DNUMBER:
+                               case T_STRING:
                                        $expected = self::$arrayOperators;
                                        if($expectListParams){
                                                $expected[] = ',';
@@ -315,6 +326,7 @@
                                                T_LNUMBER, // 123, 012, 0x1ac
                                                T_DNUMBER, // 0.12
                                                T_VARIABLE, // $foo
+                                               T_STRING,
                                                T_INC, // ++
                                                T_DEC, // --
                                                T_CURLY_OPEN, // {
@@ -389,6 +401,12 @@
                                        case T_ECHO:
                                        case T_VARIABLE:
                                                break;
+                                       case T_STRING:
+                                       if( strcasecmp($text, 'true') == 0 || 
strcasecmp($text, 'false') == 0 ) {
+                                               $debug[] = '<span 
style="color:#0000E6" title="'. token_name($id) . '">' . 
htmlspecialchars($text) . '</span>';
+                                               break;
+                                       }
+                                       // break is not necessary here
                                        default:
                                                if( is_array($token) ) {
                                                        $debug[] = '<span 
title="'. token_name($id) . '">' . htmlspecialchars($text) . '</span>';
diff --git a/tests/phpunit/includes/InterpreterTest.php 
b/tests/phpunit/includes/InterpreterTest.php
index 921b960..4ff2c6a 100644
--- a/tests/phpunit/includes/InterpreterTest.php
+++ b/tests/phpunit/includes/InterpreterTest.php
@@ -514,4 +514,42 @@
                                );
        }
 
+       public function testRun_echo_compare_false() {
+               $this->assertEquals(
+                               Interpreter::run('echo ( 5 === (string)5 ) === 
false;'),
+                               '1'
+                               );
+       }
+       public function testRun_echo_compare_true() {
+               $this->assertEquals(
+                               Interpreter::run('echo (100 == "1e2") === 
true;'),
+                               '1'
+                               );
+       }
+       public function testRun_echo_compare_false_true() {
+               $this->assertEquals(
+                               Interpreter::run('echo (false === true) == 
false;'),
+                               '1'
+                               );
+       }
+       public function testRun_echo_compare_true_true() {
+               $this->assertEquals(
+                               Interpreter::run('echo true === true === 
true;'),
+                               '1'
+                               );
+       }
+
+       public function testRun_echo_true() {
+               $this->assertEquals(
+                               Interpreter::run('echo true;'),
+                               '1'
+                               );
+       }
+       public function testRun_echo_false() {
+               $this->assertEquals(
+                               Interpreter::run('echo false;'),
+                               ''
+                               );
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/58453
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib34e590480b47cff17f65c3c55fc07daabae16a8
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Foxway
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <pastak...@yandex.ru>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to