summaryrefslogtreecommitdiff
path: root/_test
diff options
context:
space:
mode:
authorPatrick Brown <ptbrown@whoopdedo.org>2015-05-08 17:11:44 -0400
committerPatrick Brown <ptbrown@whoopdedo.org>2015-05-08 17:11:44 -0400
commit6c0002048504e43b399abece0668afa2b5c87a07 (patch)
tree39122fc8451db991988f1ff6fd211f5a90d9c5b0 /_test
parentd0d224a82eddf30aa6daead4796cb10dd0466767 (diff)
downloadrpg-6c0002048504e43b399abece0668afa2b5c87a07.tar.gz
rpg-6c0002048504e43b399abece0668afa2b5c87a07.tar.bz2
Limit number of lines to replace.
Diffstat (limited to '_test')
-rw-r--r--_test/tests/inc/io_replaceinfile.test.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/_test/tests/inc/io_replaceinfile.test.php b/_test/tests/inc/io_replaceinfile.test.php
new file mode 100644
index 000000000..98f21868f
--- /dev/null
+++ b/_test/tests/inc/io_replaceinfile.test.php
@@ -0,0 +1,58 @@
+<?php
+
+class io_replaceinfile_test extends DokuWikiTest {
+
+ /*
+ * dependency for tests needing zlib extension to pass
+ */
+ public function test_ext_zlib() {
+ if (!extension_loaded('zlib')) {
+ $this->markTestSkipped('skipping all zlib tests. Need zlib extension');
+ }
+ }
+
+ /*
+ * dependency for tests needing zlib extension to pass
+ */
+ public function test_ext_bz2() {
+ if (!extension_loaded('bz2')) {
+ $this->markTestSkipped('skipping all bzip2 tests. Need bz2 extension');
+ }
+ }
+
+ function _write($file){
+ $contents = "The\012Delete\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012";
+ io_saveFile($file, $contents);
+ // Replace one, no regex
+ $this->assertTrue(io_replaceInFile($file, "Delete\012", "Delete00\012", false, 1));
+ $this->assertEquals("The\012Delete00\012Delete\012Delete01\012Delete02\012Delete\012DeleteX\012Test\012", io_readFile($file));
+ // Replace all, no regex
+ $this->assertTrue(io_replaceInFile($file, "Delete\012", "DeleteX\012", false, -1));
+ $this->assertEquals("The\012Delete00\012DeleteX\012Delete01\012Delete02\012DeleteX\012DeleteX\012Test\012", io_readFile($file));
+ // Replace two, regex and backreference
+ $this->assertTrue(io_replaceInFile($file, "#Delete(\\d+)\012#", "\\1\012", true, 2));
+ $this->assertEquals("The\01200\012DeleteX\01201\012Delete02\012DeleteX\012DeleteX\012Test\012", io_readFile($file));
+ // Delete and insert, no regex
+ $this->assertTrue(io_replaceInFile($file, "DeleteX\012", "Replace\012", false, 0));
+ $this->assertEquals("The\01200\01201\012Delete02\012Test\012Replace\012", io_readFile($file));
+ }
+
+ function test_replace(){
+ $this->_write(TMP_DIR.'/test.txt');
+ }
+
+ /**
+ * @depends test_ext_zlib
+ */
+ function test_gzwrite(){
+ $this->_write(TMP_DIR.'/test.txt.gz');
+ }
+
+ /**
+ * @depends test_ext_bz2
+ */
+ function test_bzwrite(){
+ $this->_write(TMP_DIR.'/test.txt.bz2');
+ }
+
+}