Skip to content

Commit

Permalink
Add tests for inverse variables
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 22, 2023
1 parent ed1fbf7 commit f24bb1c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/test/php/com/handlebarsjs/unittest/InverseOfTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,30 @@

class InverseOfTest extends HelperTest {

#[Test, Values([[null, 'Guest'], ['Test', 'User Test']])]
public function inverse_variable($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#person}}User {{.}}{{/person}}{{^person}}Guest{{/person}}',
['person' => $input]
));
}

#[Test, Values([[null, 'Guest'], ['Test', 'User Test']])]
public function inverse_variable_with_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#person}}User {{.}}{{else}}Guest{{/person}}',
['person' => $input]
));
}

#[Test, Values([[null, 'Guest'], ['Test', 'User Test']])]
public function inverse_variable_with_short_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#person}}User {{.}}{{^}}Guest{{/person}}',
['person' => $input]
));
}

#[Test, Values([[null, 'Guest'], [['name' => 'Test'], 'User Test']])]
public function inverse_section($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
Expand All @@ -12,6 +36,22 @@ public function inverse_section($input, $outcome) {
));
}

#[Test, Values([[null, 'Guest'], [['name' => 'Test'], 'User Test']])]
public function inverse_section_with_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#person}}User {{name}}{{else}}Guest{{/person}}',
['person' => $input]
));
}

#[Test, Values([[null, 'Guest'], [['name' => 'Test'], 'User Test']])]
public function inverse_section_with_short_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#person}}User {{name}}{{^}}Guest{{/person}}',
['person' => $input]
));
}

#[Test, Values([[[], 'no people'], [['A', 'B'], 'AB']])]
public function inverse_iterator($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
Expand Down

0 comments on commit f24bb1c

Please sign in to comment.