Skip to content

Commit

Permalink
full coverage highlighting with toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
bcpeinhardt committed Nov 28, 2024
1 parent d3f4f4f commit a8a379f
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 23 deletions.
119 changes: 99 additions & 20 deletions priv/static/squared_away.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7689,11 +7689,12 @@ function uploadFile() {

// build/dev/javascript/squared_away/squared_away.mjs
var Model2 = class extends CustomType {
constructor(holding_shift, grid_width, grid_height, display_formulas, active_cell, src_grid, type_checked_grid, value_grid, errors_to_display) {
constructor(holding_shift, grid_width, grid_height, show_test_coverage, display_formulas, active_cell, src_grid, type_checked_grid, value_grid, errors_to_display) {
super();
this.holding_shift = holding_shift;
this.grid_width = grid_width;
this.grid_height = grid_height;
this.show_test_coverage = show_test_coverage;
this.display_formulas = display_formulas;
this.active_cell = active_cell;
this.src_grid = src_grid;
Expand All @@ -7702,6 +7703,12 @@ var Model2 = class extends CustomType {
this.errors_to_display = errors_to_display;
}
};
var UserToggledShowTestCoverage = class extends CustomType {
constructor(to2) {
super();
this.to = to2;
}
};
var UserToggledFormulaMode = class extends CustomType {
constructor(to2) {
super();
Expand Down Expand Up @@ -7900,6 +7907,7 @@ function init2(_) {
initial_grid_width,
initial_grid_height,
false,
false,
new None(),
src_grid,
type_checked_grid,
Expand All @@ -7924,6 +7932,12 @@ function update(model, msg) {
model.withFields({ display_formulas }),
none()
];
} else if (msg instanceof UserToggledShowTestCoverage) {
let show_test_coverage = msg.to;
return [
model.withFields({ show_test_coverage }),
none()
];
} else if (msg instanceof UserFocusedOnCell) {
let key = msg.key;
return [model.withFields({ active_cell: new Some(key) }), none()];
Expand Down Expand Up @@ -7978,7 +7992,7 @@ function update(model, msg) {
throw makeError(
"let_assert",
"squared_away",
239,
245,
"",
"Pattern match failed, no pattern matched the value.",
{ value: maybe_expr }
Expand All @@ -7993,7 +8007,7 @@ function update(model, msg) {
throw makeError(
"let_assert",
"squared_away",
247,
253,
"",
"Pattern match failed, no pattern matched the value.",
{ value: $ }
Expand All @@ -8020,7 +8034,7 @@ function update(model, msg) {
throw makeError(
"let_assert",
"squared_away",
267,
273,
"",
"Pattern match failed, no pattern matched the value.",
{ value: $1 }
Expand Down Expand Up @@ -8079,7 +8093,7 @@ function update(model, msg) {
throw makeError(
"let_assert",
"squared_away",
307,
313,
"",
"Pattern match failed, no pattern matched the value.",
{ value: maybe_expr }
Expand All @@ -8094,7 +8108,7 @@ function update(model, msg) {
throw makeError(
"let_assert",
"squared_away",
312,
318,
"",
"Pattern match failed, no pattern matched the value.",
{ value: $ }
Expand All @@ -8121,7 +8135,7 @@ function update(model, msg) {
throw makeError(
"let_assert",
"squared_away",
331,
337,
"",
"Pattern match failed, no pattern matched the value.",
{ value: $1 }
Expand Down Expand Up @@ -8421,29 +8435,30 @@ function view(model) {
}
})();
let $2 = (() => {
let $12 = model.active_cell;
if ($12 instanceof None) {
let $12 = model.show_test_coverage;
let $22 = model.active_cell;
if (!$12 && $22 instanceof None) {
return colors;
} else {
let active_cell = $12[0];
let $22 = get4(model.type_checked_grid, active_cell);
if (!$22.isOk()) {
} else if (!$12 && $22 instanceof Some) {
let active_cell = $22[0];
let $3 = get4(model.type_checked_grid, active_cell);
if (!$3.isOk()) {
return colors;
} else {
let typed_expr = $22[0];
let $3 = typed_expr.type_;
if ($3 instanceof TTestResult) {
let $4 = get4(model.value_grid, active_cell);
if ($4.isOk() && $4[0] instanceof TestPass) {
let $5 = (() => {
let typed_expr = $3[0];
let $4 = typed_expr.type_;
if ($4 instanceof TTestResult) {
let $5 = get4(model.value_grid, active_cell);
if ($5.isOk() && $5[0] instanceof TestPass) {
let $6 = (() => {
let _pipe$32 = dependency_list(
model.type_checked_grid,
typed_expr,
toList([])
);
return contains(_pipe$32, key);
})();
if (!$5) {
if (!$6) {
return colors;
} else {
return ["#006400", "#e6ffe6"];
Expand All @@ -8455,6 +8470,51 @@ function view(model) {
return colors;
}
}
} else {
let deps = (() => {
let _pipe$32 = model.type_checked_grid;
let _pipe$42 = to_list3(_pipe$32);
let _pipe$5 = filter_map(
_pipe$42,
(g) => {
let k = g[0];
let mte = g[1];
if (!mte.isOk()) {
return new Error(void 0);
} else {
let te = mte[0];
let $32 = te.type_;
if ($32 instanceof TTestResult) {
let $4 = get4(model.value_grid, k);
if ($4.isOk() && $4[0] instanceof TestPass) {
return new Ok(te);
} else {
return new Error(void 0);
}
} else {
return new Error(void 0);
}
}
}
);
let _pipe$6 = map2(
_pipe$5,
(_capture) => {
return dependency_list(
model.type_checked_grid,
_capture,
toList([])
);
}
);
return flatten2(_pipe$6);
})();
let $3 = contains(deps, key);
if (!$3) {
return colors;
} else {
return ["#006400", "#e6ffe6"];
}
}
})();
let color = $2[0];
Expand Down Expand Up @@ -8549,6 +8609,21 @@ function view(model) {
toList([for$("formula_mode")]),
t("Show formulas")
);
let show_test_coverage_toggle = input(
toList([
type_("checkbox"),
id("test_coverage"),
on_check(
(var0) => {
return new UserToggledShowTestCoverage(var0);
}
)
])
);
let show_test_coverage_toggle_label = label(
toList([for$("test_coverage")]),
t("Show test coverage")
);
let save_button = button(
toList([on_click(new UserClickedSaveBtn())]),
t("Save")
Expand Down Expand Up @@ -8617,6 +8692,10 @@ function view(model) {
toList([class$("menu-item")]),
toList([formula_mode_toggle, formula_mode_toggle_label])
),
div(
toList([class$("menu-item")]),
toList([show_test_coverage_toggle, show_test_coverage_toggle_label])
),
div(
toList([class$("menu-item")]),
toList([load_button])
Expand Down
62 changes: 59 additions & 3 deletions src/squared_away.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Model {
holding_shift: Bool,
grid_width: Int,
grid_height: Int,
show_test_coverage: Bool,
display_formulas: Bool,
active_cell: Option(grid.GridKey),
src_grid: grid.Grid(String),
Expand Down Expand Up @@ -86,6 +87,7 @@ fn init(_flags) -> #(Model, effect.Effect(Msg)) {
grid_width: initial_grid_width,
grid_height: initial_grid_height,
display_formulas: False,
show_test_coverage: False,
active_cell: None,
src_grid:,
value_grid:,
Expand Down Expand Up @@ -136,6 +138,7 @@ fn recalculate_col_width(model: Model, col: Int) -> Int {
}

type Msg {
UserToggledShowTestCoverage(to: Bool)
UserToggledFormulaMode(to: Bool)
UserSetCellValue(key: grid.GridKey, val: String)
UserFocusedOnCell(key: grid.GridKey)
Expand Down Expand Up @@ -199,6 +202,9 @@ fn update(model: Model, msg: Msg) -> #(Model, effect.Effect(Msg)) {
UserToggledFormulaMode(display_formulas) -> {
#(Model(..model, display_formulas:), effect.none())
}
UserToggledShowTestCoverage(show_test_coverage) -> {
#(Model(..model, show_test_coverage:), effect.none())
}
UserFocusedOnCell(key) -> {
#(Model(..model, active_cell: Some(key)), effect.none())
}
Expand Down Expand Up @@ -483,9 +489,12 @@ fn view(model: Model) -> element.Element(Msg) {
}
}

let #(color, background_color) = case model.active_cell {
None -> colors
Some(active_cell) ->
let #(color, background_color) = case
model.show_test_coverage,
model.active_cell
{
False, None -> colors
False, Some(active_cell) ->
case grid.get(model.type_checked_grid, active_cell) {
Error(_) -> colors
Ok(typed_expr) ->
Expand All @@ -509,6 +518,39 @@ fn view(model: Model) -> element.Element(Msg) {
_ -> colors
}
}
True, _ -> {
// In show test coverage mode, we need to check the dependency lists of *all*
// passing tests
let deps =
model.type_checked_grid
|> grid.to_list
|> list.filter_map(fn(g) {
let #(k, mte) = g
case mte {
Error(_) -> Error(Nil)
Ok(te) ->
case te.type_ {
typ.TTestResult ->
case grid.get(model.value_grid, k) {
Ok(value.TestPass) -> Ok(te)
_ -> Error(Nil)
}
_ -> Error(Nil)
}
}
})
|> list.map(squared_away_lang.dependency_list(
model.type_checked_grid,
_,
[],
))
|> list.flatten

case list.contains(deps, key) {
False -> colors
True -> #("#006400", "#e6ffe6")
}
}
}

let col_width =
Expand Down Expand Up @@ -572,6 +614,16 @@ fn view(model: Model) -> element.Element(Msg) {
let formula_mode_toggle_label =
html.label([attribute.for("formula_mode")], t("Show formulas"))

let show_test_coverage_toggle =
html.input([
attribute.type_("checkbox"),
attribute.id("test_coverage"),
event.on_check(UserToggledShowTestCoverage),
])

let show_test_coverage_toggle_label =
html.label([attribute.for("test_coverage")], t("Show test coverage"))

let save_button = html.button([event.on_click(UserClickedSaveBtn)], t("Save"))
let load_button =
html.input([
Expand Down Expand Up @@ -616,6 +668,10 @@ fn view(model: Model) -> element.Element(Msg) {
formula_mode_toggle,
formula_mode_toggle_label,
]),
html.div([attribute.class("menu-item")], [
show_test_coverage_toggle,
show_test_coverage_toggle_label,
]),
html.div([attribute.class("menu-item")], [load_button]),
html.div([attribute.class("menu-item")], [save_button]),
html.div([attribute.class("menu-item")], [test_count_html]),
Expand Down

0 comments on commit a8a379f

Please sign in to comment.