Skip to content

Commit b17ddf3

Browse files
Add tests for all import combinations
1 parent c25b266 commit b17ddf3

File tree

9 files changed

+135
-30
lines changed

9 files changed

+135
-30
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## Unreleased
9+
10+
### Added
11+
12+
- `ojs_define` support for any tabular data source, as defined by the `Tables.jl` `istable` interface [#285].
13+
- `ojs_define` support for rendering via `JSON3.jl`, in additional to the currently supported `JSON.jl` [#286].
14+
815
## [v0.15.0] - 2025-03-14
916

1017
### Added

src/QuartoNotebookWorker/Project.toml

-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,3 @@ QuartoNotebookWorkerRemoteREPL = "RemoteREPL"
4444
QuartoNotebookWorkerReviseExt = "Revise"
4545
QuartoNotebookWorkerSymPyCoreExt = "SymPyCore"
4646
QuartoNotebookWorkerTablesExt = "Tables"
47-
48-
[compat]
49-
Tables = "1"

test/examples/integrations/ojs_define.qmd

-21
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
[deps]
22
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
33
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
4+
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
5+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Both imported
3+
---
4+
5+
```{julia}
6+
import JSON
7+
import JSON3
8+
```
9+
10+
```{julia}
11+
ojs_define(; key = "value")
12+
```
13+
14+
```{julia}
15+
import Tables
16+
```
17+
18+
```{julia}
19+
ojs_define(; table = (; a = [1, 2, 3]))
20+
```
21+
22+
```{julia}
23+
import DataFrames
24+
```
25+
26+
```{julia}
27+
ojs_define(; df = DataFrames.DataFrame(; a = [1, 2, 3]))
28+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: JSON3 imported
3+
---
4+
5+
```{julia}
6+
import JSON3
7+
```
8+
9+
```{julia}
10+
ojs_define(; key = "value")
11+
```
12+
13+
```{julia}
14+
import Tables
15+
```
16+
17+
```{julia}
18+
ojs_define(; table = (; a = [1, 2, 3]))
19+
```
20+
21+
```{julia}
22+
import DataFrames
23+
```
24+
25+
```{julia}
26+
ojs_define(; df = DataFrames.DataFrame(; a = [1, 2, 3]))
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: JSON imported
3+
---
4+
5+
```{julia}
6+
import JSON
7+
```
8+
9+
```{julia}
10+
ojs_define(; key = "value")
11+
```
12+
13+
```{julia}
14+
import Tables
15+
```
16+
17+
```{julia}
18+
ojs_define(; table = (; a = [1, 2, 3]))
19+
```
20+
21+
```{julia}
22+
import DataFrames
23+
```
24+
25+
```{julia}
26+
ojs_define(; df = DataFrames.DataFrame(; a = [1, 2, 3]))
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: No imports
3+
---
4+
5+
```{julia}
6+
ojs_define(; key = "value")
7+
```
+37-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,43 @@
11
include("../../utilities/prelude.jl")
22

3-
test_example(joinpath(@__DIR__, "../../examples/integrations/ojs_define.qmd")) do json
3+
test_example(
4+
joinpath(@__DIR__, "../../examples/integrations/ojs_define/no_imports.qmd"),
5+
) do json
46
cells = json["cells"]
5-
67
cell = cells[2]
7-
@test contains(cell["outputs"][1]["data"]["text/plain"], "ojs_define")
8+
@test length(cell["outputs"]) == 1
9+
@test contains(cell["outputs"][1]["text"], "Please import either JSON.jl or JSON3.jl")
10+
end
11+
12+
for file in ("json", "json3", "both")
13+
test_example(
14+
joinpath(@__DIR__, "../../examples/integrations/ojs_define/$(file)_imported.qmd"),
15+
) do json
16+
cells = json["cells"]
17+
18+
function extract_json(str)
19+
str = replace(str, "<script type='ojs-define'>" => "")
20+
str = replace(str, "</script>" => "")
21+
return JSON3.read(str, Dict{String,Any})
22+
end
23+
24+
cell = cells[4]
25+
data = cell["outputs"][1]["data"]
26+
@test haskey(data, "text/html")
27+
@test contains(data["text/html"], "<script type='ojs-define'>")
28+
obj = extract_json(data["text/html"])
29+
@test obj["contents"][1] == Dict("name" => "key", "value" => "value")
830

9-
cell = cells[8]
10-
@test !isempty(cell["outputs"][1]["data"]["text/plain"])
11-
@test !isempty(cell["outputs"][1]["data"]["text/html"])
31+
for (nth, name) in (8 => "table", 12 => "df")
32+
cell = cells[nth]
33+
data = cell["outputs"][1]["data"]
34+
@test haskey(data, "text/html")
35+
@test contains(data["text/html"], "<script type='ojs-define'>")
36+
obj = extract_json(data["text/html"])
37+
@test obj["contents"][1]["name"] == name
38+
@test obj["contents"][1]["value"][1] == Dict("a" => 1)
39+
@test obj["contents"][1]["value"][2] == Dict("a" => 2)
40+
@test obj["contents"][1]["value"][3] == Dict("a" => 3)
41+
end
42+
end
1243
end

0 commit comments

Comments
 (0)