diff options
Diffstat (limited to 'encoding')
-rw-r--r-- | encoding/csv.ts | 9 | ||||
-rw-r--r-- | encoding/csv_test.ts | 31 | ||||
-rw-r--r-- | encoding/hex.ts | 18 | ||||
-rw-r--r-- | encoding/toml.ts | 5 | ||||
-rw-r--r-- | encoding/toml_test.ts | 3 |
5 files changed, 43 insertions, 23 deletions
diff --git a/encoding/csv.ts b/encoding/csv.ts index 1c4ae546b..ccbf4df77 100644 --- a/encoding/csv.ts +++ b/encoding/csv.ts @@ -21,11 +21,12 @@ export class ParseError extends Error { /** * @property comma - Character which separates values. Default: ',' * @property comment - Character to start a comment. Default: '#' - * @property trimLeadingSpace - Flag to trim the leading space of the value. Default: 'false' + * @property trimLeadingSpace - Flag to trim the leading space of the value. + * Default: 'false' * @property lazyQuotes - Allow unquoted quote in a quoted field or non double - * quoted quotes in quoted field Default: 'false' - * @property fieldsPerRecord - Enabling the check of fields for each row. If == 0 - * first row is used as referal for the number of fields. + * quoted quotes in quoted field Default: 'false' + * @property fieldsPerRecord - Enabling the check of fields for each row. + * If == 0, first row is used as referal for the number of fields. */ export interface ParseOptions { comma?: string; diff --git a/encoding/csv_test.ts b/encoding/csv_test.ts index a68b81dc8..88a3a24d7 100644 --- a/encoding/csv_test.ts +++ b/encoding/csv_test.ts @@ -129,7 +129,7 @@ const testCases = [ Name: "BadBareQuote", Input: `a "word","b"`, Error: ErrBareQuote - // Error: true //&ParseError{StartLine: 1, Line: 1, Column: 2, Err: ErrBareQuote}, + // &ParseError{StartLine: 1, Line: 1, Column: 2, Err: ErrBareQuote} }, { Name: "BadTrailingQuote", @@ -151,7 +151,7 @@ const testCases = [ { Name: "BadFieldCount1", Input: `a,b,c`, - // Error: &ParseError{StartLine: 1, Line: 1, Err: ErrFieldCount}, + // Error: &ParseError{StartLine: 1, Line: 1, Err: ErrFieldCount}, UseFieldsPerRecord: true, FieldsPerRecord: 2, Error: ErrFieldCount @@ -298,7 +298,11 @@ x,,, // { // 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", ""]] + // Output: [ + // ["field1", "field2\r"], + // ["\r\rfield1", "field2\r"], + // ["\r\r", ""] + // ] // }, { Name: "NonASCIICommaAndComment", @@ -339,13 +343,20 @@ x,,, // Name: "MultipleCRLF", // Input: "\r\n\r\n\r\n\r\n" // }, - // { - // // 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: '#', + /** + * 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: "QuoteWithTrailingCRLF", diff --git a/encoding/hex.ts b/encoding/hex.ts index 83c88ac78..d2e499cc7 100644 --- a/encoding/hex.ts +++ b/encoding/hex.ts @@ -32,7 +32,8 @@ function fromHexChar(byte: number): [number, boolean] { } /** - * EncodedLen returns the length of an encoding of n source bytes. Specifically, it returns n * 2. + * EncodedLen returns the length of an encoding of n source bytes. Specifically, + * it returns n * 2. * @param n */ export function encodedLen(n: number): number { @@ -73,8 +74,10 @@ export function encodeToString(src: Uint8Array): string { /** * Decode decodes `src` into `decodedLen(src.length)` bytes * returning the actual number of bytes written to `dst`. - * Decode expects that `src` contains only hexadecimal characters and that `src` has even length. - * If the input is malformed, Decode returns the number of bytes decoded before the error. + * Decode expects that `src` contains only hexadecimal characters and that `src` + * has even length. + * If the input is malformed, Decode returns the number of bytes decoded before + * the error. * @param dst * @param src */ @@ -110,7 +113,8 @@ export function decode( } /** - * DecodedLen returns the length of a decoding of `x` source bytes. Specifically, it returns `x / 2`. + * DecodedLen returns the length of a decoding of `x` source bytes. + * Specifically, it returns `x / 2`. * @param x */ export function decodedLen(x: number): number { @@ -119,14 +123,16 @@ export function decodedLen(x: number): number { /** * DecodeString returns the bytes represented by the hexadecimal string `s`. - * DecodeString expects that src contains only hexadecimal characters and that src has even length. + * DecodeString expects that src contains only hexadecimal characters and that + * src has even length. * If the input is malformed, DecodeString will throws an error. * @param s the `string` need to decode to `Uint8Array` */ export function decodeString(s: string): Uint8Array { const src = new TextEncoder().encode(s); // We can use the source slice itself as the destination - // because the decode loop increments by one and then the 'seen' byte is not used anymore. + // because the decode loop increments by one and then the 'seen' byte is not + // used anymore. const [n, err] = decode(src, src); if (err) { diff --git a/encoding/toml.ts b/encoding/toml.ts index e93903fae..8a53a8300 100644 --- a/encoding/toml.ts +++ b/encoding/toml.ts @@ -507,8 +507,9 @@ class Dumper { const min = dtPad(value.getUTCMinutes().toString()); const s = dtPad(value.getUTCSeconds().toString()); const ms = dtPad(value.getUTCMilliseconds().toString(), 3); - const fmtDate = `${value.getUTCFullYear()}-${m}-${d}T${h}:${min}:${s}.${ms}`; - return `${this._declaration(title)}${fmtDate}`; + // formated date + const fData = `${value.getUTCFullYear()}-${m}-${d}T${h}:${min}:${s}.${ms}`; + return `${this._declaration(title)}${fData}`; } _format(): string[] { const rDeclaration = /(.*)\s=/; diff --git a/encoding/toml_test.ts b/encoding/toml_test.ts index 13d4f0b14..28a620453 100644 --- a/encoding/toml_test.ts +++ b/encoding/toml_test.ts @@ -29,7 +29,8 @@ test({ str5: "The quick brown\nfox jumps over\nthe lazy dog.", str6: "The quick brown\nfox jumps over\nthe lazy dog.", lines: - "The first newline is\ntrimmed in raw strings.\n All other whitespace\n is preserved." + "The first newline is\ntrimmed in raw strings.\n All other " + + "whitespace\n is preserved." } }; const actual = parseFile(path.join(testFilesDir, "string.toml")); |