generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PatternTest.php
109 lines (88 loc) 路 3.58 KB
/
PatternTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
declare(strict_types=1);
/**
* Copyright (c) 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
{
/**
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-3
*/
public function testJsonStringJsonPointerEqualsPattern(): void
{
$jsonStringReferenceToken = self::jsonStringReferenceToken();
$expected = "/^(?P<jsonStringJsonPointer>(\\/{$jsonStringReferenceToken})*)$/u";
self::assertSame($expected, Pattern::JSON_STRING_JSON_POINTER);
}
/**
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-3
*/
public function testJsonStringReferenceTokenEqualsPattern(): void
{
$jsonStringReferenceToken = self::jsonStringReferenceToken();
$expected = "/^{$jsonStringReferenceToken}$/u";
self::assertSame($expected, Pattern::JSON_STRING_REFERENCE_TOKEN);
}
/**
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-6
* @see https://datatracker.ietf.org/doc/html/rfc3986#appendix-A
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-2.1
*/
public function testUriFragmentIdentifierJsonPointerEqualsPattern(): void
{
$uriFragmentIdentifierReferenceToken = self::uriFragmentIdentifierReferenceToken();
$expected = "/^(?P<uriFragmentIdentifierJsonPointer>#(\\/{$uriFragmentIdentifierReferenceToken})*)$/u";
self::assertSame($expected, Pattern::URI_FRAGMENT_IDENTIFIER_JSON_POINTER);
}
/**
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-6
* @see https://datatracker.ietf.org/doc/html/rfc3986#appendix-A
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-2.3
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-2.1
*/
public function testUriFragmentIdentifierReferenceTokenEqualsPattern(): void
{
$uriFragmentIdentifierReferenceToken = self::uriFragmentIdentifierReferenceToken();
$expected = "/^{$uriFragmentIdentifierReferenceToken}$/u";
self::assertSame($expected, Pattern::URI_FRAGMENT_IDENTIFIER_REFERENCE_TOKEN);
}
/**
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-3
*/
private static function jsonStringReferenceToken(): string
{
$unescaped = '(?P<unescaped>[\x00-\x2E]|[\x30-\x7D]|[\x7F-\x{10FFFF}])';
$escaped = '(?P<escaped>~[01])';
return "(?P<referenceToken>({$unescaped}|{$escaped})*)";
}
/**
* @see https://datatracker.ietf.org/doc/html/rfc6901#section-6
* @see https://datatracker.ietf.org/doc/html/rfc3986#section-3.5
* @see https://datatracker.ietf.org/doc/html/rfc3986#appendix-A
*/
private static function uriFragmentIdentifierReferenceToken(): string
{
$alpha = '(?P<alpha>[a-zA-Z])';
$digit = '(?P<digit>\d)';
$unreserved = "(?P<unreserved>({$alpha}|{$digit}|-|\\.|_|~))";
$hexDig = '(?P<hexDig>[0-9a-fA-F])';
$pctEncoded = "(?P<pctEncoded>%{$hexDig}{2})";
$subDelims = '(?P<subDelims>(!|\$|&|\'|\(|\)|\*|\+|,|;|=))';
$pchar = "(?P<pchar>({$unreserved}|{$pctEncoded}|{$subDelims}|:|@))";
return "(?P<referenceToken>({$pchar}*))";
}
}