Skip to content

Commit

Permalink
Test PartialNode string representation with options
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 28, 2023
1 parent f9c9db7 commit 94830df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 2 additions & 6 deletions src/main/php/com/handlebarsjs/PartialNode.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ public function options() { return $this->options; }
protected function optionString() {
$r= '';
foreach ($this->options as $key => $option) {
if (false !== strpos($option, ' ')) {
$r.= ' '.$key.'= "'.$option.'"';
} else {
$r.= ' '.$key.'= '.$option;
}
$r.= ' '.$key.'= '.(string)$option;
}
return $r;
}
Expand All @@ -64,7 +60,7 @@ protected function optionString() {
* @return string
*/
public function toString() {
return nameof($this).'(> '.$this->template->toString().$this->optionString().'}}, indent= "'.$this->indent.'")';
return nameof($this).'({{> '.$this->template->toString().$this->optionString().'}}, indent= "'.$this->indent.'")';
}

/**
Expand Down
12 changes: 10 additions & 2 deletions src/test/php/com/handlebarsjs/unittest/PartialNodeTest.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace com\handlebarsjs\unittest;

use com\handlebarsjs\{Lookup, PartialNode};
use com\handlebarsjs\{Lookup, PartialNode, Quoted};
use test\{Assert, Test};

class PartialNodeTest {
Expand All @@ -15,11 +15,19 @@ public function template() {
#[Test]
public function string_representation() {
Assert::equals(
'com.handlebarsjs.PartialNode(> com.handlebarsjs.Lookup(test)}}, indent= "")',
'com.handlebarsjs.PartialNode({{> com.handlebarsjs.Lookup(test)}}, indent= "")',
(new PartialNode(new Lookup('test')))->toString()
);
}

#[Test]
public function string_representation_with_options() {
Assert::equals(
'com.handlebarsjs.PartialNode({{> com.handlebarsjs.Lookup(test) mount= "/"}}, indent= "")',
(new PartialNode(new Lookup('test'), ['mount' => new Quoted('/')]))->toString()
);
}

#[Test]
public function string_cast() {
Assert::equals('{{> test}}', (string)new PartialNode(new Lookup('test')));
Expand Down

0 comments on commit 94830df

Please sign in to comment.