<commit_before><?php

  namespace PHPCoord;

  require_once(__DIR__.'/../StringStream.php');

  class test extends \PHPUnit_Framework_TestCase {
    
    public static function setUpBeforeClass() {
      stream_wrapper_register('string', '\DVDoug\StringStream\StringStream');
    }
    
    public function testReadOnly() {
      $handle = fopen('string://foobar', 'r');
      
      self::assertEquals('foobar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));
      
      fwrite($handle, 'bar');
      
      self::assertEquals('foobar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testReadWriteNoTruncate() {
      $handle = fopen('string://foobar', 'r+');
     
      fwrite($handle, 'bar');
      
      self::assertEquals('barbar', stream_get_contents($handle, -1, 0));
      self::assertEquals('bar', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testWriteOnlyTruncate() {
      $handle = fopen('string://foobar', 'w');
      
      self::assertEquals(0, ftell($handle));
      
      self::assertEquals('', stream_get_contents($handle, -1, 0));
      
      fwrite($handle, 'bar');
      
      self::assertEquals(3, ftell($handle));

      fclose($handle);
    }
    
    public function testReadWriteTruncate() {
      $handle = fopen('string://foobar', 'w+');
      self::assertEquals(0, ftell($handle));
      
      fwrite($handle, 'bar');
      
      self::assertEquals('bar', stream_get_contents($handle, -1, 0));
      self::assertEquals('bar', stream_get_contents($handle, 3, 0));
      self::assertEquals('', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testWriteOnlyAppend() {
      $handle = fopen('string://foobar', 'a');
      self::assertEquals(6, ftell($handle));
      
      fwrite($handle, 'bar');
      
      self::assertEquals(9, ftell($handle));

      fclose($handle);
    }
    
    public function testReadWriteAppend() {
      $handle = fopen('string://foobar', 'a+');
      self::assertEquals('foobar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));
      
      fwrite($handle, 'bar');
      
      self::assertEquals('foobarbar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('barbar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testWriteOnlyNoTruncate() {
      $handle = fopen('string://foobar', 'c');
      self::assertEquals(0, ftell($handle));
      
      fwrite($handle, 'bar');
      
      self::assertEquals(3, ftell($handle));
      
      fclose($handle);
    }
    
    public function testReadWriteNoTruncate2() {
      $handle = fopen('string://foobar', 'c+');
     
      fwrite($handle, 'bar');
      
      self::assertEquals('barbar', stream_get_contents($handle, -1, 0));
      self::assertEquals('bar', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testTruncateExtension() {<commit_msg>Skip truncate test for PHP5.3<commit_after><?php

  namespace PHPCoord;

  require_once(__DIR__.'/../StringStream.php');

  class test extends \PHPUnit_Framework_TestCase {
    
    public static function setUpBeforeClass() {
      stream_wrapper_register('string', '\DVDoug\StringStream\StringStream');
    }
    
    public function testReadOnly() {
      $handle = fopen('string://foobar', 'r');
      
      self::assertEquals('foobar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));
      
      fwrite($handle, 'bar');
      
      self::assertEquals('foobar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testReadWriteNoTruncate() {
      $handle = fopen('string://foobar', 'r+');
     
      fwrite($handle, 'bar');
      
      self::assertEquals('barbar', stream_get_contents($handle, -1, 0));
      self::assertEquals('bar', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testWriteOnlyTruncate() {
      $handle = fopen('string://foobar', 'w');
      
      self::assertEquals(0, ftell($handle));
      
      self::assertEquals('', stream_get_contents($handle, -1, 0));
      
      fwrite($handle, 'bar');
      
      self::assertEquals(3, ftell($handle));

      fclose($handle);
    }
    
    public function testReadWriteTruncate() {
      $handle = fopen('string://foobar', 'w+');
      self::assertEquals(0, ftell($handle));
      
      fwrite($handle, 'bar');
      
      self::assertEquals('bar', stream_get_contents($handle, -1, 0));
      self::assertEquals('bar', stream_get_contents($handle, 3, 0));
      self::assertEquals('', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testWriteOnlyAppend() {
      $handle = fopen('string://foobar', 'a');
      self::assertEquals(6, ftell($handle));
      
      fwrite($handle, 'bar');
      
      self::assertEquals(9, ftell($handle));

      fclose($handle);
    }
    
    public function testReadWriteAppend() {
      $handle = fopen('string://foobar', 'a+');
      self::assertEquals('foobar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));
      
      fwrite($handle, 'bar');
      
      self::assertEquals('foobarbar', stream_get_contents($handle, -1, 0));
      self::assertEquals('foo', stream_get_contents($handle, 3, 0));
      self::assertEquals('barbar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testWriteOnlyNoTruncate() {
      $handle = fopen('string://foobar', 'c');
      self::assertEquals(0, ftell($handle));
      
      fwrite($handle, 'bar');
      
      self::assertEquals(3, ftell($handle));
      
      fclose($handle);
    }
    
    public function testReadWriteNoTruncate2() {
      $handle = fopen('string://foobar', 'c+');
     
      fwrite($handle, 'bar');
      
      self::assertEquals('barbar', stream_get_contents($handle, -1, 0));
      self::assertEquals('bar', stream_get_contents($handle, 3, 0));
      self::assertEquals('bar', stream_get_contents($handle, -1, 3));

      fclose($handle);
    }
    
    public function testTruncateExtension() {
    
      if (!version_compare(PHP_VERSION, '5.4.0', '>=')) {
        $this->markTestSkipped('Truncate support introduced in PHP 5.4');
      }
        
{'fraction_non_alphanumeric': 0.17393069842988632, 'fraction_numerical': 0.015024363833243097, 'mean_word_length': 3.1464646464646466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2198431', 'n_tokens_mistral': 2342, 'n_tokens_neox': 2237, 'n_words': 395}