mirror of
https://github.com/ToxicCrack/PrintABrick.git
synced 2025-05-28 01:30:11 -07:00
Add LDModelParser tests
This commit is contained in:
parent
6c495d1f28
commit
b712678a2c
77
tests/Util/LDModelParser/LDModelParserTest.php
Normal file
77
tests/Util/LDModelParser/LDModelParserTest.php
Normal file
@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\AppBundle\Util\LDModelParser;
|
||||
|
||||
use AppBundle\Exception\ErrorParsingLineException;
|
||||
use AppBundle\Exception\ParseErrorException;
|
||||
use AppBundle\Util\LDModelParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Constraints\DateTime;
|
||||
|
||||
class LDModelParserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var LDModelParser
|
||||
*/
|
||||
private $parser;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->parser = new LDModelParser();
|
||||
}
|
||||
|
||||
public function testValid()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/valid.dat');
|
||||
|
||||
$array = [
|
||||
"id" => "1234",
|
||||
"name" => "Category Name",
|
||||
"category" => "Category!",
|
||||
"keywords" => [
|
||||
'keyword1', 'keyword 2', 'keyword3', 'keyword4'
|
||||
],
|
||||
"author" => "Author [nickname]",
|
||||
"modified" => new \DateTime('2017-04-01'),
|
||||
"type" => "Part",
|
||||
'subparts' => [
|
||||
'submodel' => [
|
||||
1 => 2,
|
||||
16 => 1
|
||||
]
|
||||
],
|
||||
"parent" => null,
|
||||
"license" => "Redistributable under CCAL version 2.0",
|
||||
];
|
||||
|
||||
$this->assertEquals($array, $this->parser->parse($resource));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException AppBundle\Exception\ErrorParsingLineException
|
||||
*/
|
||||
public function testInvalid()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/invalid.dat');
|
||||
|
||||
$this->parser->parse($resource);
|
||||
}
|
||||
|
||||
public function testStickers() {
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/stickers.txt');
|
||||
|
||||
foreach (preg_split('/^---DAT/m', $resource) as $dat) {
|
||||
$this->assertEquals('Sticker', $this->parser->parse($dat)['type']);
|
||||
}
|
||||
}
|
||||
|
||||
public function testAlias()
|
||||
{
|
||||
$resource = file_get_contents(__DIR__.'/fixtures/alias.txt');
|
||||
|
||||
foreach (preg_split('/^---DAT/m', $resource) as $dat) {
|
||||
$this->assertEquals('parent', $this->parser->parse($dat)['parent']);
|
||||
}
|
||||
}
|
||||
}
|
27
tests/Util/LDModelParser/fixtures/alias.txt
Normal file
27
tests/Util/LDModelParser/fixtures/alias.txt
Normal file
@ -0,0 +1,27 @@
|
||||
0 ~Moved to parent
|
||||
0 Name: 1111.dat
|
||||
0 Author: Author [nickname]
|
||||
0 !LDRAW_ORG Part UPDATE 2017-04
|
||||
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
|
||||
|
||||
0 BFC CERTIFY CCW
|
||||
|
||||
0 !HISTORY 2017-04-01 [nickname] Official Update 2017-04
|
||||
|
||||
0 // comment
|
||||
|
||||
1 16 0 -72 0 1 0 0 0 1 0 0 0 1 parent.DaT
|
||||
---DAT
|
||||
0 ~Moved to parent
|
||||
0 Name: 1111.dat
|
||||
0 Author: Author [nickname]
|
||||
0 !LDRAW_ORG Part UPDATE 2017-04
|
||||
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
|
||||
|
||||
0 BFC CERTIFY CCW
|
||||
|
||||
0 !HISTORY 2017-04-01 [nickname] Official Update 2017-04
|
||||
|
||||
0 // comment
|
||||
|
||||
1 16 0 -72 0 1 0 0 0 1 0 0 0 1 parent.DaT
|
32
tests/Util/LDModelParser/fixtures/invalid.dat
Normal file
32
tests/Util/LDModelParser/fixtures/invalid.dat
Normal file
@ -0,0 +1,32 @@
|
||||
0 Category Name
|
||||
0 Name: 1234.dat
|
||||
0 Author: Author [nickname]
|
||||
0 !LDRAW_ORG Part UPDATE 2017-04
|
||||
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
|
||||
|
||||
0 BFC CERTIFY CCW
|
||||
|
||||
0 !CATEGORY Category!
|
||||
|
||||
0 !KEYWORDS keyword1, keyword 2, keyword3
|
||||
0 !KEYWORDS keyword4,
|
||||
|
||||
0 !HISTORY 2017-04-01 [nickname] Official Update 2017-04
|
||||
|
||||
7
|
||||
|
||||
0 // comment
|
||||
|
||||
1 1 0 -72 0 1 0 0 0 1 0 0 0 1 submodel.dat
|
||||
1 1 0 -34 0 1 0 0 0 1 0 0 0 1 submodel.DAT
|
||||
|
||||
4 0 7.47 9.26 -10.343 7.59 8.99 -10.263 7.45 8.7 -10.356 6.708 8.556 -10.853
|
||||
4 0 7.19 9.36 -10.53 7.47 9.26 -10.343 6.708 8.556 -10.853 6.56 9.32 -10.951
|
||||
4 0 7.19 9.36 -10.53 6.56 9.32 -10.951 6.59 9.57 -10.931 7 9.988 -10.657
|
||||
4 0 7 9.988 -10.657 6.59 9.57 -10.931 6.25 9.91 -11.158 6.47 10.51 -11.011
|
||||
4 0 6.47 10.51 -11.011 6.25 9.91 -11.158 5.81 10.14 -11.453 5.74 10.85 -11.499
|
||||
4 0 5.74 10.85 -11.499 5.81 10.14 -11.453 5.34 10.31 -11.767 4.975 11.08 -12.0111
|
||||
4 0 4.975 11.08 -12.0111 5.34 10.31 -11.767 5.2 9 -11.86 4.975 8.24 -12.0111
|
||||
|
||||
0 BFC INVERTNEXT
|
||||
1 16 0 -34 0 1 0 0 0 1 0 0 0 1 submodel.Dat
|
5
tests/Util/LDModelParser/fixtures/stickers.txt
Normal file
5
tests/Util/LDModelParser/fixtures/stickers.txt
Normal file
@ -0,0 +1,5 @@
|
||||
0 Sticker Model Name
|
||||
0 Name: 0043d03.dat
|
||||
---DAT
|
||||
0 Category Model
|
||||
0 Name: 0043d03.dat
|
31
tests/Util/LDModelParser/fixtures/valid.dat
Normal file
31
tests/Util/LDModelParser/fixtures/valid.dat
Normal file
@ -0,0 +1,31 @@
|
||||
0 Category Name
|
||||
0 Name: 1234.dat
|
||||
0 Author: Author [nickname]
|
||||
0 !LDRAW_ORG Part UPDATE 2017-04
|
||||
0 !LICENSE Redistributable under CCAL version 2.0 : see CAreadme.txt
|
||||
|
||||
0 BFC CERTIFY CCW
|
||||
|
||||
0 !CATEGORY Category!
|
||||
|
||||
0 !KEYWORDS keyword1, keyword 2, keyword3
|
||||
0 !KEYWORDS keyword4,
|
||||
|
||||
0 !HISTORY 2017-04-01 [nickname] Official Update 2017-04
|
||||
|
||||
|
||||
0 // comment
|
||||
|
||||
1 1 0 -72 0 1 0 0 0 1 0 0 0 1 submodel.dat
|
||||
1 1 0 -34 0 1 0 0 0 1 0 0 0 1 submodel.DAT
|
||||
|
||||
4 0 7.47 9.26 -10.343 7.59 8.99 -10.263 7.45 8.7 -10.356 6.708 8.556 -10.853
|
||||
4 0 7.19 9.36 -10.53 7.47 9.26 -10.343 6.708 8.556 -10.853 6.56 9.32 -10.951
|
||||
4 0 7.19 9.36 -10.53 6.56 9.32 -10.951 6.59 9.57 -10.931 7 9.988 -10.657
|
||||
4 0 7 9.988 -10.657 6.59 9.57 -10.931 6.25 9.91 -11.158 6.47 10.51 -11.011
|
||||
4 0 6.47 10.51 -11.011 6.25 9.91 -11.158 5.81 10.14 -11.453 5.74 10.85 -11.499
|
||||
4 0 5.74 10.85 -11.499 5.81 10.14 -11.453 5.34 10.31 -11.767 4.975 11.08 -12.0111
|
||||
4 0 4.975 11.08 -12.0111 5.34 10.31 -11.767 5.2 9 -11.86 4.975 8.24 -12.0111
|
||||
|
||||
0 BFC INVERTNEXT
|
||||
1 16 0 -34 0 1 0 0 0 1 0 0 0 1 submodel.Dat
|
Loading…
x
Reference in New Issue
Block a user