TextToLatexTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Mike van Riel
  4. *
  5. * PHP Version 5.0
  6. *
  7. * @copyright 2010-2013 Mike van Riel (http://www.mikevanriel.com)
  8. * @license http://www.opensource.org/licenses/mit-license.php MIT
  9. * @link https://github.com/mvriel/TextToLatex
  10. */
  11. namespace MikeVanRiel;
  12. /**
  13. * Tests the TextToLatex class.
  14. */
  15. class TextToLatexTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /** @var TextToLatex */
  18. protected $fixture;
  19. /**
  20. * Instantiates a default TextToLatex object.
  21. */
  22. public function setUp()
  23. {
  24. $this->fixture = new TextToLatex();
  25. }
  26. /**
  27. * @param string $character The character to test.
  28. *
  29. * @dataProvider provideReservedCharacters
  30. * @covers MikeVanRiel::TextToLatex
  31. */
  32. public function testConvertsReservedCharactersToEscapedVersion($character)
  33. {
  34. $this->assertSame('\\'.$character, $this->fixture->convert($character));
  35. }
  36. /**
  37. * @covers MikeVanRiel::TextToLatex
  38. */
  39. public function testConvertBackslashToSpecialCode()
  40. {
  41. $this->assertSame('{\textbackslash}', $this->fixture->convert('\\'));
  42. }
  43. /**
  44. * @covers MikeVanRiel::TextToLatex
  45. */
  46. public function testConvertEllipsisToSpecialCode()
  47. {
  48. $this->assertSame('123{\ldots}456', $this->fixture->convert('123...456'));
  49. $this->assertSame('try{\ldots}catch', $this->fixture->convert('try...catch'));
  50. }
  51. /**
  52. * @covers MikeVanRiel::TextToLatex
  53. */
  54. public function testConvertDoubleQuotesToBackTicks()
  55. {
  56. $this->assertSame("``456''", $this->fixture->convert('"456"'));
  57. }
  58. /**
  59. * Provides all reserver characters that need to be escaped.
  60. *
  61. * @return string[][]
  62. */
  63. public function provideReservedCharacters()
  64. {
  65. return array(
  66. array('#'),
  67. array('{'),
  68. array('}'),
  69. array('_'),
  70. array('&'),
  71. );
  72. }
  73. }