document_rst_stack_test.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. <?php
  2. /**
  3. * ezcDocumentRstStackTests
  4. *
  5. * Licensed to the Apache Software Foundation (ASF) under one
  6. * or more contributor license agreements. See the NOTICE file
  7. * distributed with this work for additional information
  8. * regarding copyright ownership. The ASF licenses this file
  9. * to you under the Apache License, Version 2.0 (the
  10. * "License"); you may not use this file except in compliance
  11. * with the License. You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing,
  16. * software distributed under the License is distributed on an
  17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  18. * KIND, either express or implied. See the License for the
  19. * specific language governing permissions and limitations
  20. * under the License.
  21. *
  22. * @package Document
  23. * @version //autogen//
  24. * @subpackage Tests
  25. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  26. */
  27. /**
  28. * Test suite for class.
  29. *
  30. * @package Document
  31. * @subpackage Tests
  32. */
  33. class ezcDocumentRstStackTests extends ezcTestCase
  34. {
  35. protected static $testDocuments = null;
  36. public static function suite()
  37. {
  38. return new PHPUnit_Framework_TestSuite( __CLASS__ );
  39. }
  40. public function testUnShift()
  41. {
  42. $stack = new ezcDocumentRstStack();
  43. $array = array();
  44. $this->assertSame(
  45. array_unshift( $array, 1 ),
  46. $stack->unshift( 1 )
  47. );
  48. }
  49. public function testDoubleUnShift()
  50. {
  51. $stack = new ezcDocumentRstStack();
  52. $array = array();
  53. $this->assertSame(
  54. array_unshift( $array, 1 ),
  55. $stack->unshift( 1 )
  56. );
  57. $this->assertSame(
  58. array_unshift( $array, 23 ),
  59. $stack->unshift( 23 )
  60. );
  61. }
  62. public function testEmptyShift()
  63. {
  64. $stack = new ezcDocumentRstStack();
  65. $array = array();
  66. $this->assertSame(
  67. array_shift( $array ),
  68. $stack->shift()
  69. );
  70. }
  71. public function testShift()
  72. {
  73. $stack = new ezcDocumentRstStack();
  74. $array = array();
  75. $this->assertSame(
  76. array_unshift( $array, 1 ),
  77. $stack->unshift( 1 )
  78. );
  79. $this->assertSame(
  80. array_shift( $array ),
  81. $stack->shift()
  82. );
  83. }
  84. public function testDoubleShift()
  85. {
  86. $stack = new ezcDocumentRstStack();
  87. $array = array();
  88. $this->assertSame(
  89. array_unshift( $array, 1 ),
  90. $stack->unshift( 1 )
  91. );
  92. $this->assertSame(
  93. array_unshift( $array, 23 ),
  94. $stack->unshift( 23 )
  95. );
  96. $this->assertSame(
  97. array_shift( $array ),
  98. $stack->shift()
  99. );
  100. $this->assertSame(
  101. array_shift( $array ),
  102. $stack->shift()
  103. );
  104. }
  105. public function testCountEmpty()
  106. {
  107. $stack = new ezcDocumentRstStack();
  108. $array = array();
  109. $this->assertSame(
  110. count( $array ),
  111. $stack->count()
  112. );
  113. }
  114. public function testCountSingle()
  115. {
  116. $stack = new ezcDocumentRstStack();
  117. $array = array();
  118. $this->assertSame(
  119. array_unshift( $array, 1 ),
  120. $stack->unshift( 1 )
  121. );
  122. $this->assertSame(
  123. count( $array ),
  124. $stack->count()
  125. );
  126. }
  127. public function testCountDouble()
  128. {
  129. $stack = new ezcDocumentRstStack();
  130. $array = array();
  131. $this->assertSame(
  132. array_unshift( $array, 1 ),
  133. $stack->unshift( 1 )
  134. );
  135. $this->assertSame(
  136. array_unshift( $array, 23 ),
  137. $stack->unshift( 23 )
  138. );
  139. $this->assertSame(
  140. count( $array ),
  141. $stack->count()
  142. );
  143. }
  144. public function testCountDoubleReduced()
  145. {
  146. $stack = new ezcDocumentRstStack();
  147. $array = array();
  148. $this->assertSame(
  149. array_unshift( $array, 1 ),
  150. $stack->unshift( 1 )
  151. );
  152. $this->assertSame(
  153. array_unshift( $array, 23 ),
  154. $stack->unshift( 23 )
  155. );
  156. $this->assertSame(
  157. array_shift( $array ),
  158. $stack->shift()
  159. );
  160. $this->assertSame(
  161. count( $array ),
  162. $stack->count()
  163. );
  164. }
  165. public function testCountDoubleReducedTwice()
  166. {
  167. $stack = new ezcDocumentRstStack();
  168. $array = array();
  169. $this->assertSame(
  170. array_unshift( $array, 1 ),
  171. $stack->unshift( 1 )
  172. );
  173. $this->assertSame(
  174. array_unshift( $array, 23 ),
  175. $stack->unshift( 23 )
  176. );
  177. $this->assertSame(
  178. array_shift( $array ),
  179. $stack->shift()
  180. );
  181. $this->assertSame(
  182. array_shift( $array ),
  183. $stack->shift()
  184. );
  185. $this->assertSame(
  186. count( $array ),
  187. $stack->count()
  188. );
  189. }
  190. public function testCountDoubleReducedTriple()
  191. {
  192. $stack = new ezcDocumentRstStack();
  193. $array = array();
  194. $this->assertSame(
  195. array_unshift( $array, 1 ),
  196. $stack->unshift( 1 )
  197. );
  198. $this->assertSame(
  199. array_unshift( $array, 23 ),
  200. $stack->unshift( 23 )
  201. );
  202. $this->assertSame(
  203. array_shift( $array ),
  204. $stack->shift()
  205. );
  206. $this->assertSame(
  207. array_shift( $array ),
  208. $stack->shift()
  209. );
  210. $this->assertSame(
  211. array_shift( $array ),
  212. $stack->shift()
  213. );
  214. $this->assertSame(
  215. count( $array ),
  216. $stack->count()
  217. );
  218. }
  219. public function testPrepend()
  220. {
  221. $stack = new ezcDocumentRstStack();
  222. $stack->unshift( 1 );
  223. $array = array( 1 );
  224. $stack->prepend( $prepend = array( 23, 42 ) );
  225. $array = array_merge( $prepend, $array );
  226. $this->assertSame(
  227. count( $array ),
  228. $stack->count()
  229. );
  230. $this->assertSame(
  231. array_shift( $array ),
  232. $stack->shift()
  233. );
  234. $this->assertSame(
  235. array_shift( $array ),
  236. $stack->shift()
  237. );
  238. $this->assertSame(
  239. count( $array ),
  240. $stack->count()
  241. );
  242. $this->assertSame(
  243. array_shift( $array ),
  244. $stack->shift()
  245. );
  246. $this->assertSame(
  247. array_shift( $array ),
  248. $stack->shift()
  249. );
  250. }
  251. public function testArrayAccessGet()
  252. {
  253. $stack = new ezcDocumentRstStack();
  254. $stack->unshift( 1 );
  255. $array = array( 1 );
  256. $stack->prepend( $prepend = array( 23, 42 ) );
  257. $array = array_merge( $prepend, $array );
  258. $this->assertSame(
  259. $array[0],
  260. $stack[0]
  261. );
  262. $this->assertSame(
  263. $array[1],
  264. $stack[1]
  265. );
  266. $this->assertSame(
  267. $array[2],
  268. $stack[2]
  269. );
  270. }
  271. public function testArrayAccessIsset()
  272. {
  273. $stack = new ezcDocumentRstStack();
  274. $stack->unshift( 1 );
  275. $array = array( 1 );
  276. $stack->prepend( $prepend = array( 23, 42 ) );
  277. $array = array_merge( $prepend, $array );
  278. $this->assertSame(
  279. isset( $array[-1] ),
  280. isset( $stack[-1] )
  281. );
  282. $this->assertSame(
  283. isset( $array[0] ),
  284. isset( $stack[0] )
  285. );
  286. $this->assertSame(
  287. isset( $array[1] ),
  288. isset( $stack[1] )
  289. );
  290. $this->assertSame(
  291. isset( $array[2] ),
  292. isset( $stack[2] )
  293. );
  294. $this->assertSame(
  295. isset( $array[3] ),
  296. isset( $stack[3] )
  297. );
  298. }
  299. public function testRewindEmpty()
  300. {
  301. $stack = new ezcDocumentRstStack();
  302. $array = array();
  303. $this->assertSame(
  304. reset( $array ),
  305. $stack->rewind()
  306. );
  307. }
  308. public function testRewind()
  309. {
  310. $stack = new ezcDocumentRstStack();
  311. $stack->unshift( 1 );
  312. $array = array( 1 );
  313. $this->assertSame(
  314. reset( $array ),
  315. $stack->rewind()
  316. );
  317. }
  318. public function testRewindDouble()
  319. {
  320. $stack = new ezcDocumentRstStack();
  321. $array = array();
  322. array_unshift( $array, 1 );
  323. array_unshift( $array, 23 );
  324. $stack->unshift( 1 );
  325. $stack->unshift( 23 );
  326. $this->assertSame(
  327. reset( $array ),
  328. $stack->rewind()
  329. );
  330. }
  331. }
  332. ?>