token_get_all_variation14.phpt 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. --TEST--
  2. Test token_get_all() function : usage variations - invalid token values
  3. --SKIPIF--
  4. <?php if (!extension_loaded("tokenizer")) print "skip"; ?>
  5. --FILE--
  6. <?php
  7. /* Prototype : array token_get_all(string $source)
  8. * Description: splits the given source into an array of PHP languange tokens
  9. * Source code: ext/tokenizer/tokenizer.c
  10. */
  11. /*
  12. * Testing token_get_all() with 'source' string containing invalid/unknown token value
  13. * unknown tokens - T_UNKNOWN(307)
  14. */
  15. echo "*** Testing token_get_all() : with invalid/unknown tokens ***\n";
  16. // with valid php tags and invalid tokens
  17. echo "-- with valid PHP tags & invlid tokens --\n";
  18. $source = '<?php
  19. struct myStruct {
  20. variable $a;
  21. method() { display $a; }
  22. }
  23. ?>';
  24. var_dump( token_get_all($source));
  25. // with invalid open tag for testing entire source to be unknown token
  26. echo "-- with invlalid PHP open tag & valid tokens --\n";
  27. $source = '<pli
  28. echo "hello world"; ?>';
  29. var_dump( token_get_all($source));
  30. // with invalid PHP tags and invalid tokens
  31. echo "-- with invalid PHP tags and tokens --\n";
  32. $source = '<PDP display $a; <';
  33. var_dump( token_get_all($source));
  34. echo "Done"
  35. ?>
  36. --EXPECTF--
  37. *** Testing token_get_all() : with invalid/unknown tokens ***
  38. -- with valid PHP tags & invlid tokens --
  39. array(29) {
  40. [0]=>
  41. array(3) {
  42. [0]=>
  43. int(%d)
  44. [1]=>
  45. string(6) "<?php "
  46. [2]=>
  47. int(1)
  48. }
  49. [1]=>
  50. array(3) {
  51. [0]=>
  52. int(%d)
  53. [1]=>
  54. string(1) "
  55. "
  56. [2]=>
  57. int(1)
  58. }
  59. [2]=>
  60. array(3) {
  61. [0]=>
  62. int(%d)
  63. [1]=>
  64. string(6) "struct"
  65. [2]=>
  66. int(2)
  67. }
  68. [3]=>
  69. array(3) {
  70. [0]=>
  71. int(%d)
  72. [1]=>
  73. string(1) " "
  74. [2]=>
  75. int(2)
  76. }
  77. [4]=>
  78. array(3) {
  79. [0]=>
  80. int(%d)
  81. [1]=>
  82. string(8) "myStruct"
  83. [2]=>
  84. int(2)
  85. }
  86. [5]=>
  87. array(3) {
  88. [0]=>
  89. int(%d)
  90. [1]=>
  91. string(1) " "
  92. [2]=>
  93. int(2)
  94. }
  95. [6]=>
  96. string(1) "{"
  97. [7]=>
  98. array(3) {
  99. [0]=>
  100. int(%d)
  101. [1]=>
  102. string(3) "
  103. "
  104. [2]=>
  105. int(2)
  106. }
  107. [8]=>
  108. array(3) {
  109. [0]=>
  110. int(%d)
  111. [1]=>
  112. string(8) "variable"
  113. [2]=>
  114. int(%d)
  115. }
  116. [9]=>
  117. array(3) {
  118. [0]=>
  119. int(%d)
  120. [1]=>
  121. string(1) " "
  122. [2]=>
  123. int(%d)
  124. }
  125. [10]=>
  126. array(3) {
  127. [0]=>
  128. int(%d)
  129. [1]=>
  130. string(2) "$a"
  131. [2]=>
  132. int(%d)
  133. }
  134. [11]=>
  135. string(1) ";"
  136. [12]=>
  137. array(3) {
  138. [0]=>
  139. int(%d)
  140. [1]=>
  141. string(3) "
  142. "
  143. [2]=>
  144. int(%d)
  145. }
  146. [13]=>
  147. array(3) {
  148. [0]=>
  149. int(%d)
  150. [1]=>
  151. string(6) "method"
  152. [2]=>
  153. int(4)
  154. }
  155. [14]=>
  156. string(1) "("
  157. [15]=>
  158. string(1) ")"
  159. [16]=>
  160. array(3) {
  161. [0]=>
  162. int(%d)
  163. [1]=>
  164. string(1) " "
  165. [2]=>
  166. int(4)
  167. }
  168. [17]=>
  169. string(1) "{"
  170. [18]=>
  171. array(3) {
  172. [0]=>
  173. int(%d)
  174. [1]=>
  175. string(1) " "
  176. [2]=>
  177. int(4)
  178. }
  179. [19]=>
  180. array(3) {
  181. [0]=>
  182. int(%d)
  183. [1]=>
  184. string(7) "display"
  185. [2]=>
  186. int(4)
  187. }
  188. [20]=>
  189. array(3) {
  190. [0]=>
  191. int(%d)
  192. [1]=>
  193. string(1) " "
  194. [2]=>
  195. int(4)
  196. }
  197. [21]=>
  198. array(3) {
  199. [0]=>
  200. int(%d)
  201. [1]=>
  202. string(2) "$a"
  203. [2]=>
  204. int(4)
  205. }
  206. [22]=>
  207. string(1) ";"
  208. [23]=>
  209. array(3) {
  210. [0]=>
  211. int(%d)
  212. [1]=>
  213. string(1) " "
  214. [2]=>
  215. int(4)
  216. }
  217. [24]=>
  218. string(1) "}"
  219. [25]=>
  220. array(3) {
  221. [0]=>
  222. int(%d)
  223. [1]=>
  224. string(1) "
  225. "
  226. [2]=>
  227. int(4)
  228. }
  229. [26]=>
  230. string(1) "}"
  231. [27]=>
  232. array(3) {
  233. [0]=>
  234. int(%d)
  235. [1]=>
  236. string(1) "
  237. "
  238. [2]=>
  239. int(5)
  240. }
  241. [28]=>
  242. array(3) {
  243. [0]=>
  244. int(%d)
  245. [1]=>
  246. string(2) "?>"
  247. [2]=>
  248. int(6)
  249. }
  250. }
  251. -- with invlalid PHP open tag & valid tokens --
  252. array(1) {
  253. [0]=>
  254. array(3) {
  255. [0]=>
  256. int(%d)
  257. [1]=>
  258. string(28) "<pli
  259. echo "hello world"; ?>"
  260. [2]=>
  261. int(1)
  262. }
  263. }
  264. -- with invalid PHP tags and tokens --
  265. array(1) {
  266. [0]=>
  267. array(3) {
  268. [0]=>
  269. int(%d)
  270. [1]=>
  271. string(19) "<PDP display $a; <"
  272. [2]=>
  273. int(1)
  274. }
  275. }
  276. Done