Skip to content

Commit

Permalink
Merge pull request #1451 from multiversx/bugfix_template
Browse files Browse the repository at this point in the history
template enforce new name arg to kebab case
  • Loading branch information
alyn509 authored Mar 12, 2024
2 parents 02b7ae8 + d920b53 commit efe7395
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use convert_case::{Case, Casing};

use crate::{
cli_args::TemplateArgs,
version::FrameworkVersion,
Expand All @@ -22,7 +24,11 @@ pub fn create_contract(args: &TemplateArgs) {
}

fn target_from_args(args: &TemplateArgs) -> ContractCreatorTarget {
let new_name = args.name.clone().unwrap_or_else(|| args.template.clone());
let new_name = args
.name
.clone()
.unwrap_or_else(|| args.template.clone())
.to_case(Case::Kebab);
let target_path = args.path.clone().unwrap_or_default();
ContractCreatorTarget {
target_path,
Expand Down
14 changes: 13 additions & 1 deletion framework/meta/tests/template_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fs, process::Command};

use convert_case::{Case, Casing};
use multiversx_sc_meta::{
cmd::standalone::template::{
template_names_from_repo, ContractCreator, ContractCreatorTarget, RepoSource, RepoVersion,
Expand Down Expand Up @@ -52,14 +53,25 @@ fn template_current_ping_pong_egld() {
template_test_current("ping-pong-egld", "examples", "new-ping-pong-egld");
}

#[test]
#[cfg_attr(not(feature = "template-test-current"), ignore)]
fn test_correct_naming() {
assert_eq!(
"myNew42-correct_Empty".to_string().to_case(Case::Kebab),
"my-new-42-correct-empty"
);

template_test_current("empty", "examples", "my1New2_3-correct_Empty");
}

/// Recreates the folder structure in `contracts`, on the same level.
/// This way, the relative paths are still valid in this case,
/// and we can test the templates with the framework version of the current branch.
fn template_test_current(template_name: &str, sub_path: &str, new_name: &str) {
let workspace_path = find_current_workspace().unwrap();
let target = ContractCreatorTarget {
target_path: workspace_path.join(TEMPLATE_TEMP_DIR_NAME).join(sub_path),
new_name: new_name.to_string(),
new_name: new_name.to_string().to_case(Case::Kebab),
};

let repo_source = RepoSource::from_local_path(workspace_path);
Expand Down

0 comments on commit efe7395

Please sign in to comment.