1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
pub(crate) fn default_manifest(project_name: &str, entry_type: &str) -> String {
let author = get_author();
format!(
r#"[project]
authors = ["{author}"]
entry = "{entry_type}"
license = "Apache-2.0"
name = "{project_name}"
[dependencies]
"#
)
}
pub(crate) fn default_contract() -> String {
r#"contract;
abi MyContract {
fn test_function() -> bool;
}
impl MyContract for Contract {
fn test_function() -> bool {
true
}
}
"#
.into()
}
pub(crate) fn default_script() -> String {
r#"script;
fn main() {
}
"#
.into()
}
pub(crate) fn default_library(project_name: &str) -> String {
format!(
"library {project_name};
// anything `pub` here will be exported as a part of this library's API
"
)
}
pub(crate) fn default_predicate() -> String {
r#"predicate;
fn main() -> bool {
false
}
"#
.into()
}
pub(crate) fn default_gitignore() -> String {
r#"out
target
"#
.into()
}
fn get_author() -> String {
std::env::var(sway_utils::FORC_INIT_MANIFEST_AUTHOR).unwrap_or_else(|_| whoami::realname())
}
#[test]
fn parse_default_manifest() {
use sway_utils::constants::MAIN_ENTRY;
tracing::info!(
"{:#?}",
toml::from_str::<forc_pkg::PackageManifest>(&default_manifest("test_proj", MAIN_ENTRY))
.unwrap()
)
}