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

execution-plan: Use snapshot tests for program memory #35

Merged
merged 1 commit into from
Dec 18, 2023
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
104 changes: 104 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions execution-plan/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ description = "A DSL for composing KittyCAD API queries"

[dependencies]
bytes = "1.5"
insta = "1.34.0"
kittycad = { version = "0.2.44", features = ["requests"] }
kittycad-modeling-cmds = { path = "../modeling-cmds" }
kittycad-modeling-session = { path = "../modeling-session" }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: execution-plan/src/tests.rs
expression: debug_dump_memory(&mem)
---
┌───────┬──────────┬──────────────────────────────────────┐
│ index │ val_type │ value │
├───────┼──────────┼──────────────────────────────────────┤
│ 0 │ Uuid │ 4cd175a3-e313-4c91-b624-368bea3c0483 │
│ 2 │ Float │ 40 │
│ 3 │ Bool │ true │
│ 4 │ String │ png │
│ 6 │ Float │ -20 │
│ 7 │ Float │ -20 │
│ 8 │ Float │ -20 │
│ 9 │ String │ line │
│ 10 │ Float │ 20 │
│ 11 │ Float │ -20 │
│ 12 │ Float │ -20 │
│ 13 │ Bool │ false │
│ 14 │ String │ line │
│ 15 │ Float │ 20 │
│ 16 │ Float │ 20 │
│ 17 │ Float │ -20 │
│ 18 │ Bool │ false │
│ 19 │ String │ line │
│ 20 │ Float │ -20 │
│ 21 │ Float │ 20 │
│ 22 │ Float │ -20 │
│ 23 │ Bool │ false │
│ 24 │ String │ line │
│ 25 │ Float │ -20 │
│ 26 │ Float │ -20 │
│ 27 │ Float │ -20 │
│ 28 │ Bool │ false │
│ 99 │ String │ TAKE_SNAPSHOT │
│ 100 │ Bytes │ length 129068 │
└───────┴──────────┴──────────────────────────────────────┘
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
source: execution-plan/src/tests.rs
expression: debug_dump_memory(&mem)
---
┌───────┬──────────┬──────────────────────────────────────┐
│ index │ val_type │ value │
├───────┼──────────┼──────────────────────────────────────┤
│ 0 │ Uuid │ 4cd175a3-e313-4c91-b624-368bea3c0483 │
│ 2 │ Float │ 40 │
│ 3 │ Bool │ true │
│ 4 │ String │ png │
│ 6 │ Float │ -20 │
│ 7 │ Float │ -20 │
│ 8 │ Float │ -20 │
│ 9 │ String │ line │
│ 10 │ Float │ 20 │
│ 11 │ Float │ -20 │
│ 12 │ Float │ -20 │
│ 13 │ Bool │ false │
│ 14 │ String │ line │
│ 15 │ Float │ 20 │
│ 16 │ Float │ 20 │
│ 17 │ Float │ -20 │
│ 18 │ Bool │ false │
│ 19 │ String │ line │
│ 20 │ Float │ -20 │
│ 21 │ Float │ 20 │
│ 22 │ Float │ -20 │
│ 23 │ Bool │ false │
│ 24 │ String │ line │
│ 25 │ Float │ -20 │
│ 26 │ Float │ -20 │
│ 27 │ Float │ -20 │
│ 28 │ Bool │ false │
└───────┴──────────┴──────────────────────────────────────┘
11 changes: 7 additions & 4 deletions execution-plan/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::env;

use insta::assert_snapshot;
use kittycad_modeling_cmds::shared::{PathSegment, Point3d};
use kittycad_modeling_session::{Session, SessionBuilder};
use tabled::{settings::Style, Table};
Expand Down Expand Up @@ -133,7 +134,7 @@ async fn api_call_draw_cube() {

// Define primitives, load them into memory.
let path_id_addr = Address(0);
let path = new_id();
let path = ModelingCmdId(Uuid::parse_str("4cd175a3-e313-4c91-b624-368bea3c0483").unwrap());
let cube_height_addr = Address(2);
let cube_height = Primitive::from(CUBE_WIDTH * 2.0);
let cap_addr = Address(3);
Expand Down Expand Up @@ -192,6 +193,7 @@ async fn api_call_draw_cube() {
let size = mem.set_composite(*addr, segment);
segment_addrs.push(Address(addr.0 + size));
}
assert_snapshot!("cube_memory_before", debug_dump_memory(&mem));

// Run the plan!
execute(
Expand Down Expand Up @@ -260,7 +262,7 @@ async fn api_call_draw_cube() {
.unwrap();

// Program executed successfully!
debug_dump_memory(&mem);
assert_snapshot!("cube_memory_after", debug_dump_memory(&mem));

// The image output was set to addr 99.
// Outputs are two addresses long, addr 99 will store the data format (TAKE_SNAPSHOT)
Expand All @@ -279,7 +281,8 @@ async fn api_call_draw_cube() {
twenty_twenty::assert_image("tests/outputs/cube.png", &img, 0.9999);
}

fn debug_dump_memory(mem: &Memory) {
/// Return a nicely-formatted table of memory.
fn debug_dump_memory(mem: &Memory) -> String {
impl Primitive {
fn pretty_print(&self) -> (&'static str, String) {
match self {
Expand Down Expand Up @@ -316,7 +319,7 @@ fn debug_dump_memory(mem: &Memory) {
}
})
.collect();
eprintln!("{}", Table::new(table_data).with(Style::sharp()));
Table::new(table_data).with(Style::sharp()).to_string()
}

fn new_id() -> ModelingCmdId {
Expand Down
Loading