Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Aug 29, 2022
1 parent d10212a commit d6636cf
Show file tree
Hide file tree
Showing 36 changed files with 222 additions and 34 deletions.
6 changes: 3 additions & 3 deletions dsv/base/parse/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ setReadOnly( Parser.prototype, '_push', function push( ch ) {
this._cursor += 1;

// Only expand the internal buffer if we've run out of previously allocated memory...
if ( this._cursor > buf.length ) {
if ( this._cursor >= buf.length ) {
buf.push( ch );
debug( 'Internal buffer size increased. Length: %d.', buf.length );
} else {
Expand Down Expand Up @@ -474,8 +474,8 @@ setReadOnly( Parser.prototype, '_onCommentedRow', function onCommentedRow() {
if ( this._trimComment ) {
// FIXME: trim the leading and trailing whitespace (e.g., using @stdlib/string/base/trim)
}
this._onComment( v );
debug( 'Comment: %s', v );
this._onComment( v, this._line );
debug( 'New comment. Line: %d. Value: %s', this._line, v );
}
// Increment the counter for how many lines have been processed:
this._line += 1;
Expand Down
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/basic.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"3"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/comment.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"3"
]
]
}
}
5 changes: 5 additions & 0 deletions dsv/base/parse/test/fixtures/comment_sequence.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##$$@@ comment 1
a,b,c
##$$@@ comment 2
1,2,3
##$$@@ comment 3
15 changes: 15 additions & 0 deletions dsv/base/parse/test/fixtures/comment_sequence.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"dsv": "##$$@@ comment 1\na,b,c\n##$$@@ comment 2\n1,2,3\n##$$@@ comment 3\n",
"json": [
[
"a",
"b",
"c"
],
[
"1",
"2",
"3"
]
]
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/custom_delimiter.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"d"
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"d"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/custom_newline.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"9"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/custom_newline_sequence.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"6"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/custom_quote.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"5"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/custom_quote_sequence.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"5"
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"'7'"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/doublequote.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"4"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/doublequote_custom_quote.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
"4"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/earthquakes.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/empty.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dsv": "",
"json": []
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/empty_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
"b"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/empty_leading_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"b"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/empty_lines.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"6"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/empty_quoted_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
""
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/empty_trailing_fields.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
""
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/field_leading_whitespace.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"6"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/json.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"{\"a\": \"b\", \"c\": [1, 2]}"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/latin.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"©"
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
"12345"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/quoted_field_with_escape.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"\"7\""
]
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"\n9"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/ragged.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@
"9"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/simple.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"6"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/simple2.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"6"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/small.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"a"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/unicode1.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"中国人"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/unicode2.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
"english"
]
]
}
}
2 changes: 1 addition & 1 deletion dsv/base/parse/test/fixtures/utf8.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"ʤ"
]
]
}
}
84 changes: 84 additions & 0 deletions dsv/base/parse/test/test.comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2022 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var tape = require( 'tape' );
var Parser = require( './../lib' );


// FIXTURES //

var fixture = require( './fixtures/comment.json' );


// TESTS //

tape( 'main export is a function', function test( t ) {
t.ok( true, __filename );
t.equal( typeof Parser, 'function', 'main export is a function' );
t.end();
});

tape( 'the parser successfully parses DSV containing comments', function test( t ) {
var expected;
var comments;
var flg1;
var flg2;
var p;
var i;
var j;

expected = fixture.json;
i = 0;

comments = [
' comment 1',
' comment 2',
' comment 3'
];
j = 0;

p = new Parser({
'newline': '\n',
'comment': '#',
'onRow': onRow,
'onComment': onComment,
'onClose': onClose
});
p.next( fixture.dsv ).close();

function onRow( record, row ) {
flg1 = true;
t.deepEqual( record, expected[ i ], 'returns expected value. Row: '+row+'.' );
i += 1;
}

function onComment( str, line ) {
flg2 = true;
t.strictEqual( str, comments[ j ], 'returns expected value. Line: '+line+'.' );
j += 1;
}

function onClose() {
t.ok( flg1 && flg2, 'parses rows' );
t.end();
}
});
Loading

0 comments on commit d6636cf

Please sign in to comment.