test.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. // CodeMirror, copyright (c) by Marijn Haverbeke and others
  2. // Distributed under an MIT license: http://codemirror.net/LICENSE
  3. (function() {
  4. var mode = CodeMirror.getMode({indentUnit: 2}, "php");
  5. function MT(name) { test.mode(name, mode, Array.prototype.slice.call(arguments, 1)); }
  6. MT('simple_test',
  7. '[meta <?php] ' +
  8. '[keyword echo] [string "aaa"]; ' +
  9. '[meta ?>]');
  10. MT('variable_interpolation_non_alphanumeric',
  11. '[meta <?php]',
  12. '[keyword echo] [string "aaa$~$!$@$#$$$%$^$&$*$($)$.$<$>$/$\\$}$\\\"$:$;$?$|$[[$]]$+$=aaa"]',
  13. '[meta ?>]');
  14. MT('variable_interpolation_digits',
  15. '[meta <?php]',
  16. '[keyword echo] [string "aaa$1$2$3$4$5$6$7$8$9$0aaa"]',
  17. '[meta ?>]');
  18. MT('variable_interpolation_simple_syntax_1',
  19. '[meta <?php]',
  20. '[keyword echo] [string "aaa][variable-2 $aaa][string .aaa"];',
  21. '[meta ?>]');
  22. MT('variable_interpolation_simple_syntax_2',
  23. '[meta <?php]',
  24. '[keyword echo] [string "][variable-2 $aaaa][[','[number 2]', ']][string aa"];',
  25. '[keyword echo] [string "][variable-2 $aaaa][[','[number 2345]', ']][string aa"];',
  26. '[keyword echo] [string "][variable-2 $aaaa][[','[number 2.3]', ']][string aa"];',
  27. '[keyword echo] [string "][variable-2 $aaaa][[','[variable aaaaa]', ']][string aa"];',
  28. '[keyword echo] [string "][variable-2 $aaaa][[','[variable-2 $aaaaa]',']][string aa"];',
  29. '[keyword echo] [string "1aaa][variable-2 $aaaa][[','[number 2]', ']][string aa"];',
  30. '[keyword echo] [string "aaa][variable-2 $aaaa][[','[number 2345]', ']][string aa"];',
  31. '[keyword echo] [string "aaa][variable-2 $aaaa][[','[number 2.3]', ']][string aa"];',
  32. '[keyword echo] [string "aaa][variable-2 $aaaa][[','[variable aaaaa]', ']][string aa"];',
  33. '[keyword echo] [string "aaa][variable-2 $aaaa][[','[variable-2 $aaaaa]',']][string aa"];',
  34. '[meta ?>]');
  35. MT('variable_interpolation_simple_syntax_3',
  36. '[meta <?php]',
  37. '[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string .aaaaaa"];',
  38. '[keyword echo] [string "aaa][variable-2 $aaaa][string ->][variable-2 $aaaaa][string .aaaaaa"];',
  39. '[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string [[2]].aaaaaa"];',
  40. '[keyword echo] [string "aaa][variable-2 $aaaa]->[variable aaaaa][string ->aaaa2.aaaaaa"];',
  41. '[meta ?>]');
  42. MT('variable_interpolation_escaping',
  43. '[meta <?php] [comment /* Escaping */]',
  44. '[keyword echo] [string "aaa\\$aaaa->aaa.aaa"];',
  45. '[keyword echo] [string "aaa\\$aaaa[[2]]aaa.aaa"];',
  46. '[keyword echo] [string "aaa\\$aaaa[[asd]]aaa.aaa"];',
  47. '[keyword echo] [string "aaa{\\$aaaa->aaa.aaa"];',
  48. '[keyword echo] [string "aaa{\\$aaaa[[2]]aaa.aaa"];',
  49. '[keyword echo] [string "aaa{\\aaaaa[[asd]]aaa.aaa"];',
  50. '[keyword echo] [string "aaa\\${aaaa->aaa.aaa"];',
  51. '[keyword echo] [string "aaa\\${aaaa[[2]]aaa.aaa"];',
  52. '[keyword echo] [string "aaa\\${aaaa[[asd]]aaa.aaa"];',
  53. '[meta ?>]');
  54. MT('variable_interpolation_complex_syntax_1',
  55. '[meta <?php]',
  56. '[keyword echo] [string "aaa][variable-2 $]{[variable aaaa]}[string ->aaa.aaa"];',
  57. '[keyword echo] [string "aaa][variable-2 $]{[variable-2 $aaaa]}[string ->aaa.aaa"];',
  58. '[keyword echo] [string "aaa][variable-2 $]{[variable-2 $aaaa][[',' [number 42]',']]}[string ->aaa.aaa"];',
  59. '[keyword echo] [string "aaa][variable-2 $]{[variable aaaa][meta ?>]aaaaaa');
  60. MT('variable_interpolation_complex_syntax_2',
  61. '[meta <?php] [comment /* Monsters */]',
  62. '[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*}?>} $aaa<?php } */]}[string ->aaa.aaa"];',
  63. '[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*}?>*/][[',' [string "aaa][variable-2 $aaa][string {}][variable-2 $]{[variable aaa]}[string "]',']]}[string ->aaa.aaa"];',
  64. '[keyword echo] [string "][variable-2 $]{[variable aaa][comment /*} } $aaa } */]}[string ->aaa.aaa"];');
  65. function build_recursive_monsters(nt, t, n){
  66. var monsters = [t];
  67. for (var i = 1; i <= n; ++i)
  68. monsters[i] = nt.join(monsters[i - 1]);
  69. return monsters;
  70. }
  71. var m1 = build_recursive_monsters(
  72. ['[string "][variable-2 $]{[variable aaa] [operator +] ', '}[string "]'],
  73. '[comment /* }?>} */] [string "aaa][variable-2 $aaa][string .aaa"]',
  74. 10
  75. );
  76. MT('variable_interpolation_complex_syntax_3_1',
  77. '[meta <?php] [comment /* Recursive monsters */]',
  78. '[keyword echo] ' + m1[4] + ';',
  79. '[keyword echo] ' + m1[7] + ';',
  80. '[keyword echo] ' + m1[8] + ';',
  81. '[keyword echo] ' + m1[5] + ';',
  82. '[keyword echo] ' + m1[1] + ';',
  83. '[keyword echo] ' + m1[6] + ';',
  84. '[keyword echo] ' + m1[9] + ';',
  85. '[keyword echo] ' + m1[0] + ';',
  86. '[keyword echo] ' + m1[10] + ';',
  87. '[keyword echo] ' + m1[2] + ';',
  88. '[keyword echo] ' + m1[3] + ';',
  89. '[keyword echo] [string "end"];',
  90. '[meta ?>]');
  91. var m2 = build_recursive_monsters(
  92. ['[string "a][variable-2 $]{[variable aaa] [operator +] ', ' [operator +] ', '}[string .a"]'],
  93. '[comment /* }?>{{ */] [string "a?>}{{aa][variable-2 $aaa][string .a}a?>a"]',
  94. 5
  95. );
  96. MT('variable_interpolation_complex_syntax_3_2',
  97. '[meta <?php] [comment /* Recursive monsters 2 */]',
  98. '[keyword echo] ' + m2[0] + ';',
  99. '[keyword echo] ' + m2[1] + ';',
  100. '[keyword echo] ' + m2[5] + ';',
  101. '[keyword echo] ' + m2[4] + ';',
  102. '[keyword echo] ' + m2[2] + ';',
  103. '[keyword echo] ' + m2[3] + ';',
  104. '[keyword echo] [string "end"];',
  105. '[meta ?>]');
  106. function build_recursive_monsters_2(mf1, mf2, nt, t, n){
  107. var monsters = [t];
  108. for (var i = 1; i <= n; ++i)
  109. monsters[i] = nt[0] + mf1[i - 1] + nt[1] + mf2[i - 1] + nt[2] + monsters[i - 1] + nt[3];
  110. return monsters;
  111. }
  112. var m3 = build_recursive_monsters_2(
  113. m1,
  114. m2,
  115. ['[string "a][variable-2 $]{[variable aaa] [operator +] ', ' [operator +] ', ' [operator +] ', '}[string .a"]'],
  116. '[comment /* }?>{{ */] [string "a?>}{{aa][variable-2 $aaa][string .a}a?>a"]',
  117. 4
  118. );
  119. MT('variable_interpolation_complex_syntax_3_3',
  120. '[meta <?php] [comment /* Recursive monsters 2 */]',
  121. '[keyword echo] ' + m3[4] + ';',
  122. '[keyword echo] ' + m3[0] + ';',
  123. '[keyword echo] ' + m3[3] + ';',
  124. '[keyword echo] ' + m3[1] + ';',
  125. '[keyword echo] ' + m3[2] + ';',
  126. '[keyword echo] [string "end"];',
  127. '[meta ?>]');
  128. MT("variable_interpolation_heredoc",
  129. "[meta <?php]",
  130. "[string <<<here]",
  131. "[string doc ][variable-2 $]{[variable yay]}[string more]",
  132. "[string here]; [comment // normal]");
  133. })();