Fix twig compare

This commit is contained in:
Diogo Pinheiro
2019-11-01 15:46:43 +00:00
committed by Fabien Potencier
parent 083e64f6d3
commit 0d81c6e5a2
6 changed files with 12 additions and 8 deletions
+1 -1
View File
@@ -989,7 +989,7 @@ function twig_compare($a, $b)
}
// fallback to <=>
return $b <=> $a;
return $a <=> $b;
}
/**
+1 -1
View File
@@ -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'))
+1 -1
View File
@@ -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'))
+7 -3
View File
@@ -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'],
];
}
}