@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HarbormasterBuildLogTestCase
4 extends PhabricatorTestCase {
5
6 public function testBuildLogLineMaps() {
7 $snowman = "\xE2\x98\x83";
8
9 $inputs = array(
10 'no_newlines.log' => array(
11 64,
12 array(
13 str_repeat('AAAAAAAA', 32),
14 ),
15 array(
16 array(64, 0),
17 array(128, 0),
18 array(192, 0),
19 array(255, 0),
20 ),
21 ),
22 'no_newlines_updated.log' => array(
23 64,
24 array_fill(0, 32, 'AAAAAAAA'),
25 array(
26 array(64, 0),
27 array(128, 0),
28 array(192, 0),
29 ),
30 ),
31 'one_newline.log' => array(
32 64,
33 array(
34 str_repeat('AAAAAAAA', 16),
35 "\n",
36 str_repeat('AAAAAAAA', 16),
37 ),
38 array(
39 array(64, 0),
40 array(127, 0),
41 array(191, 1),
42 array(255, 1),
43 ),
44 ),
45 'several_newlines.log' => array(
46 64,
47 array_fill(0, 12, "AAAAAAAAAAAAAAAAAA\n"),
48 array(
49 array(56, 2),
50 array(113, 5),
51 array(170, 8),
52 array(227, 11),
53 ),
54 ),
55 'mixed_newlines.log' => array(
56 64,
57 array(
58 str_repeat('A', 63)."\r",
59 str_repeat('A', 63)."\r\n",
60 str_repeat('A', 63)."\n",
61 str_repeat('A', 63),
62 ),
63 array(
64 array(63, 0),
65 array(127, 1),
66 array(191, 2),
67 array(255, 3),
68 ),
69 ),
70 'more_mixed_newlines.log' => array(
71 64,
72 array(
73 str_repeat('A', 63)."\r",
74 str_repeat('A', 62)."\r\n",
75 str_repeat('A', 63)."\n",
76 str_repeat('A', 63),
77 ),
78 array(
79 array(63, 0),
80 array(128, 2),
81 array(191, 2),
82 array(254, 3),
83 ),
84 ),
85 'emoji.log' => array(
86 64,
87 array(
88 str_repeat($snowman, 64),
89 ),
90 array(
91 array(63, 0),
92 array(126, 0),
93 array(189, 0),
94 ),
95 ),
96 );
97
98 foreach ($inputs as $label => $input) {
99 list($distance, $parts, $expect) = $input;
100
101 $log = id(new HarbormasterBuildLog())
102 ->setByteLength(0);
103
104 foreach ($parts as $part) {
105 $log->updateLineMap($part, $distance);
106 }
107
108 list($actual) = $log->getLineMap();
109
110 $this->assertEqual(
111 $expect,
112 $actual,
113 pht('Line Map for "%s"', $label));
114 }
115 }
116
117}