mirror of
https://github.com/expo/fbshipit.git
synced 2026-11-15 17:33:57 -10:00
Summary:Requested by nuclide. New behavior is that oneline sections are always on the same line as the header, multiline sections are always on later lines Reviewed By: zertosh Differential Revision: D3193404 fb-gh-sync-id: 0e64a6e52e6824f320bbbd45c1c4e22b95238d9d fbshipit-source-id: 0e64a6e52e6824f320bbbd45c1c4e22b95238d9d
138 lines
3.3 KiB
PHP
138 lines
3.3 KiB
PHP
<?hh
|
|
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
namespace Facebook\ShipIt;
|
|
|
|
|
|
final class MessageSectionsTest extends BaseTest {
|
|
public function examplesForGetSections(
|
|
): array<(string, ?ImmSet<string>, ImmMap<string, string>)> {
|
|
return [
|
|
tuple(
|
|
"Summary: Foo\nFor example: bar",
|
|
ImmSet { 'summary' },
|
|
ImmMap {
|
|
'summary' => "Foo\nFor example: bar",
|
|
},
|
|
),
|
|
tuple(
|
|
"Summary: Foo\nTest plan: bar",
|
|
ImmSet { 'summary', 'test plan' },
|
|
ImmMap {
|
|
'summary' => 'Foo',
|
|
'test plan' => 'bar',
|
|
},
|
|
),
|
|
tuple(
|
|
'Foo: bar',
|
|
null,
|
|
ImmMap { 'foo' => 'bar' },
|
|
),
|
|
tuple(
|
|
'Foo: Bar: baz',
|
|
ImmSet { 'foo' },
|
|
ImmMap { 'foo' => 'Bar: baz' },
|
|
),
|
|
tuple(
|
|
'Foo: Bar: baz',
|
|
ImmSet { 'bar' },
|
|
ImmMap { '' => 'Foo: Bar: baz' },
|
|
),
|
|
tuple(
|
|
'Foo: Bar: baz',
|
|
ImmSet { 'foo', 'bar' },
|
|
ImmMap { 'bar' => 'baz' },
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider examplesForGetSections
|
|
*/
|
|
public function testGetSections(
|
|
string $message,
|
|
?ImmSet<string> $valid,
|
|
ImmMap<string, string> $expected,
|
|
): void {
|
|
$in = (new ShipItChangeset())->withMessage($message);
|
|
$out = ShipItMessageSections::getSections($in, $valid);
|
|
$this->assertEquals($expected, $out->toImmMap());
|
|
}
|
|
|
|
public function examplesForBuildMessage(
|
|
): array<(ImmMap<string, string>, string)> {
|
|
return [
|
|
tuple(
|
|
ImmMap { 'foo' => 'bar' },
|
|
'Foo: bar',
|
|
),
|
|
tuple(
|
|
ImmMap { 'foo' => "bar\nbaz" },
|
|
"Foo:\nbar\nbaz",
|
|
),
|
|
tuple(
|
|
ImmMap { 'foo bar' => 'herp derp' },
|
|
'Foo Bar: herp derp',
|
|
),
|
|
tuple(
|
|
ImmMap { 'foo' => '' },
|
|
'',
|
|
),
|
|
tuple(
|
|
ImmMap { 'foo' => 'bar', 'herp' => 'derp' },
|
|
"Foo: bar\n\nHerp: derp",
|
|
),
|
|
tuple(
|
|
ImmMap { 'foo' => '', 'herp' => 'derp' },
|
|
"Herp: derp",
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider examplesForBuildMessage
|
|
*/
|
|
public function testBuildMessage(
|
|
ImmMap<string, string> $sections,
|
|
string $expected,
|
|
): void {
|
|
$this->assertSame(
|
|
$expected,
|
|
ShipItMessageSections::buildMessage($sections),
|
|
);
|
|
}
|
|
|
|
public function getExamplesForWhitespaceEndToEnd(
|
|
): array<(string, string)> {
|
|
return [
|
|
tuple("Summary: foo", 'Summary: foo'),
|
|
tuple("Summary:\nfoo", 'Summary: foo'),
|
|
tuple("Summary: foo\nbar", "Summary:\nfoo\nbar"),
|
|
tuple("Summary:\nfoo\nbar", "Summary:\nfoo\nbar"),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider getExamplesForWhitespaceEndToEnd
|
|
*/
|
|
public function testWhitespaceEndToEnd(
|
|
string $in,
|
|
string $expected,
|
|
): void {
|
|
$message = (new ShipItChangeset())
|
|
->withMessage($in)
|
|
|> ShipItMessageSections::getSections($$, ImmSet { 'summary' })
|
|
|> ShipItMessageSections::buildMessage($$->toImmMap());
|
|
$this->assertSame(
|
|
$expected,
|
|
$message,
|
|
);
|
|
}
|
|
}
|