Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ decondenser-wasm/src/bindings.rs

# Files where logs can be stored and not committed
*.log
!decondenser/tests/integration/formatting/*.log

# Special name pattern for dirty experimentation that should not be committed
*dbg*
Expand Down
6 changes: 4 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}/decondenser-vscode"
"--extensionDevelopmentPath=${workspaceFolder}/decondenser-vscode",
"${workspaceFolder}/decondenser",
"${workspaceFolder}/decondenser/tests/integration/formatting/001-rust.log"
],
"outFiles": ["${workspaceFolder}/decondenser-vscode/dist/**/*.js"],
"preLaunchTask": "${defaultBuildTask}"
Expand All @@ -21,7 +23,7 @@
},
"args": ["build", "-p", "decondenser-cli"]
},
"args": ["--input=dbg.log", "--output=dbg.out.log"]
"args": ["fmt", "--input=dbg.log", "--output=dbg.out.log"]
}
]
}
2 changes: 2 additions & 0 deletions decondenser-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ impl wit::GuestDecondenser for Decondenser {
}

fn format(&self, input: String) -> String {
eprintln!("EPRINTLN INVOKED");
println!("PRINTLN INVOKED");
// Delegate to the inherent method of the same name. No, it's not an
// unconditional recursion, the compiler would report it otherwise .
self.format(&input)
Expand Down
4 changes: 2 additions & 2 deletions decondenser/src/formatting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ impl<'i> FormattingCtx<'_, 'i> {
fn on_group(&mut self, leading_space: Option<&'i str>, group: &'i parsing::l2::Group<'i>) {
let config = group.config;

self.fmt.begin(group.config.break_style.0);

let is_empty_group = group
.content
.iter()
Expand All @@ -108,6 +106,8 @@ impl<'i> FormattingCtx<'_, 'i> {
return;
}

self.fmt.begin(group.config.break_style.0);

let mut tokens = group.content.iter();

let closing_punct_leading_blank = tokens
Expand Down
1 change: 1 addition & 0 deletions decondenser/tests/integration/formatting/001-rust.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Library { name: "Thornwick Archive", location: "Eldenmoor, Westreach", books: [Book { id: 1001, title: "The Hollow Lexicon", authors: [Author { name: "Elenya Thorne", pseudonym: Some("E. T. Mire"), birth_year: Some(1972) }], metadata: Metadata { isbn: Some("978-3-8267-9321-0"), pages: 412, genres: ["Mystery", "Arcane Fiction"], language: "Eldentongue", rating: Some(4.6) }, status: Available }, Book { id: 1002, title: "Cradle of Ironlight", authors: [Author { name: "Jorren Valek", pseudonym: None, birth_year: Some(1960) }, Author { name: "Silra Venn", pseudonym: None, birth_year: None }], metadata: Metadata { isbn: None, pages: 634, genres: ["Epic Fantasy"], language: "Virellic", rating: Some(4.9) }, status: CheckedOut { by_user_id: 78230944, due_date: "2025-08-21" } }, Book { id: 1003, title: "Treatise on Umbral Taxonomy", authors: [Author { name: "Professor N. W. Glaive", pseudonym: None, birth_year: None }], metadata: Metadata { isbn: Some("979-1-9472-3829-5"), pages: 271, genres: ["Non-fiction", "Shadow Studies"], language: "Imperial Common", rating: None }, status: Reserved(2198371) }], publishers: {"Marrow & Quill": Publisher { name: "Marrow & Quill", country: "Draventh", founded: 1951, imprints: [] }, "Cindergrove Press": Publisher { name: "Cindergrove Press", country: "Virelia", founded: 1894, imprints: ["Ash & Ink", "Frostmark Editions"] }} }
78 changes: 78 additions & 0 deletions decondenser/tests/integration/formatting/001-rust.out.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
Library {
name: "Thornwick Archive",
location: "Eldenmoor, Westreach",
books: [
Book {
id: 1001,
title: "The Hollow Lexicon",
authors: [
Author {
name: "Elenya Thorne",
pseudonym: Some("E. T. Mire"),
birth_year: Some(1972)
}
],
metadata: Metadata {
isbn: Some("978-3-8267-9321-0"),
pages: 412,
genres: ["Mystery", "Arcane Fiction"],
language: "Eldentongue",
rating: Some(4.6)
},
status: Available
},
Book {
id: 1002,
title: "Cradle of Ironlight",
authors: [
Author {
name: "Jorren Valek",
pseudonym: None,
birth_year: Some(1960)
},
Author { name: "Silra Venn", pseudonym: None, birth_year: None }
],
metadata: Metadata {
isbn: None,
pages: 634,
genres: ["Epic Fantasy"],
language: "Virellic",
rating: Some(4.9)
},
status: CheckedOut { by_user_id: 78230944, due_date: "2025-08-21" }
},
Book {
id: 1003,
title: "Treatise on Umbral Taxonomy",
authors: [
Author {
name: "Professor N. W. Glaive",
pseudonym: None,
birth_year: None
}
],
metadata: Metadata {
isbn: Some("979-1-9472-3829-5"),
pages: 271,
genres: ["Non-fiction", "Shadow Studies"],
language: "Imperial Common",
rating: None
},
status: Reserved(2198371)
}
],
publishers: {
"Marrow & Quill": Publisher {
name: "Marrow & Quill",
country: "Draventh",
founded: 1951,
imprints: []
},
"Cindergrove Press": Publisher {
name: "Cindergrove Press",
country: "Virelia",
founded: 1894,
imprints: ["Ash & Ink", "Frostmark Editions"]
}
}
}
1 change: 1 addition & 0 deletions decondenser/tests/integration/formatting/002-elixir.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
no match of right hand side value: {:ok, %Req.Response{status: 400, headers: %{"content-type" => ["application/json; charset=UTF-8"], "task_resource_usage" => ["{\"action\":\"indices:data/read/search[phase/query]\",\"taskId\":1979,\"parentTaskId\":1978,\"nodeId\":\"bpv3-LSSR4KXrWJNugVRDA\",\"taskResourceUsage\":{\"cpu_time_in_nanos\":392450,\"memory_in_bytes\":7456}}"]}, body: %{"error" => %{"caused_by" => %{"caused_by" => %{"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.", "type" => "illegal_argument_exception"}, "reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.", "type" => "illegal_argument_exception"}, "failed_shards" => [%{"index" => "tags", "node" => "bpv3-LSSR4KXrWJNugVRDA", "reason" => %{"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.", "type" => "illegal_argument_exception"}, "shard" => 0}], "grouped" => true, "phase" => "query", "reason" => "all shards failed", "root_cause" => [%{"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.", "type" => "illegal_argument_exception"}], "type" => "search_phase_execution_exception"}, "status" => 400}, trailers: %{}, private: %{}}}
48 changes: 48 additions & 0 deletions decondenser/tests/integration/formatting/002-elixir.out.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
no match of right hand side value: {
:ok,
%Req.Response{
status: 400,
headers: %{
"content-type" => ["application/json; charset=UTF-8"],
"task_resource_usage" => [
"{\"action\":\"indices:data/read/search[phase/query]\",\"taskId\":1979,\"parentTaskId\":1978,\"nodeId\":\"bpv3-LSSR4KXrWJNugVRDA\",\"taskResourceUsage\":{\"cpu_time_in_nanos\":392450,\"memory_in_bytes\":7456}}"
]
},
body: %{
"error" => %{
"caused_by" => %{
"caused_by" => %{
"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
"type" => "illegal_argument_exception"
},
"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
"type" => "illegal_argument_exception"
},
"failed_shards" => [
%{
"index" => "tags",
"node" => "bpv3-LSSR4KXrWJNugVRDA",
"reason" => %{
"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
"type" => "illegal_argument_exception"
},
"shard" => 0
}
],
"grouped" => true,
"phase" => "query",
"reason" => "all shards failed",
"root_cause" => [
%{
"reason" => "Text fields are not optimised for operations that require per-document field data like aggregations and sorting, so these operations are disabled by default. Please use a keyword field instead. Alternatively, set fielddata=true on [name] in order to load field data by uninverting the inverted index. Note that this can use significant memory.",
"type" => "illegal_argument_exception"
}
],
"type" => "search_phase_execution_exception"
},
"status" => 400
},
trailers: %{},
private: %{}
}
}
60 changes: 44 additions & 16 deletions decondenser/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@
use decondenser::Decondenser;
use std::borrow::Cow;
use std::io::Write;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::str::FromStr;

/// This test updates the `output` values in the `formatting.toml` file. It
/// never fails, it only updates the file. However, on CI we make sure that the
/// `formatting.toml` file is fresh by checking if it changes after the test
/// run. This way we can observe the changes to the output values in PR diffs
/// and have them automatically updated via `scripts/update-tests.sh`.
fn tests_dir() -> &'static Path {
static CACHE: std::sync::OnceLock<PathBuf> = std::sync::OnceLock::new();

CACHE.get_or_init(|| {
PathBuf::from_iter([
std::env::var("CARGO_MANIFEST_DIR")
.as_deref()
.unwrap_or(env!("CARGO_MANIFEST_DIR")),
"tests",
"integration",
])
})
}

