<?php
namespace nur\mapper\base;

use nur\b\io\StringReader;
use nur\mapper\line\LineReader;
use nur\t\TestCase;

class ProducerTest extends TestCase {
  function testProducer() {
    $p = new LineReader(new StringReader("first\nsecond\nthird\nfourth\nfifth"));
    $i = 0;
    $lines = [];
    foreach ($p as $line) {
      if ($i++ < 2) {
        $lines[] = $line;
      } else {
        break;
      }
    }
    $p->close();
    self::assertSame(["first", "second"], $lines);

    $p = new LineReader(new StringReader("first\nsecond\n"));
    $lines = [];
    foreach ($p as $line) {
      $lines[] = $line;
    }
    $p->close();
    self::assertSame(["first", "second"], $lines);
  }
}