finished default parser
This commit is contained in:
112
tests/unit/AbcParser/Domain/Core/SettingTest.php
Normal file
112
tests/unit/AbcParser/Domain/Core/SettingTest.php
Normal file
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/26/17
|
||||
* Time: 9:21 PM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\AbcParser\Domain\Core;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Setting;
|
||||
use XaiCorp\AbcParser\Domain\Core\Transcriber;
|
||||
|
||||
class SettingTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testCreate()
|
||||
{
|
||||
$params = [];
|
||||
|
||||
$setting = new Setting();
|
||||
|
||||
$this->assertInstanceOf(Setting::class, $setting);
|
||||
}
|
||||
|
||||
public function testAddTranscriber()
|
||||
{
|
||||
$name = new StringAtom('me');
|
||||
$email = new EmailAtom('me@example.com');
|
||||
$transcriber = new Transcriber($name, $email);
|
||||
$setting = new Setting();
|
||||
$setting->addTranscriber($transcriber);
|
||||
|
||||
$result = $setting->getTranscribers();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($transcriber, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddNote()
|
||||
{
|
||||
$note = 'a note';
|
||||
$setting = new Setting();
|
||||
$setting->addNote($note);
|
||||
|
||||
$result = $setting->getNotes();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($note, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddRecording()
|
||||
{
|
||||
$recording = 'cd recording number';
|
||||
$setting = new Setting();
|
||||
$setting->addRecording($recording);
|
||||
|
||||
$result = $setting->getDiscography();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($recording, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddSource()
|
||||
{
|
||||
$source = 'thesession.org';
|
||||
$setting = new Setting();
|
||||
$setting->addSource($source);
|
||||
|
||||
$result = $setting->getSources();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($source, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddWords()
|
||||
{
|
||||
$words = 'sing along with me';
|
||||
$setting = new Setting();
|
||||
$setting->addWords($words);
|
||||
|
||||
$result = $setting->getWords();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($words, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddBook()
|
||||
{
|
||||
$book = 'sing along with me';
|
||||
$setting = new Setting();
|
||||
$setting->addBook($book);
|
||||
|
||||
$result = $setting->getBooks();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($book, $result[0]);
|
||||
}
|
||||
|
||||
public function testAddFilename()
|
||||
{
|
||||
$filename = 'test.abc';
|
||||
$setting = new Setting();
|
||||
$setting->addFilename($filename);
|
||||
|
||||
$result = $setting->getFilenames();
|
||||
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($filename, $result[0]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/27/17
|
||||
* Time: 6:14 AM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
|
||||
class ContextTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private function getAbc($filename = '/abc/valid_abc_1.abc')
|
||||
{
|
||||
return file_get_contents(codecept_data_dir($filename));
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$this->assertInstanceOf(Context::class, $context);
|
||||
}
|
||||
|
||||
public function testLoopingThroughLines()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$this->assertGreaterThan(1, count($context));
|
||||
foreach ($context as $key => $line) {
|
||||
$this->assertInternalType('string', $line);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetStateDefaultsToNoData()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $context->getState();
|
||||
|
||||
$this->assertEquals(Context::MODE_NO_DATA, $result);
|
||||
}
|
||||
|
||||
public function testSetStateInFileHeader()
|
||||
{
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $context->setStateInFileHeader()->getState();
|
||||
|
||||
$this->assertEquals(Context::MODE_FILE_HEADER, $result);
|
||||
}
|
||||
|
||||
public function testGetVersionReturnsDefault()
|
||||
{
|
||||
$expected = Context::ABC_VERSION_DEFAULT;
|
||||
$abc = new StringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $context->getVersion();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: richard
|
||||
* Date: 11/30/17
|
||||
* Time: 8:58 AM
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\AbcParser\Domain\Modules\Interpreter;
|
||||
|
||||
use Enzyme\Axiom\Atoms\StringAtom;
|
||||
use Enzyme\Collection\CollectionException;
|
||||
use XaiCorp\AbcParser\Domain\Atoms\EmailAtom;
|
||||
use XaiCorp\AbcParser\Domain\Core\Author;
|
||||
use XaiCorp\AbcParser\Domain\Core\Composer;
|
||||
use XaiCorp\AbcParser\Domain\Core\Tune;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Builder;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Context;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\DefaultInterpreter;
|
||||
use XaiCorp\AbcParser\Domain\Modules\Interpreter\Interpreter;
|
||||
|
||||
class DefaultInterpreterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Interpreter
|
||||
*/
|
||||
protected $interpreter;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$builder = new Builder();
|
||||
$this->interpreter = new DefaultInterpreter($builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return bool|string
|
||||
*/
|
||||
private function getAbc($filename = '/abc/valid_abc_1.abc')
|
||||
{
|
||||
return file_get_contents(codecept_data_dir($filename));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $string
|
||||
* @return StringAtom
|
||||
*/
|
||||
private function createStringAtom($string = '')
|
||||
{
|
||||
try {
|
||||
return new StringAtom($string);
|
||||
} catch (\Exception $e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
private function createAuthor($name, $email = '')
|
||||
{
|
||||
return new Author(
|
||||
$this->createStringAtom($name),
|
||||
new EmailAtom($email)
|
||||
);
|
||||
}
|
||||
|
||||
private function createComposer($name, $email = '')
|
||||
{
|
||||
return new Composer(
|
||||
$this->createStringAtom($name),
|
||||
new EmailAtom($email)
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$builder = new Builder();
|
||||
$interpreter = new DefaultInterpreter($builder);
|
||||
|
||||
$this->assertInstanceOf(Interpreter::class, $interpreter);
|
||||
}
|
||||
|
||||
public function testExecuteReturnsInterpreter()
|
||||
{
|
||||
$abc = $this->createStringAtom($this->getAbc());
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $this->interpreter->execute($context);
|
||||
|
||||
$this->assertInstanceOf(Interpreter::class, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesTitles()
|
||||
{
|
||||
$expectedTitle = ['Abbotts Bromley Horn Dance'];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getTitles();
|
||||
|
||||
$this->assertEquals($expectedTitle, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesAuthor()
|
||||
{
|
||||
$expected = 'trad';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getAuthors()[0]->get('name');
|
||||
|
||||
$this->assertEquals($expected, $result->getValue());
|
||||
}
|
||||
|
||||
public function testExecuteParsesComposer()
|
||||
{
|
||||
$expected = [$this->createComposer('trad.')];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getComposers()[0]->get('name');
|
||||
|
||||
$this->assertEquals($expected[0]->get('name'), $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesTranscriber()
|
||||
{
|
||||
$expected = [$this->createComposer('Andy Hornby')];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getTranscribers()[0]->get('name');
|
||||
|
||||
$this->assertEquals($expected[0]->get('name'), $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesDiscography()
|
||||
{
|
||||
$expected = 'None';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getDiscography()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesGroups()
|
||||
{
|
||||
$expected = 'lute';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getGroups()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesKey()
|
||||
{
|
||||
$expected = 'G';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getKey();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesMusic()
|
||||
{
|
||||
$expected = implode('\n', [
|
||||
'e|B2e G2e|B2e E2G|FGA GAB|1AGF G2:|2AGF E2|',
|
||||
'|e|c2e cde|A2c ABc|FGA GFE|_E=EF B,2g|',
|
||||
'e2g efg|c2e cde|dcB AGF|E3E2',
|
||||
'|:A|BcB e3|BcB f3|BcB AGF|1G2F G2:|2E3-E2|]',
|
||||
]);
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getMusic();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesMeter()
|
||||
{
|
||||
$expected = '6/8';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getMeter();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesParts()
|
||||
{
|
||||
$expected = 'ABC';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getPart();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesSources()
|
||||
{
|
||||
$expected = 'http://www.leeds.ac.uk/music/Info/RRTuneBk/gettune/00000dab.html';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getSources()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesHistory()
|
||||
{
|
||||
$expected = [
|
||||
'Thousand year old tradition',
|
||||
'The Horns live in the church and are removed for the dance once a year',
|
||||
];
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getHistory();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesRhythms()
|
||||
{
|
||||
$expected = 'Jig';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getRhythms()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesFilename()
|
||||
{
|
||||
$expected = 'none.abc';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getFilenames()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesBook()
|
||||
{
|
||||
$expected = 'Traditional English tunes';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getBooks()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesWords()
|
||||
{
|
||||
$expected = 'None';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getWords()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesTempo()
|
||||
{
|
||||
$expected = '1/8=80';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getTempo();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesNoteLength()
|
||||
{
|
||||
$expected = '1/8';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getNoteLength();
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesNotes()
|
||||
{
|
||||
$expected = 'Traditional English';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$setting = $tune->getSettings()[0];
|
||||
$result = $setting->getNotes()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testExecuteParsesOrigin()
|
||||
{
|
||||
$expected = 'England';
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/valid_abc_2.abc'));
|
||||
$context = new Context($abc);
|
||||
|
||||
$tune = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes()
|
||||
->first();
|
||||
$result = $tune->getOrigins()[0];
|
||||
|
||||
$this->assertEquals($expected, $result);
|
||||
}
|
||||
|
||||
public function testMultipleTunesInAFile()
|
||||
{
|
||||
$abc = $this->createStringAtom($this->getAbc('/abc/jigs.abc'));
|
||||
|
||||
$context = new Context($abc);
|
||||
|
||||
$result = $this->interpreter
|
||||
->execute($context)
|
||||
->getTunes();
|
||||
|
||||
$this->assertCount(52, $result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user