1515namespace PhpAidc \LabelPrinter \Tests \Unit ;
1616
1717use PhpAidc \LabelPrinter \Compiler ;
18+ use PhpAidc \LabelPrinter \Label \Batch ;
1819use PhpAidc \LabelPrinter \Label \Label ;
1920use PhpAidc \LabelPrinter \Label \Element ;
2021use PhpAidc \LabelPrinter \Contract \Command ;
2425
2526class CompilerTest extends TestCase
2627{
27- public function testCompile (): void
28+ public function testCompileLabel (): void
2829 {
2930 $ compiler = Compiler::create (new LanguageA ());
3031
3132 $ label = Label::create ()->add (Element::raw ('' ));
33+ $ this ->assertEquals ('ASIZE|ACMD|APRINT1| ' , $ compiler ->compile ($ label ));
3234
33- $ this ->assertEquals ('ASIZE|ACMD|APRINT| ' , $ compiler ->compile ($ label ));
35+ $ label ->copies (2 );
36+ $ this ->assertEquals ('ASIZE|ACMD|APRINT2| ' , $ compiler ->compile ($ label ));
3437 }
3538
36- public function testConditionalCompilation (): void
39+ public function testCompileBatch (): void
40+ {
41+ $ compiler = Compiler::create (new LanguageA ());
42+
43+ $ label = Label::create ()->add (Element::raw ('' ));
44+ $ batch = new Batch ();
45+
46+ $ batch ->add (clone $ label );
47+ $ batch ->add ((clone $ label )->copies (2 ));
48+
49+ $ this ->assertEquals ('ASIZE|ACMD|APRINT1|ASIZE|ACMD|APRINT2| ' , $ compiler ->compile ($ batch ));
50+ }
51+
52+ public function testLanguageCondition (): void
3753 {
3854 $ label = Label::create ()
3955 ->for (LanguageA::class, static function (Label $ label ) {
@@ -43,8 +59,28 @@ public function testConditionalCompilation(): void
4359 $ label ->add (Element::raw ('' ));
4460 });
4561
46- $ this ->assertEquals ('ASIZE|ACMD|APRINT| ' , Compiler::create (new LanguageA ())->compile ($ label ));
47- $ this ->assertEquals ('BSIZE|BCMD|BPRINT| ' , Compiler::create (new LanguageB ())->compile ($ label ));
62+ $ this ->assertEquals ('ASIZE|ACMD|APRINT1| ' , Compiler::create (new LanguageA ())->compile ($ label ));
63+ $ this ->assertEquals ('BSIZE|BCMD|BPRINT1| ' , Compiler::create (new LanguageB ())->compile ($ label ));
64+ }
65+
66+ public function testBooleanConditionTruthy (): void
67+ {
68+ $ label = Label::create ()
69+ ->when (1 > 0 , static function (Label $ label ) {
70+ $ label ->add (Element::raw ('' ));
71+ });
72+
73+ $ this ->assertEquals ('ASIZE|ACMD|APRINT1| ' , Compiler::create (new LanguageA ())->compile ($ label ));
74+ }
75+
76+ public function testBooleanConditionFalsy (): void
77+ {
78+ $ label = Label::create ()
79+ ->when (0 > 1 , static function (Label $ label ) {
80+ $ label ->add (Element::raw ('' ));
81+ });
82+
83+ $ this ->assertEquals ('ASIZE|APRINT1| ' , Compiler::create (new LanguageA ())->compile ($ label ));
4884 }
4985}
5086
@@ -67,7 +103,7 @@ public function compileCommand(Command $command): iterable
67103
68104 public function compilePrint (int $ copies ): iterable
69105 {
70- yield ' APRINT| ' ;
106+ yield " APRINT { $ copies } | " ;
71107 }
72108}
73109
@@ -90,6 +126,6 @@ public function compileCommand(Command $command): iterable
90126
91127 public function compilePrint (int $ copies ): iterable
92128 {
93- yield ' BPRINT| ' ;
129+ yield " BPRINT { $ copies } | " ;
94130 }
95131}
0 commit comments