Skip to content

Commit

Permalink
chore: move noir program templates into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Oct 17, 2023
1 parent d4f61d3 commit c29f455
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 32 deletions.
35 changes: 3 additions & 32 deletions tooling/nargo_cli/src/cli/init_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,9 @@ pub(crate) struct InitCommand {
pub(crate) contract: bool,
}

const BIN_EXAMPLE: &str = r#"fn main(x : Field, y : pub Field) {
assert(x != y);
}
#[test]
fn test_main() {
main(1, 2);
// Uncomment to make test fail
// main(1, 1);
}
"#;

const CONTRACT_EXAMPLE: &str = r#"contract Main {
internal fn double(x: Field) -> pub Field { x * 2 }
fn triple(x: Field) -> pub Field { x * 3 }
fn quadruple(x: Field) -> pub Field { double(double(x)) }
}
"#;

const LIB_EXAMPLE: &str = r#"fn my_util(x : Field, y : Field) -> bool {
x != y
}
#[test]
fn test_my_util() {
assert(my_util(1, 2));
// Uncomment to make test fail
// assert(my_util(1, 1));
}
"#;
const BIN_EXAMPLE: &str = include_str!("./noir_template_files/binary.nr");
const CONTRACT_EXAMPLE: &str = include_str!("./noir_template_files/contract.nr");
const LIB_EXAMPLE: &str = include_str!("./noir_template_files/library.nr");

pub(crate) fn run(
// Backend is currently unused, but we might want to use it to inform the "new" template in the future
Expand Down
11 changes: 11 additions & 0 deletions tooling/nargo_cli/src/cli/noir_template_files/binary.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn main(x: Field, y: pub Field) {
assert(x != y);
}

#[test]
fn test_main() {
main(1, 2);

// Uncomment to make test fail
// main(1, 1);
}
5 changes: 5 additions & 0 deletions tooling/nargo_cli/src/cli/noir_template_files/contract.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract Main {
internal fn double(x: Field) -> pub Field { x * 2 }
fn triple(x: Field) -> pub Field { x * 3 }
fn quadruple(x: Field) -> pub Field { double(double(x)) }
}
11 changes: 11 additions & 0 deletions tooling/nargo_cli/src/cli/noir_template_files/library.nr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
fn not_equal(x: Field, y: Field) -> bool {
x != y
}

#[test]
fn test_not_equal() {
assert(not_equal(1, 2));

// Uncomment to make test fail
// assert(not_equal(1, 1));
}

0 comments on commit c29f455

Please sign in to comment.