Skip to content

Commit f0cdd88

Browse files
committed
Add tests for Unicode boundary characters and 64-bit integer handling
1 parent 3ac74fd commit f0cdd88

2 files changed

Lines changed: 78 additions & 0 deletions

File tree

tests/AstParserTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ public function testNegativeIntegerNode(): void
8080
$this->assertSame('-100', $node->raw);
8181
}
8282

83+
public function testLargeIntegerNode(): void
84+
{
85+
$node = Maml::parseAst('9007199254740992')->value;
86+
$this->assertInstanceOf(IntegerNode::class, $node);
87+
$this->assertSame(9007199254740992, $node->value);
88+
$this->assertSame('9007199254740992', $node->raw);
89+
}
90+
91+
public function testI64MaxBoundary(): void
92+
{
93+
$max = (string) PHP_INT_MAX; // 9223372036854775807
94+
$node = Maml::parseAst($max)->value;
95+
$this->assertInstanceOf(IntegerNode::class, $node);
96+
$this->assertSame(PHP_INT_MAX, $node->value);
97+
$this->assertSame($max, $node->raw);
98+
}
99+
100+
public function testI64MinBoundary(): void
101+
{
102+
$min = (string) PHP_INT_MIN; // -9223372036854775808
103+
$node = Maml::parseAst($min)->value;
104+
$this->assertInstanceOf(IntegerNode::class, $node);
105+
$this->assertSame(PHP_INT_MIN, $node->value);
106+
$this->assertSame($min, $node->raw);
107+
}
108+
83109
public function testFloatNode(): void
84110
{
85111
$node = Maml::parseAst('3.14')->value;

tests/AstPrinterTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,58 @@ public function testPrintStringWithControlChar(): void
8181
$this->assertPrintRoundTrip('"\\u{1}"');
8282
}
8383

84+
public function testPrintStringWithAllControlChars(): void
85+
{
86+
for ($code = 0x00; $code < 0x20; $code++) {
87+
if ($code === 0x09) {
88+
continue;
89+
} // tab uses \t
90+
if ($code === 0x0A) {
91+
continue;
92+
} // newline uses \n
93+
if ($code === 0x0D) {
94+
continue;
95+
} // CR uses \r
96+
$escaped = '"\\u{' . strtoupper(dechex($code)) . '}"';
97+
$this->assertPrintRoundTrip($escaped);
98+
}
99+
// DEL (0x7F)
100+
$this->assertPrintRoundTrip('"\\u{7F}"');
101+
}
102+
103+
public function testPrintUnicodeBoundaryCharsPassThrough(): void
104+
{
105+
// U+D7FF (last before surrogates)
106+
$d7ff = '"' . mb_chr(0xD7FF, 'UTF-8') . '"';
107+
$this->assertPrintRoundTrip($d7ff);
108+
// U+E000 (first after surrogates)
109+
$e000 = '"' . mb_chr(0xE000, 'UTF-8') . '"';
110+
$this->assertPrintRoundTrip($e000);
111+
// U+10000 (first supplementary plane)
112+
$sup = '"' . mb_chr(0x10000, 'UTF-8') . '"';
113+
$this->assertPrintRoundTrip($sup);
114+
// U+10FFFF (max unicode)
115+
$max = '"' . mb_chr(0x10FFFF, 'UTF-8') . '"';
116+
$this->assertPrintRoundTrip($max);
117+
}
118+
119+
// ---- 64-bit integer boundary round-trips ----
120+
121+
public function testPrintLargeInteger(): void
122+
{
123+
$this->assertPrintRoundTrip('9007199254740992');
124+
}
125+
126+
public function testPrintI64Max(): void
127+
{
128+
$this->assertPrintRoundTrip((string) PHP_INT_MAX);
129+
}
130+
131+
public function testPrintI64Min(): void
132+
{
133+
$this->assertPrintRoundTrip((string) PHP_INT_MIN);
134+
}
135+
84136
public function testPrintTrue(): void
85137
{
86138
$this->assertPrintRoundTrip('true');

0 commit comments

Comments
 (0)