Skip to content

Commit 7fbda2f

Browse files
committed
Enable doctests, reorganize end-to-end tests
Signed-off-by: Andrew Stein <steinlink@gmail.com>
1 parent 7eb6b89 commit 7fbda2f

16 files changed

Lines changed: 1052 additions & 687 deletions

File tree

rust/perspective-client/src/rust/client.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,6 @@ impl ReconnectCallback {
206206
/// An instance of a [`Client`] is a connection to a single
207207
/// `perspective_server::Server`, whether locally in-memory or remote over some
208208
/// transport like a WebSocket.
209-
///
210-
/// # Examples
211-
///
212-
/// Create a `perspective_server::Server` and a synchronous [`Client`] via the
213-
/// `perspective` crate:
214-
///
215-
/// ```rust
216-
/// use perspective::LocalClient;
217-
/// use perspective::server::Server;
218-
///
219-
/// let server = Server::default();
220-
/// let client = perspective::LocalClient::new(&server);
221-
/// ```
222209
#[derive(Clone)]
223210
pub struct Client {
224211
name: Arc<String>,
@@ -530,10 +517,13 @@ impl Client {
530517
///
531518
/// Load a CSV from a `String`:
532519
///
533-
/// ```rust
520+
/// ```no_run
521+
/// # use perspective_client::*;
522+
/// # async fn run(client: Client) -> Result<(), Box<dyn std::error::Error>> {
534523
/// let opts = TableInitOptions::default();
535524
/// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
536525
/// let table = client.table(data, opts).await?;
526+
/// # Ok(()) }
537527
/// ```
538528
pub async fn table(&self, input: TableData, options: TableInitOptions) -> ClientResult<Table> {
539529
let entity_id = match options.name.clone() {
@@ -657,9 +647,13 @@ impl Client {
657647
///
658648
/// # Examples
659649
///
660-
/// ```rust
661-
/// let tables = client.open_table("table_one").await;
662-
/// ```
650+
/// ```no_run
651+
/// # use perspective_client::Client;
652+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
653+
/// # let client: Client = todo!();
654+
/// let table = client.open_table("table_one".to_owned()).await?;
655+
/// # Ok(()) }
656+
/// ```
663657
pub async fn open_table(&self, entity_id: String) -> ClientResult<Table> {
664658
let infos = self.get_table_infos().await?;
665659

@@ -689,8 +683,12 @@ impl Client {
689683
///
690684
/// # Examples
691685
///
692-
/// ```rust
693-
/// let tables = client.get_hosted_table_names().await;
686+
/// ```no_run
687+
/// # use perspective_client::Client;
688+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
689+
/// # let client: Client = todo!();
690+
/// let tables = client.get_hosted_table_names().await?;
691+
/// # Ok(()) }
694692
/// ```
695693
pub async fn get_hosted_table_names(&self) -> ClientResult<Vec<String>> {
696694
let msg = Request {

rust/perspective-client/src/rust/table.rs

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,18 @@ impl Table {
242242
///
243243
/// # Examples
244244
///
245-
/// ```rust
245+
/// ```no_run
246+
/// # use perspective_client::{Client, TableData, TableInitOptions, UpdateData};
247+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
248+
/// # let client: Client = todo!();
246249
/// let options = TableInitOptions {
247250
/// index: Some("x".to_string()),
248-
/// ..default()
251+
/// ..TableInitOptions::default()
249252
/// };
250-
/// let table = client.table("x,y\n1,2\n3,4", options).await;
251-
/// let index = table.get_index()
253+
/// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
254+
/// let table = client.table(data, options).await?;
255+
/// let index = table.get_index();
256+
/// # Ok(()) }
252257
/// ```
253258
pub fn get_index(&self) -> Option<String> {
254259
self.options.index.as_ref().map(|index| index.to_owned())
@@ -294,14 +299,18 @@ impl Table {
294299
///
295300
/// # Examples
296301
///
297-
/// ```rust
302+
/// ```no_run
303+
/// # use perspective_client::{Client, DeleteOptions, TableData, TableInitOptions, UpdateData};
304+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
305+
/// # let client: Client = todo!();
298306
/// let opts = TableInitOptions::default();
299307
/// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
300308
/// let table = client.table(data, opts).await?;
301309
///
302310
/// // ...
303311
///
304312
/// table.delete(DeleteOptions::default()).await?;
313+
/// # Ok(()) }
305314
/// ```
306315
pub async fn delete(&self, options: DeleteOptions) -> ClientResult<()> {
307316
let msg = self.client_message(ClientReq::TableDeleteReq(TableDeleteReq {
@@ -319,8 +328,12 @@ impl Table {
319328
///
320329
/// # Examples
321330
///
322-
/// ```rust
323-
/// let columns = table.columns().await;
331+
/// ```no_run
332+
/// # use perspective_client::Table;
333+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
334+
/// # let table: Table = todo!();
335+
/// let columns = table.columns().await?;
336+
/// # Ok(()) }
324337
/// ```
325338
pub async fn columns(&self) -> ClientResult<Vec<String>> {
326339
let msg = self.client_message(ClientReq::TableSchemaReq(TableSchemaReq {}));
@@ -430,8 +443,14 @@ impl Table {
430443
///
431444
/// # Examples
432445
///
433-
/// ```rust
434-
/// table.remove(UpdateData::Csv("index\n1\n2\n3")).await?;
446+
/// ```no_run
447+
/// # use perspective_client::{Table, UpdateData};
448+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
449+
/// # let table: Table = todo!();
450+
/// table
451+
/// .remove(UpdateData::Csv("index\n1\n2\n3".into()))
452+
/// .await?;
453+
/// # Ok(()) }
435454
/// ```
436455
pub async fn remove(&self, input: UpdateData) -> ClientResult<()> {
437456
let msg = self.client_message(ClientReq::TableRemoveReq(TableRemoveReq {
@@ -457,10 +476,13 @@ impl Table {
457476
///
458477
/// # Examples
459478
///
460-
/// ```rust
479+
/// ```no_run
480+
/// # use perspective_client::{Table, UpdateData};
481+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
482+
/// # let table: Table = todo!();
461483
/// let data = UpdateData::Csv("x,y\n1,2".into());
462-
/// let opts = UpdateOptions::default();
463-
/// table.replace(data, opts).await?;
484+
/// table.replace(data).await?;
485+
/// # Ok(()) }
464486
/// ```
465487
pub async fn replace(&self, input: UpdateData) -> ClientResult<()> {
466488
let msg = self.client_message(ClientReq::TableReplaceReq(TableReplaceReq {
@@ -491,11 +513,15 @@ impl Table {
491513
///
492514
/// # Examples
493515
///
494-
/// ```rust
516+
/// ```no_run
517+
/// # use perspective_client::{Table, UpdateData, UpdateOptions};
518+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
519+
/// # let table: Table = todo!();
495520
/// let data = UpdateData::Csv("x,y\n1,2".into());
496521
/// let opts = UpdateOptions::default();
497522
/// table.update(data, opts).await?;
498-
/// ```
523+
/// # Ok(()) }
524+
/// ```
499525
pub async fn update(&self, input: UpdateData, options: UpdateOptions) -> ClientResult<()> {
500526
let msg = self.client_message(ClientReq::TableUpdateReq(TableUpdateReq {
501527
data: Some(input.into()),
@@ -538,8 +564,12 @@ impl Table {
538564
///
539565
/// # Examples
540566
///
541-
/// ```rust
542-
/// use crate::config::*;
567+
/// ```no_run
568+
/// # use std::collections::HashMap;
569+
/// # use perspective_client::Table;
570+
/// # use perspective_client::config::*;
571+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
572+
/// # let table: Table = todo!();
543573
/// let view = table
544574
/// .view(Some(ViewConfigUpdate {
545575
/// columns: Some(vec![Some("Sales".into())]),
@@ -552,6 +582,7 @@ impl Table {
552582
/// ..ViewConfigUpdate::default()
553583
/// }))
554584
/// .await?;
585+
/// # Ok(()) }
555586
/// ```
556587
pub async fn view(&self, config: Option<ViewConfigUpdate>) -> ClientResult<View> {
557588
let view_name = randid();

rust/perspective-client/src/rust/utils/clone.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
/// .. }` or `move async { .. }`, but for clone semantics. `clone!()` works
1616
/// with symbols as well as properties and methods, using the last symbol name
1717
/// in the method chain, or an alias via `x = ...` syntax.
18-
///
19-
/// # Examples
20-
///
21-
/// ```
22-
/// clone!(my_struct.option_method(), alias = my_struct.prop1.my_rc);
23-
/// println!("These bindings exist: {:?} {:?}", option_method, alias);
2418
/// ```
2519
#[doc(hidden)]
2620
#[macro_export]
@@ -41,7 +35,6 @@ macro_rules! clone {
4135
let mut $binder = $($orig)*.clone();
4236
};
4337

44-
4538
(impl @expand { $($orig:tt)* } { $($binder:tt)* } $i:tt) => {
4639
$crate::clone!(impl @bind $i { $($orig)* $i } { $($binder)* });
4740
};

rust/perspective-client/src/rust/view.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,26 @@ impl Deref for OnUpdateData {
168168
///
169169
/// # Examples
170170
///
171-
/// ```rust
171+
/// ```no_run
172+
/// # use perspective_client::{Client, TableData, TableInitOptions, UpdateData, ViewWindow};
173+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
174+
/// # let client: Client = todo!();
172175
/// let opts = TableInitOptions::default();
173176
/// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
174177
/// let table = client.table(data, opts).await?;
175178
///
176179
/// let view = table.view(None).await?;
177-
/// let arrow = view.to_arrow().await?;
180+
/// let arrow = view.to_arrow(ViewWindow::default()).await?;
178181
/// view.delete().await?;
182+
/// # Ok(()) }
179183
/// ```
180184
///
181-
/// ```rust
182-
/// use crate::config::*;
185+
/// ```no_run
186+
/// # use std::collections::HashMap;
187+
/// # use perspective_client::Table;
188+
/// # use perspective_client::config::*;
189+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
190+
/// # let table: Table = todo!();
183191
/// let view = table
184192
/// .view(Some(ViewConfigUpdate {
185193
/// columns: Some(vec![Some("Sales".into())]),
@@ -192,28 +200,39 @@ impl Deref for OnUpdateData {
192200
/// ..ViewConfigUpdate::default()
193201
/// }))
194202
/// .await?;
203+
/// # Ok(()) }
195204
/// ```
196205
///
197206
/// Group By
198207
///
199-
/// ```rust
208+
/// ```no_run
209+
/// # use perspective_client::Table;
210+
/// # use perspective_client::config::*;
211+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
212+
/// # let table: Table = todo!();
200213
/// let view = table
201214
/// .view(Some(ViewConfigUpdate {
202215
/// group_by: Some(vec!["a".into(), "c".into()]),
203216
/// ..ViewConfigUpdate::default()
204217
/// }))
205218
/// .await?;
219+
/// # Ok(()) }
206220
/// ```
207221
///
208222
/// Split By
209223
///
210-
/// ```rust
224+
/// ```no_run
225+
/// # use perspective_client::Table;
226+
/// # use perspective_client::config::*;
227+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
228+
/// # let table: Table = todo!();
211229
/// let view = table
212230
/// .view(Some(ViewConfigUpdate {
213231
/// split_by: Some(vec!["a".into(), "c".into()]),
214232
/// ..ViewConfigUpdate::default()
215233
/// }))
216234
/// .await?;
235+
/// # Ok(()) }
217236
/// ```
218237
///
219238
/// In Javascript, a [`Table`] can be constructed on a [`Table::view`] instance,
@@ -223,13 +242,18 @@ impl Deref for OnUpdateData {
223242
/// [Client/Server Replicated](server.md#clientserver-replicated) design, by
224243
/// serializing the `View` to an arrow and setting up an `on_update` callback.
225244
///
226-
/// ```rust
245+
/// ```no_run
246+
/// # use perspective_client::{Client, TableData, TableInitOptions, UpdateData, UpdateOptions};
247+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
248+
/// # let client: Client = todo!();
227249
/// let opts = TableInitOptions::default();
228250
/// let data = TableData::Update(UpdateData::Csv("x,y\n1,2\n3,4".into()));
229-
/// let table = client.table(data, opts).await?;
251+
/// let table = client.table(data, opts.clone()).await?;
230252
/// let view = table.view(None).await?;
231-
/// let table2 = client.table(TableData::View(view)).await?;
232-
/// table.update(data).await?;
253+
/// let table2 = client.table(TableData::View(view), opts).await?;
254+
/// let more = UpdateData::Csv("x,y\n5,6".into());
255+
/// table.update(more, UpdateOptions::default()).await?;
256+
/// # Ok(()) }
233257
/// ```
234258
#[derive(Clone, Debug)]
235259
pub struct View {
@@ -524,10 +548,14 @@ impl View {
524548
///
525549
/// # Examples
526550
///
527-
/// ```rust
551+
/// ```no_run
552+
/// # use perspective_client::{OnUpdateOptions, View};
553+
/// # async fn run() -> Result<(), Box<dyn std::error::Error>> {
554+
/// # let view: View = todo!();
528555
/// let callback = |_| async { print!("Updated!") };
529556
/// let cid = view.on_update(callback, OnUpdateOptions::default()).await?;
530557
/// view.remove_update(cid).await?;
558+
/// # Ok(()) }
531559
/// ```
532560
pub async fn remove_update(&self, update_id: u32) -> ClientResult<()> {
533561
let msg = self.client_message(ClientReq::ViewRemoveOnUpdateReq(ViewRemoveOnUpdateReq {

rust/perspective-js/src/ts/perspective.node.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ export async function cwd_static_file_handler(
148148
"Access-Control-Allow-Origin": "*",
149149
});
150150
if (extname === ".arrow" || extname === ".feather") {
151-
response.end(content, "utf-8");
151+
response.end(content, "utf8");
152152
} else {
153-
response.end(content);
153+
response.end(content, "utf8");
154154
}
155155

156156
return;

0 commit comments

Comments
 (0)