mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-30 03:57:21 +00:00
Fix twig compare
This commit is contained in:
committed by
Fabien Potencier
parent
083e64f6d3
commit
0d81c6e5a2
@@ -989,7 +989,7 @@ function twig_compare($a, $b)
|
||||
}
|
||||
|
||||
// fallback to <=>
|
||||
return $b <=> $a;
|
||||
return $a <=> $b;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,7 +24,7 @@ class GreaterBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('-1 === twig_compare(')
|
||||
->raw('1 === twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
|
||||
@@ -24,7 +24,7 @@ class GreaterEqualBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('0 >= twig_compare(')
|
||||
->raw('0 <= twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
|
||||
@@ -24,7 +24,7 @@ class LessBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('1 === twig_compare(')
|
||||
->raw('-1 === twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
|
||||
@@ -24,7 +24,7 @@ class LessEqualBinary extends AbstractBinary
|
||||
}
|
||||
|
||||
$compiler
|
||||
->raw('0 <= twig_compare(')
|
||||
->raw('0 >= twig_compare(')
|
||||
->subcompile($this->getNode('left'))
|
||||
->raw(', ')
|
||||
->subcompile($this->getNode('right'))
|
||||
|
||||
@@ -285,10 +285,10 @@ class CoreTest extends TestCase
|
||||
|
||||
[0, '0', '0'],
|
||||
[0, '0', '0.0'],
|
||||
[1, '0', 'foo'],
|
||||
[-1, '0', ''],
|
||||
[-1, '0', 'foo'],
|
||||
[1, '0', ''],
|
||||
[0, '42', ' 42'],
|
||||
[1, '42', '42foo'],
|
||||
[-1, '42', '42foo'],
|
||||
|
||||
[0, 42, '000042'],
|
||||
[0, 42, '42.0'],
|
||||
@@ -310,6 +310,10 @@ class CoreTest extends TestCase
|
||||
[0, -INF, '-INF'],
|
||||
[0, INF, '1e1000'],
|
||||
[0, -INF, '-1e1000'],
|
||||
|
||||
[-1, 10, 20],
|
||||
[-1, '10', 20],
|
||||
[-1, 10, '20'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user