Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F110012567
DifferentialCommitMessageParserTestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Apr 24, 08:38
Size
1 KB
Mime Type
text/x-php
Expires
Sat, Apr 26, 08:38 (2 d)
Engine
blob
Format
Raw Data
Handle
25777403
Attached To
rPH Phabricator
DifferentialCommitMessageParserTestCase.php
View Options
<?php
final
class
DifferentialCommitMessageParserTestCase
extends
PhabricatorTestCase
{
public
function
testDifferentialCommitMessageParser
()
{
$dir
=
dirname
(
__FILE__
).
'/messages/'
;
$list
=
Filesystem
::
listDirectory
(
$dir
,
$include_hidden
=
false
);
foreach
(
$list
as
$file
)
{
if
(!
preg_match
(
'/.txt$/'
,
$file
))
{
continue
;
}
$data
=
Filesystem
::
readFile
(
$dir
.
$file
);
$divider
=
"~~~~~~~~~~
\n
"
;
$parts
=
explode
(
$divider
,
$data
);
if
(
count
(
$parts
)
!==
4
)
{
throw
new
Exception
(
pht
(
'Expected test file "%s" to contain four parts (message, fields, '
.
'output, errors) divided by "~~~~~~~~~~".'
,
$file
));
}
list
(
$message
,
$fields
,
$output
,
$errors
)
=
$parts
;
$fields
=
phutil_json_decode
(
$fields
,
null
);
$output
=
phutil_json_decode
(
$output
,
null
);
$errors
=
phutil_json_decode
(
$errors
,
null
);
if
(
$fields
===
null
||
$output
===
null
||
$errors
===
null
)
{
throw
new
Exception
(
pht
(
'Expected test file "%s" to contain valid JSON in its sections.'
,
$file
));
}
$parser
=
id
(
new
DifferentialCommitMessageParser
())
->
setLabelMap
(
$fields
)
->
setTitleKey
(
'title'
)
->
setSummaryKey
(
'summary'
);
$result_output
=
$parser
->
parseCorpus
(
$message
);
$result_errors
=
$parser
->
getErrors
();
$this
->
assertEqual
(
$output
,
$result_output
);
$this
->
assertEqual
(
$errors
,
$result_errors
);
}
}
public
function
testDifferentialCommitMessageParserNormalization
()
{
$map
=
array
(
'Test Plan'
=>
'test plan'
,
'REVIEWERS'
=>
'reviewers'
,
'sUmmArY'
=>
'summary'
,
);
foreach
(
$map
as
$input
=>
$expect
)
{
$this
->
assertEqual
(
$expect
,
DifferentialCommitMessageParser
::
normalizeFieldLabel
(
$input
),
pht
(
'Field normalization of label "%s".'
,
$input
));
}
}
}
Event Timeline
Log In to Comment