Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Commit

Permalink
add FIXMEs required by HHVM 4.20+
Browse files Browse the repository at this point in the history
  • Loading branch information
jjergus committed Aug 27, 2019
1 parent f629af6 commit 8178618
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
9 changes: 9 additions & 0 deletions tests/AttributesCoercionModeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function testIntishStringAsInt(): void {
expect(() ==> {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::THROW_EXCEPTION);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes myint="1" />;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -69,6 +70,7 @@ public function testFloatAsInt(): void {
expect(() ==> {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::THROW_EXCEPTION);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes myint={1.23} />;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -77,6 +79,7 @@ public function testIntAsFloat(): void {
expect(() ==> {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::THROW_EXCEPTION);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes myfloat={2} />;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -85,6 +88,7 @@ public function testIntAsString(): void {
expect(() ==> {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::THROW_EXCEPTION);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes mystring={2} />;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -93,6 +97,7 @@ public function testIntAsBool(): void {
expect(() ==> {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::THROW_EXCEPTION);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes mybool={1} />;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -101,6 +106,7 @@ public function testStringAsBool(): void {
expect(() ==> {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::THROW_EXCEPTION);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes mybool="true" />;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -109,6 +115,7 @@ public function testSilentCoercion(): void {
error_reporting(E_ALL);
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::SILENT);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes mystring={2} />;
expect($x->:mystring)->toBeSame('2');
}
Expand All @@ -120,6 +127,7 @@ public function testLoggingDeprecationCoercion(): void {
XHPAttributeCoercion::SetMode(XHPAttributeCoercionMode::LOG_DEPRECATION);
try {
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes mystring={2} />;
} catch (Exception $e) {
$exception = $e;
Expand All @@ -128,6 +136,7 @@ public function testLoggingDeprecationCoercion(): void {

error_reporting(E_ALL & ~E_USER_DEPRECATED);
/* HH_IGNORE_ERROR[4110] testing behavior for incorrect types */
/* HH_IGNORE_ERROR[4343] testing behavior for incorrect types */
$x = <test:attribute-coercion-modes mystring={2} />;
expect($x->:mystring)->toBeSame('2');
}
Expand Down
43 changes: 28 additions & 15 deletions tests/AttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function testShapeWithExtraKey(): void {
$x =
<test:attribute-types
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
/* HH_IGNORE_ERROR[4166] */
myshape={shape('foo' => 'herp', 'bar' => 'derp', 'baz' => 'extra')}
/>;
Expand Down Expand Up @@ -130,7 +131,7 @@ public function testValidArrayKeys(): void {

public function testInvalidArrayKeys(): void {
expect(() ==> {
$x = <test:attribute-types myarraykey={/* HH_FIXME[4110] */ 1.23} />;
$x = <test:attribute-types myarraykey={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ 1.23} />;
$x->toString();
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -144,7 +145,7 @@ public function testValidNum(): void {

public function testInvalidNum(): void {
expect(() ==> {
$x = <test:attribute-types mynum=/* HH_FIXME[4110] */ "123" />;
$x = <test:attribute-types mynum=/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ "123" />;
$x->toString();
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -155,12 +156,14 @@ public function testNoAttributes(): void {

public function testStringableObjectAsString(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types mystring={new StringableTestClass()} />;
expect($x->:mystring)->toBeSame('StringableTestClass');
}

public function testIntegerAsString(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types mystring={123} />;
expect($x->:mystring)->toBeSame('123');
}
Expand All @@ -169,31 +172,34 @@ public function testUnstringableObjectAsString(): void {
expect(() ==> {
$x =
<test:attribute-types
mystring={/* HH_FIXME[4110] */ new EmptyTestClass()}
mystring={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ new EmptyTestClass()}
/>;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testArrayAsString(): void {
expect(() ==> {
$x = <test:attribute-types mystring={/* HH_FIXME[4110] */ []} />;
$x = <test:attribute-types mystring={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ []} />;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testIntishStringAsInt(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types myint={'123'} />;
expect($x->:myint)->toBeSame(123);
}

public function testFloatAsInt(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types myint={1.23} />;
expect($x->:myint)->toBeSame(1);
}

public function testFloatishStringAsInt(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types myint="1.23" />;
expect($x->:myint)->toBeSame(1);
}
Expand All @@ -202,52 +208,55 @@ public function testObjectAsInt(): void {
expect(() ==> {
$x =
<test:attribute-types
myint={/* HH_FIXME[4110] */ new EmptyTestClass()}
myint={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ new EmptyTestClass()}
/>;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testArrayAsInt(): void {
expect(() ==> {
$x = <test:attribute-types myint={/* HH_FIXME[4110] */ []} />;
$x = <test:attribute-types myint={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ []} />;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testNumericPrefixStringAsInt(): void {
expect(() ==> {
$x = <test:attribute-types myint=/* HH_FIXME[4110] */ "123derp" />;
$x = <test:attribute-types myint=/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ "123derp" />;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testTrueStringAsBool(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types mybool="true" />;
expect($x->:mybool)->toBeSame(true);
}

public function testFalseStringAsBool(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types mybool="false" />;
expect($x->:mybool)->toBeSame(false);
}

public function testMixedCaseFalseStringAsBool(): void {
expect(() ==> {
$x = <test:attribute-types mybool=/* HH_FIXME[4110] */ "False" />;
$x = <test:attribute-types mybool=/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ "False" />;
})->toThrow(XHPInvalidAttributeException::class);
// 'False' is actually truthy
}

public function testNoStringAsBool(): void {
expect(() ==> {
$x = <test:attribute-types mybool=/* HH_FIXME[4110] */ "No" />;
$x = <test:attribute-types mybool=/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ "No" />;
})->toThrow(XHPInvalidAttributeException::class);
// 'No' is actually truthy
}

public function testAttrNameAsBool(): void {
// idiomatic - eg checked="checked"
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types mybool="mybool" />;
expect($x->:mybool)->toBeSame(true);
}
Expand All @@ -260,36 +269,39 @@ public function testInvalidEnumValue(): void {

public function testIntAsFloat(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types myfloat={123} />;
expect($x->:myfloat)->toBeSame(123.0);
}

public function testNumericStringsAsFloats(): void {
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types myfloat="123" />;
expect($x->:myfloat)->toBeSame(123.0);
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
$x = <test:attribute-types myfloat="1.23" />;
expect($x->:myfloat)->toBeSame(1.23);
}

public function testNonNumericStringAsFloat(): void {
expect(() ==> {
$x = <test:attribute-types myfloat=/* HH_FIXME[4110] */ "herpderp" />;
$x = <test:attribute-types myfloat=/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ "herpderp" />;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testNumericPrefixStringAsFloat(): void {
expect(() ==> {
$x = <test:attribute-types myfloat=/* HH_FIXME[4110] */ "123derp" />;
$x = <test:attribute-types myfloat=/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ "123derp" />;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testNotAContainerAsArray(): void {
expect(() ==> {
$x =
<test:attribute-types
myarray={/* HH_FIXME[4110] */ new EmptyTestClass()}
myarray={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ new EmptyTestClass()}
/>;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -298,7 +310,7 @@ public function testHackContainerAsArray(): void {
expect(() ==> {
$x =
<test:attribute-types
myarray={/* HH_FIXME[4110] */ Vector {1, 2, 3}}
myarray={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ Vector {1, 2, 3}}
/>;
})->toThrow(XHPInvalidAttributeException::class);
}
Expand All @@ -307,14 +319,14 @@ public function testIncompatibleObjectAsObject(): void {
expect(() ==> {
$x =
<test:attribute-types
myobject={/* HH_FIXME[4110] */ new EmptyTestClass()}
myobject={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ new EmptyTestClass()}
/>;
})->toThrow(XHPInvalidAttributeException::class);
}

public function testPassingArrayAsVector(): void {
expect(() ==> {
$x = <test:attribute-types myvector={/* HH_FIXME[4110] */ [1, 2, 3]} />;
$x = <test:attribute-types myvector={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ [1, 2, 3]} />;
})->toThrow(XHPInvalidAttributeException::class);
}

Expand Down Expand Up @@ -380,6 +392,7 @@ public function testRenderCallableAttribute(): void {
$x =
<test:callable-attribute
/* HH_IGNORE_ERROR[4110] */
/* HH_IGNORE_ERROR[4343] */
foo={function() {
}}
/>;
Expand Down
6 changes: 3 additions & 3 deletions tests/HackEnumAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public function testValidValues(): void {

public function testValidRawValues(): void {
// UNSAFE
$x = <test:hack-enum-attribute foo={/* HH_IGNORE_ERROR[4110] */ 1} />;
$x = <test:hack-enum-attribute foo={/* HH_IGNORE_ERROR[4110] */ /* HH_IGNORE_ERROR[4343] */ 1} />;
expect($x->toString())->toBeSame('<div>HERP</div>');
$x = <test:hack-enum-attribute foo={/* HH_IGNORE_ERROR[4110] */2} />;
$x = <test:hack-enum-attribute foo={/* HH_IGNORE_ERROR[4110] *//* HH_IGNORE_ERROR[4343] */2} />;
expect($x->toString())->toBeSame('<div>DERP</div>');
}

public function testInvalidValue(): void {
expect(() ==> {
$x = <test:hack-enum-attribute foo={/* HH_FIXME[4110] */ 0} />;
$x = <test:hack-enum-attribute foo={/* HH_FIXME[4110] */ /* HH_FIXME[4343] */ 0} />;
})->toThrow(XHPInvalidAttributeException::class);
}
}

0 comments on commit 8178618

Please sign in to comment.