Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889776
DifferentialDiffTestCase.php
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
DifferentialDiffTestCase.php
View Options
<?php
final
class
DifferentialDiffTestCase
extends
ArcanistPhutilTestCase
{
public
function
testDetectCopiedCode
(
)
{
$copies
=
$this
->
detectCopiesIn
(
'lint_engine.diff'
)
;
$this
->
assertEqual
(
array_combine
(
range
(
237
,
252
)
,
range
(
167
,
182
)
)
,
ipull
(
$copies
,
1
)
)
;
}
public
function
testDetectCopiedOverlaidCode
(
)
{
$copies
=
$this
->
detectCopiesIn
(
'copy_overlay.diff'
)
;
$this
->
assertEqual
(
array
(
7
=>
22
,
8
=>
23
,
9
=>
24
,
10
=>
25
,
11
=>
26
,
12
=>
27
,
)
,
ipull
(
$copies
,
1
)
)
;
}
private
function
detectCopiesIn
(
$file
)
{
$root
=
dirname
(
__FILE__
)
.
'/diff/'
;
$parser
=
new
ArcanistDiffParser
(
)
;
$diff
=
DifferentialDiff
::
newFromRawChanges
(
PhabricatorUser
::
getOmnipotentUser
(
)
,
$parser
->
parseDiff
(
Filesystem
::
readFile
(
$root
.
$file
)
)
)
;
return
idx
(
head
(
$diff
->
getChangesets
(
)
)
->
getMetadata
(
)
,
'copy:lines'
)
;
}
public
function
testDetectSlowCopiedCode
(
)
{
// This tests that the detector has a reasonable runtime when a diff
// contains a very large number of identical lines. See T5041.
$parser
=
new
ArcanistDiffParser
(
)
;
$line
=
str_repeat
(
'x'
,
60
)
;
$oline
=
'-'
.
$line
.
"\n"
;
$nline
=
'+'
.
$line
.
"\n"
;
$n
=
1000
;
$oblock
=
str_repeat
(
$oline
,
$n
)
;
$nblock
=
str_repeat
(
$nline
,
$n
)
;
$raw_diff
=
<<<EODIFF
diff --git a/dst b/dst
new file mode 100644
index 0000000..1234567
--- /dev/null
+++ b/dst
@@ -0,0 +1,{$n} @@
{$nblock}
diff --git a/src b/src
deleted file mode 100644
index 123457..0000000
--- a/src
+++ /dev/null
@@ -1,{$n} +0,0 @@
{$oblock}
EODIFF
;
$diff
=
DifferentialDiff
::
newFromRawChanges
(
PhabricatorUser
::
getOmnipotentUser
(
)
,
$parser
->
parseDiff
(
$raw_diff
)
)
;
$this
->
assertTrue
(
true
)
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 12:38 (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124650
Default Alt Text
DifferentialDiffTestCase.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment