App-RecordStream
view release on metacpan or search on metacpan
tests/RecordStream/Operation/toptable.t view on Meta::CPAN
TABLE
# --v field order is respected on output
App::RecordStream::Test::OperationHelper->test_output(
'toptable',
['--x', '!b!,FIELD', '--y', '!^(a|c)$!sort', '--v', 'ct,avg_d'],
$stream2,
$table4,
);
my $pin_records = <<RECORDS;
{"c":"2","a":{"1":{"b":{"1":4,"2":1}},"0":{"b":{"0":1,"2":4}},"2":{"b":{"1":21,"0":"","2":22}}},"d":"1"}
{"c":"2","a":{"1":{"b":{"1":"","2":""}},"0":{"b":{"0":6,"2":27}},"2":{"b":{"1":3,"0":25,"2":26}}},"d":"2"}
{"c":"2","a":{"1":{"b":{"1":"","2":""}},"0":{"b":{"0":22,"2":2}},"2":{"b":{"1":"","0":"","2":""}}},"d":"0"}
RECORDS
App::RecordStream::Test::OperationHelper->do_match(
'toptable',
['--x', 'a,b', '--y', 'c,d', '--pin', 'c=2', '--records'],
$stream1,
$pin_records,
);
my $sort_stream = <<RECORDS;
{"priority":"20","uid":"root","ct":47}
{"priority":"20","uid":"ALL","ct":120}
{"priority":"20","uid":"messagebus","ct":1}
{"priority":"20","uid":"syslog","ct":1}
{"priority":"20","uid":"avahi","ct":2}
{"priority":"20","uid":"daemon","ct":1}
{"priority":"20","uid":"colord","ct":1}
{"priority":"20","uid":"bernard","ct":67}
{"priority":"ALL","uid":"root","ct":63}
{"priority":"ALL","uid":"ALL","ct":140}
{"priority":"ALL","uid":"messagebus","ct":1}
{"priority":"ALL","uid":"syslog","ct":1}
{"priority":"ALL","uid":"avahi","ct":2}
{"priority":"ALL","uid":"daemon","ct":1}
{"priority":"ALL","uid":"colord","ct":1}
{"priority":"ALL","uid":"rtkit","ct":1}
{"priority":"ALL","uid":"bernard","ct":70}
{"priority":"-100","uid":"root","ct":1}
{"priority":"-100","uid":"ALL","ct":1}
{"priority":"0","uid":"root","ct":12}
{"priority":"0","uid":"ALL","ct":12}
{"priority":"25","uid":"root","ct":1}
{"priority":"25","uid":"ALL","ct":1}
{"priority":"39","uid":"root","ct":1}
{"priority":"39","uid":"ALL","ct":1}
{"priority":"10","uid":"root","ct":1}
{"priority":"10","uid":"ALL","ct":1}
{"priority":"21","uid":"rtkit","ct":1}
{"priority":"21","uid":"ALL","ct":1}
{"priority":"9","uid":"bernard","ct":1}
{"priority":"9","uid":"ALL","ct":1}
{"priority":"30","uid":"bernard","ct":2}
{"priority":"30","uid":"ALL","ct":2}
RECORDS
my $unsorted_output = <<OUTPUT;
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
| |uid|root|ALL|messagebus|syslog|avahi|daemon|colord|bernard|rtkit|
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|priority| | | | | | | | | | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|20 | |47 |120|1 |1 |2 |1 |1 |67 | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|ALL | |63 |140|1 |1 |2 |1 |1 |70 |1 |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|-100 | |1 |1 | | | | | | | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|0 | |12 |12 | | | | | | | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|25 | |1 |1 | | | | | | | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|39 | |1 |1 | | | | | | | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|10 | |1 |1 | | | | | | | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|21 | | |1 | | | | | | |1 |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|9 | | |1 | | | | | |1 | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
|30 | | |2 | | | | | |2 | |
+--------+---+----+---+----------+------+-----+------+------+-------+-----+
OUTPUT
# Test input order
App::RecordStream::Test::OperationHelper->test_output(
'toptable',
['--x', 'uid', '--y', 'priority'],
$sort_stream,
$unsorted_output,
);
my $sorted_output = <<OUTPUT;
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
| |uid|avahi|bernard|colord|daemon|messagebus|root|rtkit|syslog|ALL|
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|priority| | | | | | | | | | |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|-100 | | | | | | |1 | | |1 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|0 | | | | | | |12 | | |12 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|10 | | | | | | |1 | | |1 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|20 | |2 |67 |1 |1 |1 |47 | |1 |120|
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|21 | | | | | | | |1 | |1 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|25 | | | | | | |1 | | |1 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|30 | | |2 | | | | | | |2 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|39 | | | | | | |1 | | |1 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|9 | | |1 | | | | | | |1 |
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
|ALL | |2 |70 |1 |1 |1 |63 |1 |1 |140|
+--------+---+-----+-------+------+------+----------+----+-----+------+---+
OUTPUT
# Test sort-to-end
App::RecordStream::Test::OperationHelper->test_output(
'toptable',
['--x', 'uid', '--y', 'priority', '--sa'],
$sort_stream,
$sorted_output,
);
( run in 0.876 second using v1.01-cache-2.11-cpan-39bf76dae61 )