#[test]
fn formatting() {
fn formatting_toml() {
Snapshot::new("formatting.toml").update(|test| {
let input = test["input"].as_str().unwrap();

Expand Down Expand Up @@ -54,7 +63,33 @@ fn formatting() {
}

#[test]
fn unescaping() {
fn formatting_dir() {
let tests = std::fs::read_dir(tests_dir().join("formatting")).unwrap();

for test in tests {
let test_path = test.unwrap().path();
let test_name = test_path.to_string_lossy();

let mut test_name_parts = test_name.split('.').collect::<Vec<_>>();

if test_name_parts.get(test_name_parts.len().saturating_sub(2)) == Some(&"out") {
continue;
}

let decondenser = Decondenser::generic();

let input = std::fs::read_to_string(&test_path).unwrap();
let output = decondenser.format(&input);

test_name_parts.insert(test_name_parts.len().saturating_sub(1), "out");
let out_path = test_path.with_file_name(test_name_parts.join("."));

std::fs::write(&out_path, output).unwrap();
}
}

#[test]
fn unescaping_toml() {
Snapshot::new("unescaping.toml").update(|test| {
let input = test["input"].as_str().unwrap();
let output = decondenser::unescape(input);
Expand All @@ -74,14 +109,7 @@ struct Snapshot {

impl Snapshot {
fn new(file_name: &str) -> Self {
let path = PathBuf::from_iter([
std::env::var("CARGO_MANIFEST_DIR")
.as_deref()
.unwrap_or(env!("CARGO_MANIFEST_DIR")),
"tests",
"integration",
file_name,
]);
let path = tests_dir().join(file_name);

let file = std::fs::read_to_string(&path).unwrap();

Expand Down
Loading