Skip to content

Commit

Permalink
Merge branch 'master' into tf/fix-primitive-type-gen
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray authored Jan 8, 2024
2 parents 8e6c2c1 + 3801956 commit 6be11ac
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"montcurve",
"nand",
"nargo",
"neovim",
"newtype",
"nightlies",
"nixpkgs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,6 @@ Example of how it is used:
use dep::std;

fn main(x: u8, y: u8) -> pub u8 {
std::wrapping_add(x + y)
std::wrapping_add(x, y)
}
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main(x: Field, y: pub Field) {
let xs = Vec::new();
let option = Option::none();
fn main() {
let _xs = Vec::new();
let _option = Option::none();

print("42\n");
println("42");
Expand All @@ -10,11 +10,10 @@ mod a {
// We don't want to give an error due to re-importing elements that are already in the prelude.
use dep::std::collections::vec::Vec;
use dep::std::option::Option;
use dep::{print, println};

fn main() {
let xs = Vec::new();
let option = Option::none();
let _xs = Vec::new();
let _option = Option::none();

print("42\n");
println("42");
Expand All @@ -23,8 +22,8 @@ mod a {

mod b {
fn main() {
let xs = Vec::new();
let option = Option::none();
let _xs = Vec::new();
let _option = Option::none();

print("42\n");
println("42");
Expand Down
27 changes: 27 additions & 0 deletions tooling/lsp/src/requests/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ where
}
}

/// Calculates the byte offset of a given character in a line.
/// LSP Clients (editors, eg. neovim) use a different coordinate (LSP Positions) system than the compiler.
///
/// LSP Positions navigate through line numbers and character numbers, eg. `(line: 1, character: 5)`
/// meanwhile byte indexes are used within the compiler to navigate through the source code.
fn character_to_line_offset(line: &str, character: u32) -> Result<usize, Error> {
let line_len = line.len();
let mut character_offset = 0;
Expand Down Expand Up @@ -199,3 +204,25 @@ mod goto_definition_tests {
assert!(&response.is_some());
}
}

#[cfg(test)]
mod character_to_line_offset_tests {
use super::*;

#[test]
fn test_character_to_line_offset() {
let line = "Hello, dark!";
let character = 8;

let result = character_to_line_offset(line, character).unwrap();
assert_eq!(result, 8);

// In the case of a multi-byte character, the offset should be the byte index of the character
// byte offset for 8 character (黑) is expected to be 10
let line = "Hello, 黑!";
let character = 8;

let result = character_to_line_offset(line, character).unwrap();
assert_eq!(result, 10);
}
}
7 changes: 4 additions & 3 deletions tooling/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ fn check_rustc_version() {
const GIT_COMMIT: &&str = &"GIT_COMMIT";

fn main() {
// Rebuild if the tests have changed
println!("cargo:rerun-if-changed=tests");

check_rustc_version();

// Only use build_data if the environment variable isn't set
Expand All @@ -39,6 +36,10 @@ fn main() {
};
let test_dir = root_dir.join("test_programs");

// Rebuild if the tests have changed
println!("cargo:rerun-if-changed=tests");
println!("cargo:rerun-if-changed={}", test_dir.as_os_str().to_str().unwrap());

generate_execution_success_tests(&mut test_file, &test_dir);
generate_noir_test_success_tests(&mut test_file, &test_dir);
generate_noir_test_failure_tests(&mut test_file, &test_dir);
Expand Down
19 changes: 11 additions & 8 deletions tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn run_tests<S: BlackBoxFunctionSolver>(

for (test_name, test_function) in test_functions {
write!(writer, "[{}] Testing {test_name}... ", package.name)
.expect("Failed to write to stdout");
.expect("Failed to write to stderr");
writer.flush().expect("Failed to flush writer");

match run_test(
Expand All @@ -159,13 +159,13 @@ fn run_tests<S: BlackBoxFunctionSolver>(
writer
.set_color(ColorSpec::new().set_fg(Some(Color::Green)))
.expect("Failed to set color");
writeln!(writer, "ok").expect("Failed to write to stdout");
writeln!(writer, "ok").expect("Failed to write to stderr");
}
TestStatus::Fail { message, error_diagnostic } => {
writer
.set_color(ColorSpec::new().set_fg(Some(Color::Red)))
.expect("Failed to set color");
writeln!(writer, "{message}\n").expect("Failed to write to stdout");
writeln!(writer, "FAIL\n{message}\n").expect("Failed to write to stderr");
if let Some(diag) = error_diagnostic {
noirc_errors::reporter::report_all(
context.file_manager.as_file_map(),
Expand All @@ -189,12 +189,13 @@ fn run_tests<S: BlackBoxFunctionSolver>(
writer.reset().expect("Failed to reset writer");
}

write!(writer, "[{}] ", package.name).expect("Failed to write to stdout");
write!(writer, "[{}] ", package.name).expect("Failed to write to stderr");

if count_failed == 0 {
writer.set_color(ColorSpec::new().set_fg(Some(Color::Green))).expect("Failed to set color");
writeln!(writer, "{count_all} test{plural} passed").expect("Failed to write to stdout");
write!(writer, "{count_all} test{plural} passed").expect("Failed to write to stderr");
writer.reset().expect("Failed to reset writer");
writeln!(writer).expect("Failed to write to stderr");

Ok(())
} else {
Expand All @@ -207,13 +208,15 @@ fn run_tests<S: BlackBoxFunctionSolver>(
.set_color(ColorSpec::new().set_fg(Some(Color::Green)))
.expect("Failed to set color");
write!(writer, "{count_passed} test{plural_passed} passed, ",)
.expect("Failed to write to stdout");
.expect("Failed to write to stderr");
}

writer.set_color(ColorSpec::new().set_fg(Some(Color::Red))).expect("Failed to set color");
writeln!(writer, "{count_failed} test{plural_failed} failed")
.expect("Failed to write to stdout");
write!(writer, "{count_failed} test{plural_failed} failed")
.expect("Failed to write to stderr");
writer.reset().expect("Failed to reset writer");

// Writes final newline.
Err(CliError::Generic(String::new()))
}
}

0 comments on commit 6be11ac

Please sign in to comment.