Skip to content

Commit

Permalink
Add a print statement alongisde println in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grasshopper47 committed Nov 30, 2023
1 parent 20aa1b2 commit e7f217d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
14 changes: 12 additions & 2 deletions test_programs/execution_success/strings/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,26 @@ fn main(message: pub str<11>, y: Field, hex_as_string: str<4>, hex_as_field: Fie
let x = 10;
let z = x * 5;
std::println(10);
std::print(10);

std::println(z); // x * 5 in println not yet supported
std::print(z);
std::println(x);
std::print(x);

let array = [1, 2, 3, 5, 8];
assert(y == 5); // Change to y != 5 to see how the later print statements are not called
std::println(array);
std::print(array);

bad_message = "hell\0\"world";
std::println(bad_message);
std::print(bad_message);
assert(message != bad_message);

let hash = std::hash::pedersen_commitment([x]);
std::println(hash);
std::print(hash);

assert(hex_as_string == "0x41");
// assert(hex_as_string != 0x41); This will fail with a type mismatch between str[4] and Field
Expand All @@ -36,6 +42,10 @@ fn test_prints_strings() {

std::println(message);
std::println("goodbye world");

std::print(message);
std::print("\n");
std::print("goodbye world\n");
}

#[test]
Expand All @@ -52,8 +62,8 @@ fn test_prints_array() {
}

fn failed_constraint(hex_as_field: Field) {
// TODO(#2116): Note that `println` will not work if a failed constraint can be
// evaluated at compile time.
// TODO(#2116): Note that `println` will not work if a failed constraint can be
// evaluated at compile time.
// When this method is called from a test method or with constant values
// a `Failed constraint` compile error will be caught before this `println`
// is executed as the input will be a constant.
Expand Down
1 change: 1 addition & 0 deletions tooling/nargo_fmt/tests/expected/print.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dep::std;

fn main() {
std::print("Hello world");
std::println("Hello world");
}
3 changes: 2 additions & 1 deletion tooling/nargo_fmt/tests/expected/print2.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dep::std;

fn main( ) {
fn main() {
std::print("Hello world");
std::println("Hello world");
}
5 changes: 4 additions & 1 deletion tooling/nargo_fmt/tests/input/print.nr
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use dep::std;

fn main() { std::println("Hello world"); }
fn main() {
std::print("Hello world");
std::println("Hello world");
}
5 changes: 3 additions & 2 deletions tooling/nargo_fmt/tests/input/print2.nr
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use dep::std;

fn main( ) {
std::println("Hello world");
fn main() {
std::print("Hello world");
std::println("Hello world");
}

0 comments on commit e7f217d

Please sign in to comment.