Skip to content

Commit

Permalink
refactor(std): Uncomment disabled tests, use skip option (denoland#4378)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Mar 15, 2020
1 parent 2f4be6e commit 6471d4c
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 265 deletions.
259 changes: 138 additions & 121 deletions std/encoding/csv_test.ts
Expand Up @@ -29,21 +29,22 @@ const testCases = [
Input: "a,b\rc,d\r\n",
Output: [["a", "b\rc", "d"]]
},
// {
// Name: "RFC4180test",
// Input: `#field1,field2,field3
// "aaa","bbb","ccc"
// "a,a","bbb","ccc"
// zzz,yyy,xxx`,
// UseFieldsPerRecord: true,
// FieldsPerRecord: 0,
// Output: [
// ["#field1", "field2", "field3"],
// ["aaa", "bbb", "ccc"],
// ["a,a", `bbb`, "ccc"],
// ["zzz", "yyy", "xxx"]
// ]
// },
{
Name: "RFC4180test",
Input: `#field1,field2,field3
"aaa","bbb","ccc"
"a,a","bbb","ccc"
zzz,yyy,xxx`,
UseFieldsPerRecord: true,
FieldsPerRecord: 0,
Output: [
["#field1", "field2", "field3"],
["aaa", "bbb", "ccc"],
["a,a", `bbb`, "ccc"],
["zzz", "yyy", "xxx"]
],
skip: true
},
{
Name: "NoEOLTest",
Input: "a,b,c",
Expand All @@ -55,14 +56,15 @@ const testCases = [
Output: [["a", "b", "c"]],
Comma: ";"
},
// {
// Name: "MultiLine",
// Input: `"two
// line","one line","three
// line
// field"`,
// Output: [["two\nline"], ["one line"], ["three\nline\nfield"]]
// },
{
Name: "MultiLine",
Input: `"two
line","one line","three
line
field"`,
Output: [["two\nline"], ["one line"], ["three\nline\nfield"]],
skip: true
},
{
Name: "BlankLine",
Input: "a,b,c\n\nd,e,f\n\n",
Expand Down Expand Up @@ -256,54 +258,62 @@ x,,,
],
ReuseRecord: true
},
// {
// Name: "StartLine1", // Issue 19019
// Input: 'a,"b\nc"d,e',
// Error: true
// // Error: &ParseError{StartLine: 1, Line: 2, Column: 1, Err: ErrQuote},
// },
// {
// Name: "StartLine2",
// Input: 'a,b\n"d\n\n,e',
// Error: true
// // Error: &ParseError{StartLine: 2, Line: 5, Column: 0, Err: ErrQuote},
// },
// {
// Name: "CRLFInQuotedField", // Issue 21201
// Input: 'A,"Hello\r\nHi",B\r\n',
// Output: [["A", "Hello\nHi", "B"]]
// },
{
Name: "StartLine1", // Issue 19019
Input: 'a,"b\nc"d,e',
Error: true,
// Error: &ParseError{StartLine: 1, Line: 2, Column: 1, Err: ErrQuote},
skip: true
},
{
Name: "StartLine2",
Input: 'a,b\n"d\n\n,e',
Error: true,
// Error: &ParseError{StartLine: 2, Line: 5, Column: 0, Err: ErrQuote},
skip: true
},
{
Name: "CRLFInQuotedField", // Issue 21201
Input: 'A,"Hello\r\nHi",B\r\n',
Output: [["A", "Hello\nHi", "B"]],
skip: true
},
{
Name: "BinaryBlobField", // Issue 19410
Input: "x09\x41\xb4\x1c,aktau",
Output: [["x09A\xb4\x1c", "aktau"]]
},
// {
// Name: "TrailingCR",
// Input: "field1,field2\r",
// Output: [["field1", "field2"]]
// },
// {
// Name: "QuotedTrailingCR",
// Input: '"field"\r',
// Output: [['"field"']]
// },
// {
// Name: "QuotedTrailingCRCR",
// Input: '"field"\r\r',
// Error: true,
// // Error: &ParseError{StartLine: 1, Line: 1, Column: 6, Err: ErrQuote},
// },
// {
// Name: "FieldCR",
// Input: "field\rfield\r",
// Output: [["field\rfield"]]
// },
// {
// Name: "FieldCRCR",
// Input: "field\r\rfield\r\r",
// Output: [["field\r\rfield\r"]]
// },
{
Name: "TrailingCR",
Input: "field1,field2\r",
Output: [["field1", "field2"]],
skip: true
},
{
Name: "QuotedTrailingCR",
Input: '"field"\r',
Output: [['"field"']],
skip: true
},
{
Name: "QuotedTrailingCRCR",
Input: '"field"\r\r',
Error: true,
// Error: &ParseError{StartLine: 1, Line: 1, Column: 6, Err: ErrQuote},
skip: true
},
{
Name: "FieldCR",
Input: "field\rfield\r",
Output: [["field\rfield"]],
skip: true
},
{
Name: "FieldCRCR",
Input: "field\r\rfield\r\r",
Output: [["field\r\rfield\r"]],
skip: true
},
{
Name: "FieldCRCRLF",
Input: "field\r\r\nfield\r\r\n",
Expand All @@ -314,20 +324,22 @@ x,,,
Input: "field\r\r\n\rfield\r\r\n\r",
Output: [["field\r"], ["\rfield\r"]]
},
// {
// Name: "FieldCRCRLFCRCR",
// Input: "field\r\r\n\r\rfield\r\r\n\r\r",
// Output: [["field\r"], ["\r\rfield\r"], ["\r"]]
// },
// {
// Name: "MultiFieldCRCRLFCRCR",
// Input: "field1,field2\r\r\n\r\rfield1,field2\r\r\n\r\r,",
// Output: [
// ["field1", "field2\r"],
// ["\r\rfield1", "field2\r"],
// ["\r\r", ""]
// ]
// },
{
Name: "FieldCRCRLFCRCR",
Input: "field\r\r\n\r\rfield\r\r\n\r\r",
Output: [["field\r"], ["\r\rfield\r"], ["\r"]],
skip: true
},
{
Name: "MultiFieldCRCRLFCRCR",
Input: "field1,field2\r\r\n\r\rfield1,field2\r\r\n\r\r,",
Output: [
["field1", "field2\r"],
["\r\rfield1", "field2\r"],
["\r\r", ""]
],
skip: true
},
{
Name: "NonASCIICommaAndComment",
Input: "a£b,c£ \td,e\n€ comment\n",
Expand Down Expand Up @@ -358,30 +370,30 @@ x,,,
Output: [["λ"], ["λ"], ["λ"]],
Comment: "θ"
},
// {
// Name: "QuotedFieldMultipleLF",
// Input: '"\n\n\n\n"',
// Output: [["\n\n\n\n"]]
// },
// {
// Name: "MultipleCRLF",
// Input: "\r\n\r\n\r\n\r\n"
// },
{
Name: "QuotedFieldMultipleLF",
Input: '"\n\n\n\n"',
Output: [["\n\n\n\n"]],
skip: true
},
{
Name: "MultipleCRLF",
Input: "\r\n\r\n\r\n\r\n",
skip: true
},
/**
* The implementation may read each line in several chunks if
* it doesn't fit entirely.
* in the read buffer, so we should test the code to handle that condition.
*/
// {
// Name: "HugeLines",
// Input:
// strings.Repeat("#ignore\n", 10000) +
// strings.Repeat("@", 5000) +
// "," +
// strings.Repeat("*", 5000),
// Output: [[strings.Repeat("@", 5000), strings.Repeat("*", 5000)]],
// Comment: "#"
// },
{
Name: "HugeLines",
Input:
"#ignore\n".repeat(10000) + "@".repeat(5000) + "," + "*".repeat(5000),
Output: [["@".repeat(5000), "*".repeat(5000)]],
Comment: "#",
skip: true
},
{
Name: "QuoteWithTrailingCRLF",
Input: '"foo"bar"\r\n',
Expand All @@ -394,28 +406,32 @@ x,,,
Output: [[`foo"bar`]],
LazyQuotes: true
},
// {
// Name: "DoubleQuoteWithTrailingCRLF",
// Input: '"foo""bar"\r\n',
// Output: [[`foo"bar`]]
// },
// {
// Name: "EvenQuotes",
// Input: `""""""""`,
// Output: [[`"""`]]
// },
// {
// Name: "OddQuotes",
// Input: `"""""""`,
// Error: true
// // Error:" &ParseError{StartLine: 1, Line: 1, Column: 7, Err: ErrQuote}",
// },
// {
// Name: "LazyOddQuotes",
// Input: `"""""""`,
// Output: [[`"""`]],
// LazyQuotes: true
// },
{
Name: "DoubleQuoteWithTrailingCRLF",
Input: '"foo""bar"\r\n',
Output: [[`foo"bar`]],
skip: true
},
{
Name: "EvenQuotes",
Input: `""""""""`,
Output: [[`"""`]],
skip: true
},
{
Name: "OddQuotes",
Input: `"""""""`,
Error: true,
// Error:" &ParseError{StartLine: 1, Line: 1, Column: 7, Err: ErrQuote}",
skip: true
},
{
Name: "LazyOddQuotes",
Input: `"""""""`,
Output: [[`"""`]],
LazyQuotes: true,
skip: true
},
{
Name: "BadComma1",
Comma: "\n",
Expand Down Expand Up @@ -450,6 +466,7 @@ x,,,
];
for (const t of testCases) {
Deno.test({
skip: !!t.skip,
name: `[CSV] ${t.Name}`,
async fn(): Promise<void> {
let comma = ",";
Expand Down
44 changes: 23 additions & 21 deletions std/examples/catj.ts
Expand Up @@ -81,28 +81,30 @@ function print(data: any): void {
}
}

const parsedArgs = parse(Deno.args);

if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
console.log("Usage: catj [-h|--help] [file...]");
console.log();
console.log("Examples:");
console.log();
console.log("// print file:\n catj file.json");
console.log();
console.log("// print multiple files:\n catj file1.json file2.json");
console.log();
console.log("// print from stdin:\n cat file.json | catj -");
}
if (import.meta.main) {
const parsedArgs = parse(Deno.args);

if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
console.log("Usage: catj [-h|--help] [file...]");
console.log();
console.log("Examples:");
console.log();
console.log("// print file:\n catj file.json");
console.log();
console.log("// print multiple files:\n catj file1.json file2.json");
console.log();
console.log("// print from stdin:\n cat file.json | catj -");
}

if (parsedArgs._[0] === "-") {
const contents = await Deno.readAll(Deno.stdin);
const json = JSON.parse(decoder.decode(contents));
print(json);
} else {
for (const fileName of parsedArgs._) {
const fileContents = await Deno.readFile(fileName);
const json = JSON.parse(decoder.decode(fileContents));
if (parsedArgs._[0] === "-") {
const contents = await Deno.readAll(Deno.stdin);
const json = JSON.parse(decoder.decode(contents));
print(json);
} else {
for (const fileName of parsedArgs._) {
const fileContents = await Deno.readFile(fileName.toString());
const json = JSON.parse(decoder.decode(fileContents));
print(json);
}
}
}

0 comments on commit 6471d4c

Please sign in to comment.