From 5fa2d73778f2534d5032d9ffbc80cc99707835bd Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Sat, 12 Oct 2024 16:59:25 -0400 Subject: [PATCH] Fix JS tests --- eipw-lint-js/tests/main.rs | 440 ++++++++++++++++++------------------- eipw-snippets/src/lib.rs | 3 + 2 files changed, 219 insertions(+), 224 deletions(-) diff --git a/eipw-lint-js/tests/main.rs b/eipw-lint-js/tests/main.rs index d9346d5a..20eeea06 100644 --- a/eipw-lint-js/tests/main.rs +++ b/eipw-lint-js/tests/main.rs @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +#![cfg(target_arch = "wasm32")] use eipw_lint_js::{format, lint}; @@ -34,50 +35,48 @@ async fn lint_one() { let actual: serde_json::Value = serde_wasm_bindgen::from_value(result).unwrap(); let expected = json! { [ - { - "formatted": "error[preamble-requires-status]: preamble header `requires` contains items not stable enough for a `status` of `Last Call`\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | ^^^ has a less advanced status\n |\n = help: valid `status` values for this proposal are: `Draft`, `Stagnant`\n = help: see https://ethereum.github.io/eipw/preamble-requires-status/", - "footer": [ - { - "annotation_type": "Help", - "id": null, - "label": "valid `status` values for this proposal are: `Draft`, `Stagnant`" - }, - { - "annotation_type": "Help", - "id": null, - "label": "see https://ethereum.github.io/eipw/preamble-requires-status/" - } - ], - "opt": { - "anonymized_line_numbers": false, - "color": false - }, - "slices": [ - { - "annotations": [ - { - "annotation_type": "Error", - "label": "has a less advanced status", - "range": [ - 9, - 12 - ] - } - ], - "fold": false, - "line_start": 12, - "origin": "tests/eips/eip-1000.md", - "source": "requires: 20" - } - ], - "title": { - "annotation_type": "Error", - "id": "preamble-requires-status", - "label": "preamble header `requires` contains items not stable enough for a `status` of `Last Call`" - } - } + { + "footer": [ + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "valid `status` values for this proposal are: `Draft`, `Stagnant`" + }, + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "see https://ethereum.github.io/eipw/preamble-requires-status/" + } + ], + "formatted": "error[preamble-requires-status]: preamble header `requires` contains items not stable enough for a `status` of `Last Call`\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | ^^^ has a less advanced status\n |\n = help: valid `status` values for this proposal are: `Draft`, `Stagnant`\n = help: see https://ethereum.github.io/eipw/preamble-requires-status/", + "id": "preamble-requires-status", + "level": "Error", + "snippets": [ + { + "annotations": [ + { + "label": "has a less advanced status", + "level": "Error", + "range": { + "end": 12, + "start": 9 + } + } + ], + "fold": false, + "line_start": 12, + "origin": "tests/eips/eip-1000.md", + "source": "requires: 20" + } + ], + "title": "preamble header `requires` contains items not stable enough for a `status` of `Last Call`" + } ] - }; + }; assert_eq!(expected, actual); } @@ -98,62 +97,62 @@ async fn lint_json_schema() { let actual: serde_json::Value = serde_wasm_bindgen::from_value(result).unwrap(); let expected = json! { [ - { - "formatted": "error[markdown-json-cite]: code block of type `csl-json` does not conform to required schema\n --> tests/eips/eip-2000.md:42:1\n |\n42 | // ```csl-json\n43 | || {\n44 | || \"type\": \"article\",\n45 | || \"id\": \"1\",\n46 | | \"URL\": \"3\"\n | ||__________________^ \"3\" is not a \"uri\"\n | |__________________^ \"DOI\" is a required property\n |\n = help: see https://github.com/ethereum/eipw/blob/master/eipw-lint/src/lints/markdown/json_schema/citation.json\n = help: see https://ethereum.github.io/eipw/markdown-json-cite/", - "footer": [ - { - "annotation_type": "Help", - "id": null, - "label": "see https://github.com/ethereum/eipw/blob/master/eipw-lint/src/lints/markdown/json_schema/citation.json" - }, - { - "annotation_type": "Help", - "id": null, - "label": "see https://ethereum.github.io/eipw/markdown-json-cite/" - } - ], - "opt": { - "anonymized_line_numbers": false, - "color": false - }, - "slices": [ - { - "annotations": [ - { - "annotation_type": "Error", - "label": "\"3\" is not a \"uri\"", - "range": [ - 0, - 86 - ] - }, - { - "annotation_type": "Error", - "label": "\"DOI\" is a required property", - "range": [ - 0, - 86 - ] - } - ], - "fold": false, - "line_start": 42, - "origin": "tests/eips/eip-2000.md", - "source": " ```csl-json\n {\n \"type\": \"article\",\n \"id\": \"1\",\n \"URL\": \"3\"" - } - ], - "title": { - "annotation_type": "Error", - "id": "markdown-json-cite", - "label": "code block of type `csl-json` does not conform to required schema" - } - } + { + "footer": [ + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "see https://github.com/ethereum/eipw/blob/master/eipw-lint/src/lints/markdown/json_schema/citation.json" + }, + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "see https://ethereum.github.io/eipw/markdown-json-cite/" + } + ], + "formatted": "error[markdown-json-cite]: code block of type `csl-json` does not conform to required schema\n --> tests/eips/eip-2000.md:42:1\n |\n42 | // ```csl-json\n43 | || {\n44 | || \"type\": \"article\",\n45 | || \"id\": \"1\",\n46 | || \"URL\": \"3\"\n | ||__________________^ \"3\" is not a \"uri\"\n | ||__________________^ \"DOI\" is a required property\n |\n = help: see https://github.com/ethereum/eipw/blob/master/eipw-lint/src/lints/markdown/json_schema/citation.json\n = help: see https://ethereum.github.io/eipw/markdown-json-cite/", + "id": "markdown-json-cite", + "level": "Error", + "snippets": [ + { + "annotations": [ + { + "label": "\"3\" is not a \"uri\"", + "level": "Error", + "range": { + "end": 86, + "start": 0 + } + }, + { + "label": "\"DOI\" is a required property", + "level": "Error", + "range": { + "end": 86, + "start": 0 + } + } + ], + "fold": false, + "line_start": 42, + "origin": "tests/eips/eip-2000.md", + "source": " ```csl-json\n {\n \"type\": \"article\",\n \"id\": \"1\",\n \"URL\": \"3\"" + } + ], + "title": "code block of type `csl-json` does not conform to required schema" + } ] - }; + + }; assert_eq!(expected, actual); } +#[cfg(target_arch = "wasm32")] #[wasm_bindgen_test] async fn lint_one_with_options() { let mut path = PathBuf::from("tests"); @@ -183,50 +182,48 @@ async fn lint_one_with_options() { let actual: serde_json::Value = serde_wasm_bindgen::from_value(result).unwrap(); let expected = json! { [ - { - "formatted": "warning[preamble-requires-status]: preamble header `requires` contains items not stable enough for a `status` of `Last Call`\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | --- has a less advanced status\n |\n = help: valid `status` values for this proposal are: `Draft`, `Stagnant`\n = help: see https://ethereum.github.io/eipw/preamble-requires-status/", - "footer": [ - { - "annotation_type": "Help", - "id": null, - "label": "valid `status` values for this proposal are: `Draft`, `Stagnant`" - }, - { - "annotation_type": "Help", - "id": null, - "label": "see https://ethereum.github.io/eipw/preamble-requires-status/" - } - ], - "opt": { - "anonymized_line_numbers": false, - "color": false - }, - "slices": [ - { - "annotations": [ - { - "annotation_type": "Warning", - "label": "has a less advanced status", - "range": [ - 9, - 12 - ] - } - ], - "fold": false, - "line_start": 12, - "origin": "tests/eips/eip-1000.md", - "source": "requires: 20" - } - ], - "title": { - "annotation_type": "Warning", - "id": "preamble-requires-status", - "label": "preamble header `requires` contains items not stable enough for a `status` of `Last Call`" - } - } + { + "footer": [ + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "valid `status` values for this proposal are: `Draft`, `Stagnant`" + }, + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "see https://ethereum.github.io/eipw/preamble-requires-status/" + } + ], + "formatted": "warning[preamble-requires-status]: preamble header `requires` contains items not stable enough for a `status` of `Last Call`\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | --- has a less advanced status\n |\n = help: valid `status` values for this proposal are: `Draft`, `Stagnant`\n = help: see https://ethereum.github.io/eipw/preamble-requires-status/", + "id": "preamble-requires-status", + "level": "Warning", + "snippets": [ + { + "annotations": [ + { + "label": "has a less advanced status", + "level": "Warning", + "range": { + "end": 12, + "start": 9 + } + } + ], + "fold": false, + "line_start": 12, + "origin": "tests/eips/eip-1000.md", + "source": "requires: 20" + } + ], + "title": "preamble header `requires` contains items not stable enough for a `status` of `Last Call`" + } ] - }; + }; assert_eq!(expected, actual); } @@ -266,50 +263,48 @@ async fn lint_one_with_default_lints() { let actual: serde_json::Value = serde_wasm_bindgen::from_value(result).unwrap(); let expected = json! { [ - { - "formatted": "error[banana]: requires must include banana\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | ^^^ required pattern was not matched\n |\n = info: the pattern in question: `banana`\n = help: see https://ethereum.github.io/eipw/banana/", - "footer": [ - { - "annotation_type": "Info", - "id": null, - "label": "the pattern in question: `banana`" - }, - { - "annotation_type": "Help", - "id": null, - "label": "see https://ethereum.github.io/eipw/banana/" - } - ], - "opt": { - "anonymized_line_numbers": false, - "color": false - }, - "slices": [ - { - "annotations": [ - { - "annotation_type": "Error", - "label": "required pattern was not matched", - "range": [ - 9, - 12 - ] - } - ], - "fold": false, - "line_start": 12, - "origin": "tests/eips/eip-1000.md", - "source": "requires: 20" - } - ], - "title": { - "annotation_type": "Error", - "id": "banana", - "label": "requires must include banana" - } - } + { + "footer": [ + { + "footer": [], + "id": null, + "level": "Info", + "snippets": [], + "title": "the pattern in question: `banana`" + }, + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "see https://ethereum.github.io/eipw/banana/" + } + ], + "formatted": "error[banana]: requires must include banana\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | ^^^ required pattern was not matched\n |\n = info: the pattern in question: `banana`\n = help: see https://ethereum.github.io/eipw/banana/", + "id": "banana", + "level": "Error", + "snippets": [ + { + "annotations": [ + { + "label": "required pattern was not matched", + "level": "Error", + "range": { + "end": 12, + "start": 9 + } + } + ], + "fold": false, + "line_start": 12, + "origin": "tests/eips/eip-1000.md", + "source": "requires: 20" + } + ], + "title": "requires must include banana" + } ] - }; + }; assert_eq!(expected, actual); } @@ -329,7 +324,7 @@ async fn lint_one_with_default_modifiers() { "kind": "set-default-annotation", "name": "status", "value": "Last Call", - "annotation_type": "info", + "annotation_level": "info", } ] } @@ -342,54 +337,51 @@ async fn lint_one_with_default_modifiers() { let result = lint(vec![JsValue::from_str(path)], Some(opts)) .await - .ok() .unwrap(); let actual: serde_json::Value = serde_wasm_bindgen::from_value(result).unwrap(); let expected = json! { [ - { - "formatted": "info[preamble-requires-status]: preamble header `requires` contains items not stable enough for a `status` of `Last Call`\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | --- info: has a less advanced status\n |\n = help: valid `status` values for this proposal are: `Draft`, `Stagnant`\n = help: see https://ethereum.github.io/eipw/preamble-requires-status/", - "footer": [ - { - "annotation_type": "Help", - "id": null, - "label": "valid `status` values for this proposal are: `Draft`, `Stagnant`" - }, - { - "annotation_type": "Help", - "id": null, - "label": "see https://ethereum.github.io/eipw/preamble-requires-status/" - } - ], - "opt": { - "anonymized_line_numbers": false, - "color": false - }, - "slices": [ - { - "annotations": [ - { - "annotation_type": "Info", - "label": "has a less advanced status", - "range": [ - 9, - 12 - ] - } - ], - "fold": false, - "line_start": 12, - "origin": "tests/eips/eip-1000.md", - "source": "requires: 20" - } - ], - "title": { - "annotation_type": "Info", - "id": "preamble-requires-status", - "label": "preamble header `requires` contains items not stable enough for a `status` of `Last Call`" - } - } + { + "footer": [ + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "valid `status` values for this proposal are: `Draft`, `Stagnant`" + }, + { + "footer": [], + "id": null, + "level": "Help", + "snippets": [], + "title": "see https://ethereum.github.io/eipw/preamble-requires-status/" + } + ], + "formatted": "info[preamble-requires-status]: preamble header `requires` contains items not stable enough for a `status` of `Last Call`\n --> tests/eips/eip-1000.md:12:10\n |\n12 | requires: 20\n | --- info: has a less advanced status\n |\n = help: valid `status` values for this proposal are: `Draft`, `Stagnant`\n = help: see https://ethereum.github.io/eipw/preamble-requires-status/", + "id": "preamble-requires-status", + "level": "Info", + "snippets": [ + { + "annotations": [ + { + "label": "has a less advanced status", + "level": "Info", + "range": { + "end": 12, + "start": 9 + } + } + ], + "fold": false, + "line_start": 12, + "origin": "tests/eips/eip-1000.md", + "source": "requires: 20" + } + ], + "title": "preamble header `requires` contains items not stable enough for a `status` of `Last Call`" + } ] }; diff --git a/eipw-snippets/src/lib.rs b/eipw-snippets/src/lib.rs index 78e5502b..74cdf77f 100644 --- a/eipw-snippets/src/lib.rs +++ b/eipw-snippets/src/lib.rs @@ -14,6 +14,7 @@ use std::ops::Range; #[non_exhaustive] pub struct Message<'a> { pub level: Level, + #[serde(default)] pub id: Option>, pub title: Cow<'a, str>, pub snippets: Vec>, @@ -65,6 +66,7 @@ impl<'a, 'b> From<&'b Message<'a>> for ann::Message<'b> { #[derive(Debug, Deserialize, Serialize)] #[non_exhaustive] pub struct Snippet<'a> { + #[serde(default)] pub origin: Option>, pub line_start: usize, @@ -130,6 +132,7 @@ impl<'a, 'b> From<&'b Snippet<'a>> for ann::Snippet<'b> { #[non_exhaustive] pub struct Annotation<'a> { pub range: Range, + #[serde(default)] pub label: Option>, pub level: Level, }