generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d0b4c2
commit 32935d7
Showing
4 changed files
with
86 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2020-2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json-pointer | ||
*/ | ||
|
||
namespace Ergebnis\Json\Pointer; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Pattern | ||
{ | ||
/** | ||
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-3 | ||
*/ | ||
public const JSON_POINTER_JSON_STRING = '/^(?P<jsonPointer>(\/(?P<referenceToken>((?P<unescaped>[\x00-\x2E]|[\x30-\x7D]|[\x7F-\x{10FFFF}])|(?P<escaped>~[01]))*))*)$/u'; | ||
|
||
/** | ||
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-3 | ||
*/ | ||
public const REFERENCE_TOKEN = '/^(?P<referenceToken>((?P<unescaped>[\x00-\x2E]|[\x30-\x7D]|[\x7F-\x{10FFFF}])|(?P<escaped>~[01]))*)$/u'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 2020-2022 Andreas Möller | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE.md file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ergebnis/json-pointer | ||
*/ | ||
|
||
namespace Ergebnis\Json\Pointer\Test\Unit; | ||
|
||
use Ergebnis\Json\Pointer\Pattern; | ||
use PHPUnit\Framework; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @covers \Ergebnis\Json\Pointer\Pattern | ||
*/ | ||
final class PatternTest extends Framework\TestCase | ||
{ | ||
public function testJsonPointerJsonStringEqualsPattern(): void | ||
{ | ||
$referenceToken = self::referenceToken(); | ||
|
||
$expected = "/^(?P<jsonPointer>(\\/{$referenceToken})*)$/u"; | ||
|
||
self::assertSame($expected, Pattern::JSON_POINTER_JSON_STRING); | ||
} | ||
|
||
public function testReferenceTokenEqualsPattern(): void | ||
{ | ||
$referenceToken = self::referenceToken(); | ||
|
||
$expected = "/^{$referenceToken}$/u"; | ||
|
||
self::assertSame($expected, Pattern::REFERENCE_TOKEN); | ||
} | ||
|
||
/** | ||
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-3 | ||
*/ | ||
private static function referenceToken(): string | ||
{ | ||
$unescaped = '(?P<unescaped>[\x00-\x2E]|[\x30-\x7D]|[\x7F-\x{10FFFF}])'; | ||
$escaped = '(?P<escaped>~[01])'; | ||
|
||
return "(?P<referenceToken>({$unescaped}|{$escaped})*)"; | ||
} | ||
} |