From 7682e5555470fe6e9124270a919af1b454e49481 Mon Sep 17 00:00:00 2001 From: OmarTawfik <15987992+OmarTawfik@users.noreply.github.com> Date: Tue, 16 May 2023 02:12:13 -0700 Subject: [PATCH] fix test snapshot indices Follow up on #458 - make sure test snapshots padding uses chars instead of bytes - fixed a minor bug with rendering error messages on empty source input, as it expects line/col, not start/end bytes. --- crates/codegen/syntax_templates/src/shared/language.rs | 6 +----- .../outputs/cargo/crate/src/generated/language.rs | 6 +----- .../outputs/npm/crate/src/generated/language.rs | 6 +----- .../unicode_string_literal/generated/0.4.11.yml | 2 +- .../unicode_string_literal/generated/0.7.0.yml | 2 +- .../unicode_multiple/generated/0.4.11.yml | 2 +- .../unicode_multiple/generated/0.7.0.yml | 2 +- .../unicode_single/generated/0.4.11.yml | 2 +- .../unicode_single/generated/0.7.0.yml | 2 +- crates/solidity/testing/utils/src/cst_snapshots/mod.rs | 10 +++++----- 10 files changed, 14 insertions(+), 26 deletions(-) diff --git a/crates/codegen/syntax_templates/src/shared/language.rs b/crates/codegen/syntax_templates/src/shared/language.rs index 417da25b4c..d3dd5a4847 100644 --- a/crates/codegen/syntax_templates/src/shared/language.rs +++ b/crates/codegen/syntax_templates/src/shared/language.rs @@ -182,11 +182,7 @@ pub(crate) fn render_error_report( }; if source.is_empty() { - return format!( - "{kind}: {message}\n ─[{source_id}:{source_start}:{source_end}]", - source_start = source_start.char, - source_end = source_end.char - ); + return format!("{kind}: {message}\n ─[{source_id}:0:0]"); } let mut builder = Report::build(kind, source_id, source_start.byte) diff --git a/crates/solidity/outputs/cargo/crate/src/generated/language.rs b/crates/solidity/outputs/cargo/crate/src/generated/language.rs index 249e49de2a..f05674b4ad 100644 --- a/crates/solidity/outputs/cargo/crate/src/generated/language.rs +++ b/crates/solidity/outputs/cargo/crate/src/generated/language.rs @@ -184,11 +184,7 @@ pub(crate) fn render_error_report( }; if source.is_empty() { - return format!( - "{kind}: {message}\n ─[{source_id}:{source_start}:{source_end}]", - source_start = source_start.char, - source_end = source_end.char - ); + return format!("{kind}: {message}\n ─[{source_id}:0:0]"); } let mut builder = Report::build(kind, source_id, source_start.byte) diff --git a/crates/solidity/outputs/npm/crate/src/generated/language.rs b/crates/solidity/outputs/npm/crate/src/generated/language.rs index fd8dd1896c..c67baf95b2 100644 --- a/crates/solidity/outputs/npm/crate/src/generated/language.rs +++ b/crates/solidity/outputs/npm/crate/src/generated/language.rs @@ -184,11 +184,7 @@ pub(crate) fn render_error_report( }; if source.is_empty() { - return format!( - "{kind}: {message}\n ─[{source_id}:{source_start}:{source_end}]", - source_start = source_start.char, - source_end = source_end.char - ); + return format!("{kind}: {message}\n ─[{source_id}:0:0]"); } let mut builder = Report::build(kind, source_id, source_start.byte) diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.4.11.yml b/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.4.11.yml index 82ab945131..7684b0fb54 100644 --- a/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.4.11.yml +++ b/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.4.11.yml @@ -1,7 +1,7 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ unicode"This Emoji: 😃" │ 0..25 + 1 │ unicode"This Emoji: 😃" │ 0..25 Errors: # 1 total - > diff --git a/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.7.0.yml b/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.7.0.yml index 515bed047e..015a9c58f8 100644 --- a/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.7.0.yml +++ b/crates/solidity/testing/snapshots/cst_output/Expression/unicode_string_literal/generated/0.7.0.yml @@ -1,7 +1,7 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ unicode"This Emoji: 😃" │ 0..25 + 1 │ unicode"This Emoji: 😃" │ 0..25 Errors: [] diff --git a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.4.11.yml b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.4.11.yml index b2d6fe88d8..a3e33130b4 100644 --- a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.4.11.yml +++ b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.4.11.yml @@ -1,7 +1,7 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ unicode"happy 😃" unicode'sad 😔' │ 0..37 + 1 │ unicode"happy 😃" unicode'sad 😔' │ 0..37 Errors: # 1 total - > diff --git a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.7.0.yml b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.7.0.yml index 7122127ed7..4b00d4663e 100644 --- a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.7.0.yml +++ b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_multiple/generated/0.7.0.yml @@ -1,7 +1,7 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ unicode"happy 😃" unicode'sad 😔' │ 0..37 + 1 │ unicode"happy 😃" unicode'sad 😔' │ 0..37 Errors: [] diff --git a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.4.11.yml b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.4.11.yml index 2d7e66ba97..b2740943e9 100644 --- a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.4.11.yml +++ b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.4.11.yml @@ -1,7 +1,7 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ unicode"emoji 😃" │ 0..19 + 1 │ unicode"emoji 😃" │ 0..19 Errors: # 1 total - > diff --git a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.7.0.yml b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.7.0.yml index 862b18563f..9b0f59ba01 100644 --- a/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.7.0.yml +++ b/crates/solidity/testing/snapshots/cst_output/StringExpression/unicode_single/generated/0.7.0.yml @@ -1,7 +1,7 @@ # This file is generated automatically by infrastructure scripts. Please don't edit by hand. Source: > - 1 │ unicode"emoji 😃" │ 0..19 + 1 │ unicode"emoji 😃" │ 0..19 Errors: [] diff --git a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs b/crates/solidity/testing/utils/src/cst_snapshots/mod.rs index ad9d731d5f..83c053295f 100644 --- a/crates/solidity/testing/utils/src/cst_snapshots/mod.rs +++ b/crates/solidity/testing/utils/src/cst_snapshots/mod.rs @@ -36,13 +36,13 @@ fn write_source(w: &mut W, source: &str) -> Result<()> { let line_data = source .lines() .enumerate() - .map(|(index, line)| (index, line, line.bytes().len())) + .map(|(index, line)| (index, line, line.bytes().len(), line.chars().count())) .collect::>(); let source_width = { let source_width = line_data .iter() - .map(|(_, _, length)| *length) + .map(|(_, _, _, chars)| *chars) .max() .unwrap_or(0); @@ -52,13 +52,13 @@ fn write_source(w: &mut W, source: &str) -> Result<()> { writeln!(w, "Source: >")?; let mut offset = 0; - for (index, line, length) in line_data.iter() { - let range = offset..(offset + length); + for (index, line, bytes, chars) in line_data.iter() { + let range = offset..(offset + bytes); writeln!( w, " {line_number: <2} │ {line}{padding} │ {range:?}", line_number = index + 1, - padding = " ".repeat(source_width - length), + padding = " ".repeat(source_width - chars), )?; offset = range.end + 1;