Skip to content

Commit

Permalink
Add tests for inverse sections
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Oct 22, 2023
1 parent d31fcf5 commit 26a3d6d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 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,11 +4,43 @@

class InverseOfTest extends HelperTest {

#[Test, Values([[[], 'no people'], [['A', 'B'], 'AB']])]
public function inverse_section($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#people}}{{this}}{{/people}}{{^people}}no people{{/people}}',
['people' => $input]
));
}

#[Test, Values([[[], 'no people'], [['A', 'B'], 'AB']])]
public function inverse_section_with_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#people}}{{this}}{{else}}no people{{/people}}',
['people' => $input]
));
}

#[Test, Values([[[], 'no people'], [['A', 'B'], 'AB']])]
public function inverse_section_with_short_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{#people}}{{this}}{{^}}no people{{/people}}',
['people' => $input]
));
}

#[Test, Values([[[], 'no people'], [['A', 'B'], 'some people']])]
public function inverse_if_with_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{^if people}}no people{{else}}some people{{/if}}',
['people' => $input]
));
}

#[Test, Values([[[], 'no people'], [['A', 'B'], 'some people']])]
public function inverse_if_with_short_else($input, $outcome) {
Assert::equals($outcome, $this->evaluate(
'{{^if people}}no people{{^}}some people{{/if}}',
['people' => $input]
));
}
}

0 comments on commit 26a3d6d

Please sign in to comment.