Skip to content

Commit

Permalink
Ensure the tokenizer initialises its state
Browse files Browse the repository at this point in the history
  • Loading branch information
duncan3dc committed Oct 18, 2024
1 parent 5524810 commit 647cc5c
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ Changelog

--------

## 3.1.1 - 2024-10-18

### Fixed

* [Tokenizer] Correct a state bug that made it impossible to tokenize/parse multiple messages ([#14](https://github.com/estratocloud/edifact/issues/14)).

--------

## 3.1.0 - 2024-01-19

### Added
Expand Down
2 changes: 2 additions & 0 deletions src/Tokenizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ final class Tokenizer implements TokenizerInterface
public function getTokens(string $message, ControlCharactersInterface $characters): array
{
$this->message = $message;
$this->position = 0;
$this->characters = $characters;
$this->char = "";
$this->string = "";
$this->isEscaped = false;

$this->readNextChar();

Expand Down
24 changes: 24 additions & 0 deletions tests/TokenizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,30 @@ public function testBasic(): void
}


/**
* Regression test for https://github.com/estratocloud/edifact/issues/14
*/
public function testMultiple(): void
{
$this->assertTokens("RFF+PD:50515", [
new Token(Token::CONTENT, "RFF"),
new Token(Token::DATA_SEPARATOR, "+"),
new Token(Token::CONTENT, "PD"),
new Token(Token::COMPONENT_SEPARATOR, ":"),
new Token(Token::CONTENT, "50515"),
]);

# Ensure we can use the same tokenizer instance for multiple messages
$this->assertTokens("RFF+PD:50515", [
new Token(Token::CONTENT, "RFF"),
new Token(Token::DATA_SEPARATOR, "+"),
new Token(Token::CONTENT, "PD"),
new Token(Token::COMPONENT_SEPARATOR, ":"),
new Token(Token::CONTENT, "50515"),
]);
}


public function testEscape(): void
{
$this->assertTokens("RFF+PD?:5", [
Expand Down

0 comments on commit 647cc5c

Please sign in to comment.