Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(csv): use assertions in example code snippets #4932

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions csv/_io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ function runeCount(s: string): number {
* @example Usage
* ```ts
* import { parse, ParseError } from "@std/csv/parse";
* import { assertEquals } from "@std/assert/assert-equals";
*
* try {
* parse(`a "word","b"`);
* } catch (error) {
* if (error instanceof ParseError) {
* console.error(error.message);
* assertEquals(error.message, `parse error on line 1, column 2: bare " in non-quoted-field`);
* }
* }
* ```
Expand All @@ -236,12 +237,13 @@ export class ParseError extends SyntaxError {
* @example Usage
* ```ts
* import { parse, ParseError } from "@std/csv/parse";
* import { assertEquals } from "@std/assert/assert-equals";
*
* try {
* parse(`a "word","b"`);
* } catch (error) {
* if (error instanceof ParseError) {
* console.error(error.startLine);
* assertEquals(error.startLine, 1);
* }
* }
* ```
Expand All @@ -253,12 +255,13 @@ export class ParseError extends SyntaxError {
* @example Usage
* ```ts
* import { parse, ParseError } from "@std/csv/parse";
* import { assertEquals } from "@std/assert/assert-equals";
*
* try {
* parse(`a "word","b"`);
* } catch (error) {
* if (error instanceof ParseError) {
* console.error(error.line);
* assertEquals(error.line, 1);
* }
* }
* ```
Expand All @@ -270,12 +273,13 @@ export class ParseError extends SyntaxError {
* @example Usage
* ```ts
* import { parse, ParseError } from "@std/csv/parse";
* import { assertEquals } from "@std/assert/assert-equals";
*
* try {
* parse(`a "word","b"`);
* } catch (error) {
* if (error instanceof ParseError) {
* console.error(error.column);
* assertEquals(error.column, 2);
* }
* }
* ```
Expand All @@ -286,10 +290,17 @@ export class ParseError extends SyntaxError {
* Constructs a new instance.
*
* @example Usage
* ```ts no-eval
* import { ParseError } from "@std/csv/parse";
* ```ts
* import { parse, ParseError } from "@std/csv/parse";
* import { assertEquals } from "@std/assert/assert-equals";
*
* throw new ParseError(1, 2, 3, "error message");
* try {
* parse(`a "word","b"`);
* } catch (error) {
* if (error instanceof ParseError) {
* assertEquals(error.message, `parse error on line 1, column 2: bare " in non-quoted-field`);
* }
* }
* ```
*
* @param start Line where the record starts
Expand Down
8 changes: 4 additions & 4 deletions csv/csv_parse_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export type RowType<T> = T extends undefined ? string[]
* {@link https://www.rfc-editor.org/rfc/rfc4180.html | RFC 4180}.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { CsvParseStream } from "@std/csv/csv-parse-stream";
*
* const source = ReadableStream.from([
Expand Down Expand Up @@ -98,7 +98,7 @@ export class CsvParseStream<
/** Construct a new instance.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { CsvParseStream } from "@std/csv/csv-parse-stream";
*
* const source = ReadableStream.from([
Expand Down Expand Up @@ -196,7 +196,7 @@ export class CsvParseStream<
* The instance's {@linkcode ReadableStream}.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { CsvParseStream } from "@std/csv/csv-parse-stream";
*
* const source = ReadableStream.from([
Expand All @@ -222,7 +222,7 @@ export class CsvParseStream<
* The instance's {@linkcode WritableStream}.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { CsvParseStream } from "@std/csv/csv-parse-stream";
*
* const source = ReadableStream.from([
Expand Down
4 changes: 2 additions & 2 deletions csv/csv_stringify_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface CsvStringifyStreamOptions {
* Convert each chunk to a CSV record.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { CsvStringifyStream } from "@std/csv/csv-stringify-stream";
*
* const path = await Deno.makeTempFile();
Expand Down Expand Up @@ -53,7 +53,7 @@ export class CsvStringifyStream<TOptions extends CsvStringifyStreamOptions>
* Construct a new instance.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { CsvStringifyStream } from "@std/csv/csv-stringify-stream";
*
* const path = await Deno.makeTempFile();
Expand Down
4 changes: 2 additions & 2 deletions csv/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*
* results in the fields
*
* ```ts
* ```ts no-assert
* [`normal string`, `quoted-field`]
* ```
*
Expand All @@ -55,7 +55,7 @@
*
* results in
*
* ```ts
* ```ts no-assert
* [`Multi-line
* field`, `comma is ,`]
* ```
Expand Down
2 changes: 1 addition & 1 deletion csv/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function normalizeColumn(column: Column): NormalizedColumn {
* Error thrown in {@linkcode stringify}.
*
* @example Usage
* ```ts
* ```ts no-assert
* import { stringify, StringifyError } from "@std/csv/stringify";
*
* try {
Expand Down