Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F1308
Annotation.test.php
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
bzimport
Nov 21 2014, 6:56 PM
2014-11-21 18:56:17 (UTC+0)
Size
12 KB
Referenced Files
None
Subscribers
None
Annotation.test.php
View Options
<?php
class
AnnotationTestCase
extends
UnitTestCase
{
var
$id
=
0
;
var
$info
;
function
setUp
()
{
$this
->
info
=
new
Mock_RevisionInfo
(
$this
);
$this
->
info
->
id
=
$this
->
id
++;
//make sure equality doesn't match
//a different mock object
}
}
class
UnitTest_ExtendedString
extends
AnnotationTestCase
{
function
test_newFromArray
()
{
$expect
=
new
ExtendedString
(
'FooBar'
,
$this
->
info
);
$result
=
ExtendedString
::
newFromArray
(
array
(
'Foo'
,
'Bar'
),
$this
->
info
);
$this
->
assertEqual
(
$expect
,
$result
);
}
function
test_substr
()
{
$subject
=
new
ExtendedString
(
'123456789'
,
$this
->
info
);
$result
=
$subject
->
substr
(
4
);
$expect
=
new
ExtendedString
(
'56789'
,
$this
->
info
);
$this
->
assertEqual
(
$expect
,
$result
);
$result
=
$subject
->
substr
(
2
,
2
);
$expect
=
new
ExtendedString
(
'34'
,
$this
->
info
);
$this
->
assertEqual
(
$expect
,
$result
);
}
function
test_append
()
{
$result
=
new
ExtendedString
(
'Word'
,
$this
->
info
);
$result
->
append
(
' '
);
$expect
=
new
ExtendedString
(
'Word '
,
$this
->
info
);
$this
->
assertEqual
(
$expect
,
$result
);
}
function
test_splitAt
()
{
$subject
=
new
ExtendedString
(
'1234foo'
,
$this
->
info
);
$result
=
$subject
->
splitAt
(
4
);
$expect
=
array
(
new
ExtendedString
(
'1234'
,
$this
->
info
),
new
ExtendedString
(
'foo'
,
$this
->
info
));
$this
->
assertEqual
(
$expect
,
$result
);
}
function
test_strlen
()
{
$subject
=
new
ExtendedString
(
'1234'
,
$this
->
info
);
$result
=
$subject
->
strlen
();
$this
->
assertEqual
(
4
,
$result
);
}
}
class
UnitTest_Annotation
extends
AnnotationTestCase
{
var
$infos
=
array
();
//creates a uniquely identified string
function
str
(
$string
)
{
$info
=
$this
->
inf
();
$this
->
infos
[
$string
]
=
$info
;
return
new
ExtendedString
(
$string
,
$info
);
}
//creates a uniquely identified info mock
function
inf
()
{
$info
=
new
Mock_RevisionInfo
(
$this
);
$info
->
id
=
$this
->
id
++;
return
$info
;
}
function
test_copy
()
{
// realistic style
$info
=
new
UnknownRevisionInfo
();
$result
=
new
Annotation
(
array
(
new
ExtendedString
(
'String to be copied'
,
$info
)
));
$result
->
copy
(
7
);
$expect
=
new
Annotation
(
array
(
new
ExtendedString
(
'String '
,
$info
),
new
ExtendedString
(
'to be copied'
,
$info
)
),
array
(
1
,
0
)
);
$this
->
assertEqual
(
$expect
,
$result
);
$subjects
=
$copy
=
$expect
=
$position
=
array
();
// copy entire string
$info_1
=
$this
->
inf
();
$subjects
[
0
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Foobar'
,
$info_1
)
));
$copy
[
0
]
=
array
(
6
,
new
ExtendedString
(
'Foobar'
,
$info_1
)
);
$expect
[
0
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Foobar'
,
$info_1
)
),
array
(
1
,
0
)
);
//cursors are set at nonexistant entry
// copy segment of string, break apart because of it
$info_1
=
$this
->
inf
();
//all segments must have same revision info
$subjects
[
1
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Word to your mother'
,
$info_1
)
));
$copy
[
1
]
=
array
(
5
,
new
ExtendedString
(
'Word '
,
$info_1
)
);
$expect
[
1
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Word '
,
$info_1
),
new
ExtendedString
(
'to your mother'
,
$info_1
)
),
array
(
1
,
0
)
);
// copy over string and break apart
$info_1
=
$this
->
inf
();
$info_2
=
$this
->
inf
();
$subjects
[
2
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Tis '
,
$info_1
),
new
ExtendedString
(
'a shame.'
,
$info_2
)
));
$copy
[
2
]
=
array
(
6
,
new
ExtendedString
(
'Tis a '
,
$info_1
));
$expect
[
2
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Tis '
,
$info_1
),
new
ExtendedString
(
'a '
,
$info_2
),
new
ExtendedString
(
'shame.'
,
$info_2
)
),
array
(
2
,
0
)
);
// second parameter is different distance (to account for space adding
// bug in the diffing app)
$info_1
=
$this
->
inf
();
$info_2
=
$this
->
inf
();
$subjects
[
3
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Nothing'
,
$info_1
)
));
$copy
[
3
]
=
array
(
7
,
new
ExtendedString
(
'Nothing '
,
$info_2
));
$expect
[
3
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Nothing '
,
$info_1
)
),
array
(
1
,
0
)
);
//musn't change
// starting point from second entry
$info_1
=
$this
->
inf
();
$info_2
=
$this
->
inf
();
$subjects
[
4
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Part 1 '
,
$info_1
),
new
ExtendedString
(
'Part 2'
,
$info_2
)
)
,
array
(
1
,
0
)
);
$copy
[
4
]
=
array
(
5
,
new
ExtendedString
(
'Part '
,
$info_2
));
$expect
[
4
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'Part 1 '
,
$info_1
),
new
ExtendedString
(
'Part '
,
$info_2
),
new
ExtendedString
(
'2'
,
$info_2
)
)
,
array
(
2
,
0
)
);
// starting point from slightly inside first entry
// theoretically, this case should never come up, but defense in depth!
// what happens is that we don't break up anything, it just handles it
// as if the ExtendedString startd off slightly smaller
$info_1
=
$this
->
inf
();
$subjects
[
5
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'FooBar'
,
$info_1
)
),
array
(
0
,
3
)
);
$copy
[
5
]
=
array
(
3
,
new
ExtendedString
(
'Bar'
,
$info_1
));
$expect
[
5
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'FooBar'
,
$info_1
)
),
array
(
1
,
0
)
);
// copy over strings and phantoms
$info_1
=
$this
->
inf
();
$info_2
=
$this
->
inf
();
$subjects
[
6
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'To be or '
,
$info_1
),
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'to be.'
,
$info_1
)
));
$copy
[
6
]
=
array
(
15
,
new
ExtendedString
(
'To be or to be.'
,
$info_2
));
$expect
[
6
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'To be or '
,
$info_1
),
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'to be.'
,
$info_1
)
),
array
(
3
,
0
)
);
// copy ends on a phantom
// here's the joker. does the copier simply stop before the phantom
// string, or does the copier skip over as many phantoms as it can
// before it starts again? Or maybe it obliterates all the phantoms?
// I tend to favor the latter: having a copy stop at a certain point
// means that an add/delete/change is going to happen, which means that
// deleting phantoms would be a good way to reduce clutter. HOWEVER...
// you also have to wonder about the implications of deleting all the
// phantoms write before *another* deletion. Only one delete implies
// only one person deleted things, while maybe three people contributed
// to the black hole.
// It, then, would make sense to leave it to the other commands to
// clean up after these, and in order to facilitate it, we will keep
// the current behavior, which is not to munch up any phantoms once
// it has finished.
$info_1
=
$this
->
inf
();
$info_2
=
$this
->
inf
();
$subjects
[
7
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'To be or '
,
$info_1
),
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'to be.'
,
$info_1
)
));
$copy
[
7
]
=
array
(
9
,
new
ExtendedString
(
'To be or '
,
$info_2
));
$expect
[
7
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'To be or '
,
$info_1
),
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'to be.'
,
$info_1
)
),
array
(
1
,
0
)
);
//cursor is set right *at* phantom string
foreach
(
$subjects
as
$i
=>
$subject
)
{
$subject
->
copy
(
$copy
[
$i
][
0
],
$copy
[
$i
][
1
]);
$this
->
assertEqual
(
$expect
[
$i
],
$subject
,
"Run $i: %s"
);
}
}
function
test_add
()
{
// realistic style
$info_1
=
new
UnknownRevisionInfo
();
$info_2
=
$this
->
inf
();
$result
=
new
Annotation
(
array
(
new
ExtendedString
(
'Original text. '
,
$info_1
)
),
array
(
1
,
0
));
$result
->
add
(
new
ExtendedString
(
'Added text.'
,
$info_2
));
$expect
=
new
Annotation
(
array
(
new
ExtendedString
(
'Original text. '
,
$info_1
),
new
ExtendedString
(
'Added text.'
,
$info_2
)
),
array
(
2
,
0
));
$this
->
assertEqual
(
$expect
,
$result
);
$subjects
=
$add
=
$expect
=
$position
=
array
();
// add scrolls past all phantoms, and then inserts its object
$info_1
=
$this
->
inf
();
$info_2
=
$this
->
inf
();
$subjects
[
0
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'To be or '
,
$info_1
),
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'to be.'
,
$info_1
)
),
array
(
1
,
0
)
);
$add
[
0
]
=
new
ExtendedString
(
'not '
,
$info_1
);
$expect
[
0
]
=
new
Annotation
(
array
(
new
ExtendedString
(
'To be or '
,
$info_1
),
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'not '
,
$info_1
),
new
ExtendedString
(
'to be.'
,
$info_1
)
),
array
(
3
,
0
)
);
foreach
(
$subjects
as
$i
=>
$subject
)
{
$subject
->
add
(
$add
[
$i
]);
$this
->
assertEqual
(
$expect
[
$i
],
$subject
,
"Run $i: %s"
);
}
}
function
test_delete
()
{
$info_1
=
new
UnknownRevisionInfo
();
$info_2
=
$this
->
inf
();
$result
=
new
Annotation
(
array
(
new
ExtendedString
(
'I love big things.'
,
$info_1
)
));
$result
->
delete
(
7
,
$info_2
);
$expect
=
new
Annotation
(
array
(
new
PhantomString
(
$info_2
),
new
ExtendedString
(
'big things.'
,
$info_1
)
)
);
$this
->
assertEqual
(
$expect
,
$result
);
}
function
test_change
()
{
$info_1
=
new
UnknownRevisionInfo
();
$info_2
=
$this
->
inf
();
$result
=
new
Annotation
(
array
(
new
ExtendedString
(
'I absolutely '
,
$info_1
),
new
ExtendedString
(
'hate these bears.'
,
$info_1
)
),
array
(
1
,
0
)
);
$result
->
change
(
4
,
new
ExtendedString
(
'love'
,
$info_2
));
$expect
=
new
Annotation
(
array
(
new
ExtendedString
(
'I absolutely '
,
$info_1
),
new
ExtendedString
(
'love'
,
$info_2
),
new
ExtendedString
(
' these bears.'
,
$info_1
)
),
array
(
2
,
0
)
);
$this
->
assertEqual
(
$expect
,
$result
);
//needs test for phantoms
}
function
test_compile
()
{
$text_1
=
'Lalala'
;
$text_2
=
'Lalala is cool.'
;
$text_3
=
'Lalala is cool.
Perhaps we should give it a new name?'
;
$text_4
=
'Lalalala is not cool.
Perhaps we should give it a new name?'
;
$revisions
=
array
();
$revisions
[]
=
new
ExtendedString
(
$text_1
,
new
RevisionInfo
(
1
,
3
,
'Creator'
,
100
,
0
));
$revisions
[]
=
new
ExtendedString
(
$text_2
,
new
RevisionInfo
(
2
,
5
,
'Gnome'
,
200
,
1
));
$revisions
[]
=
new
ExtendedString
(
$text_3
,
new
RevisionInfo
(
3
,
7
,
'Expander'
,
400
,
0
));
$revisions
[]
=
new
ExtendedString
(
$text_4
,
new
RevisionInfo
(
4
,
9
,
'Vandal'
,
410
,
0
));
$expect
=
new
Annotation
(
array
(
new
ExtendedString
(
'Lalalala '
,
new
RevisionInfo
(
4
,
9
,
'Vandal'
,
410
,
0
))
,
new
ExtendedString
(
'is '
,
new
RevisionInfo
(
2
,
5
,
'Gnome'
,
200
,
1
))
,
new
ExtendedString
(
'not '
,
new
RevisionInfo
(
4
,
9
,
'Vandal'
,
410
,
0
))
,
new
ExtendedString
(
'cool.'
,
new
RevisionInfo
(
2
,
5
,
'Gnome'
,
200
,
1
))
,
new
ExtendedString
(
"
\n\n
"
.
'Perhaps we should give it a new name?'
,
new
RevisionInfo
(
3
,
7
,
'Expander'
,
400
,
0
))
));
$annotation
=
Annotation
::
newFromRevisions
(
$revisions
);
$this
->
assertEqual
(
$expect
,
$annotation
);
}
}
?>
File Metadata
Details
Attached
Mime Type
text/x-php
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1207
Default Alt Text
Annotation.test.php (12 KB)
Attached To
Mode
T2639: [Epic] Add feature annotate/blame command, to indicate who last changed each line / word
Attached
Detach File
Event Timeline
Log In to Comment