Commit cd2ab316 authored by Danny Froberg's avatar Danny Froberg 💬
Browse files

Added more tests

parent a6fa203b
......@@ -12,6 +12,7 @@ require_once "includes/definitions.php";
*/
function bulid_field_desc($field_head,$field_desc) {
global $field_len;
$field_len = 0+(mb_strlen( "\r\n"));
$fi = 0;
foreach ($field_desc as $key) {
switch($key[5]) {
......@@ -57,19 +58,23 @@ function process_fields( $fields ) {
echo $fields['BOPREAN'] . "\t" . $fields['BOARTL'] . "\t" . $fields['BOBNL1'] . "\t" .$fields['BOBNL2'] . "\t" . make_price($fields['BOPRIS'],2)."\t" . $fields['BOENH'] ."\t".make_price($fields['BOPC1'])."\n";
}
function parse() {
function get_file($file_name) {
$file_size = filesize( $file_name );
$file_desc = fopen( $file_name,'rb' ) or die ("can't open file");
$file_buff = fread( $file_desc, $file_size );
fclose($file_desc) or die("can't close file");
return $file_buff;
}
function parse($file_name) {
global $field_head, $field_desc, $field_len;
// Build Head
$descriptor = bulid_field_desc( $field_head, $field_desc );
// Read in file
$file_name = './tests/aaa_readfile.txt';
$file_size = filesize( $file_name );
$file_desc = fopen( $file_name,'rb' ) or die ("can't open file");
$buffer = fread( $file_desc, $file_size );
$chunks = str_split($buffer, $field_len);
$i = 1;
foreach ($chunks as $lines) {
$file_buff = get_file($file_name);
$file_chunks = str_split($file_buff, $field_len);
$pretty_numbered_lines = 1;
foreach ($file_chunks as $lines) {
// $buffer_conv = mb_convert_encoding($lines,'auto', 'CP850');
$line = unpack( $descriptor, $lines );
array_walk_recursive($line, 'myEncodeFunction');
......@@ -80,22 +85,18 @@ function parse() {
var_dump( $line );
exit();
}
$fields[] = $line; //Save for later.
// var_dump( array_chunk( $line, count( $field_desc ), true ) );
echo sprintf( "%06d", $i) ."\t";
$i++;
echo sprintf( '%06d', $pretty_numbered_lines) ."\t";
$pretty_numbered_lines++;
process_fields( $line );
}
echo 'count: '.count( $field_desc )."\n";
echo 'lines: '.count( $chunks )."\n";
echo 'lines: '.count( $file_chunks )."\n";
echo 'field len: '. $field_len."\n";
//var_dump( $fields );
fclose($file_desc) or die("can't close file");
}
// Test
parse();
\ No newline at end of file
parse('./tests/aaa_readfile.txt');
parse('./tests/V1412362.TXT');
parse('./tests/V1415377.TXT');
parse('./tests/V1414924.TXT');
parse('./tests/V1417312.TXT');
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment