Skip to content

Commit c59d105

Browse files
committed
Add toml to existing snapshot and pretty print
1 parent a97d203 commit c59d105

3 files changed

+125
-6
lines changed

compiler-core/src/config.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,9 @@ allow_read = ["./database.sqlite"]
10401040
"#;
10411041

10421042
let config = toml::from_str::<PackageConfig>(&input).unwrap();
1043-
let json = serde_json::to_string(&config).unwrap();
1044-
insta::assert_snapshot!(json);
1043+
let json = serde_json::to_string_pretty(&config).unwrap();
1044+
let output = format!("--- GLEAM.TOML\n{input}\n\n--- EXPORTED JSON\n\n{json}");
1045+
insta::assert_snapshot!(output);
10451046
}
10461047

10471048
#[test]
@@ -1053,5 +1054,6 @@ version = "1.0.0"
10531054

10541055
let config = toml::from_str::<PackageConfig>(&input).unwrap();
10551056
let json = serde_json::to_string_pretty(&config).unwrap();
1056-
insta::assert_snapshot!(json);
1057+
let output = format!("--- GLEAM.TOML\n{input}\n\n--- EXPORTED JSON\n\n{json}");
1058+
insta::assert_snapshot!(output);
10571059
}

compiler-core/src/snapshots/gleam_core__config__barebones_package_config_to_json.snap

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
---
22
source: compiler-core/src/config.rs
3-
expression: json
3+
expression: output
44
---
5+
--- GLEAM.TOML
6+
7+
name = "my_project"
8+
version = "1.0.0"
9+
10+
11+
--- EXPORTED JSON
12+
513
{
614
"name": "my_project",
715
"version": "1.0.0",
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,114 @@
11
---
22
source: compiler-core/src/config.rs
3-
expression: json
3+
expression: output
44
---
5-
{"name":"my_project","version":"1.0.0","gleam":">= 0.30.0","licences":["Apache-2.0","MIT"],"description":"Pretty complex config","documentation":{"pages":[{"title":"My Page","path":"my-page.html","source":"./path/to/my-page.md"}]},"dependencies":{"my_other_project":{"path":"../my_other_project"},"gleam_stdlib":{"version":">= 0.18.0 and < 2.0.0"}},"dev-dependencies":{"gleeunit":{"version":">= 1.0.0 and < 2.0.0"}},"repository":{"type":"github","user":"example","repo":"my_dep"},"links":[{"title":"Home page","href":"https://example.com/"}],"erlang":{"application_start_module":"my_app/application","extra_applications":["inets","ssl"]},"javascript":{"typescript_declarations":true,"runtime":"nodejs","deno":{"allow_env":["DATABASE_URL"],"allow_net":["example.com:443"],"allow_ffi":true,"allow_read":["./database.sqlite"]}},"target":"erlang","internal_modules":["my_app/internal"]}
5+
--- GLEAM.TOML
6+
7+
name = "my_project"
8+
version = "1.0.0"
9+
licences = ["Apache-2.0", "MIT"]
10+
description = "Pretty complex config"
11+
target = "erlang"
12+
repository = { type = "github", user = "example", repo = "my_dep" }
13+
links = [{ title = "Home page", href = "https://example.com" }]
14+
internal_modules = ["my_app/internal"]
15+
gleam = ">= 0.30.0"
16+
17+
[dependencies]
18+
gleam_stdlib = ">= 0.18.0 and < 2.0.0"
19+
my_other_project = { path = "../my_other_project" }
20+
21+
[dev-dependencies]
22+
gleeunit = ">= 1.0.0 and < 2.0.0"
23+
24+
[documentation]
25+
pages = [{ title = "My Page", path = "my-page.html", source = "./path/to/my-page.md" }]
26+
27+
[erlang]
28+
application_start_module = "my_app/application"
29+
extra_applications = ["inets", "ssl"]
30+
31+
[javascript]
32+
typescript_declarations = true
33+
runtime = "node"
34+
35+
[javascript.deno]
36+
allow_all = false
37+
allow_ffi = true
38+
allow_env = ["DATABASE_URL"]
39+
allow_net = ["example.com:443"]
40+
allow_read = ["./database.sqlite"]
41+
42+
43+
--- EXPORTED JSON
44+
45+
{
46+
"name": "my_project",
47+
"version": "1.0.0",
48+
"gleam": ">= 0.30.0",
49+
"licences": [
50+
"Apache-2.0",
51+
"MIT"
52+
],
53+
"description": "Pretty complex config",
54+
"documentation": {
55+
"pages": [
56+
{
57+
"title": "My Page",
58+
"path": "my-page.html",
59+
"source": "./path/to/my-page.md"
60+
}
61+
]
62+
},
63+
"dependencies": {
64+
"my_other_project": {
65+
"path": "../my_other_project"
66+
},
67+
"gleam_stdlib": {
68+
"version": ">= 0.18.0 and < 2.0.0"
69+
}
70+
},
71+
"dev-dependencies": {
72+
"gleeunit": {
73+
"version": ">= 1.0.0 and < 2.0.0"
74+
}
75+
},
76+
"repository": {
77+
"type": "github",
78+
"user": "example",
79+
"repo": "my_dep"
80+
},
81+
"links": [
82+
{
83+
"title": "Home page",
84+
"href": "https://example.com/"
85+
}
86+
],
87+
"erlang": {
88+
"application_start_module": "my_app/application",
89+
"extra_applications": [
90+
"inets",
91+
"ssl"
92+
]
93+
},
94+
"javascript": {
95+
"typescript_declarations": true,
96+
"runtime": "nodejs",
97+
"deno": {
98+
"allow_env": [
99+
"DATABASE_URL"
100+
],
101+
"allow_net": [
102+
"example.com:443"
103+
],
104+
"allow_ffi": true,
105+
"allow_read": [
106+
"./database.sqlite"
107+
]
108+
}
109+
},
110+
"target": "erlang",
111+
"internal_modules": [
112+
"my_app/internal"
113+
]
114+
}

0 commit comments

Comments
 (0)