Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ELIF (else-if) in templates #96

Merged
merged 2 commits into from
Feb 10, 2025
Merged

Support ELIF (else-if) in templates #96

merged 2 commits into from
Feb 10, 2025

Conversation

bugadani
Copy link
Contributor

This PR adds support for else-if in templates, which will be useful if we are going to have more options that are mutually exclusive.

The PR also reorders log setup to before HAL initialization, so that the HAL's init process may be able to print logs if such configured.

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bugadani bugadani added skip-changelog No changelog modification needed and removed skip-changelog No changelog modification needed labels Feb 10, 2025
Copy link
Collaborator

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would add a test case for ELIF - otherwise looks fine

@bugadani
Copy link
Contributor Author

Do we have tests to add it to?

@bjoernQ
Copy link
Collaborator

bjoernQ commented Feb 10, 2025

Do we have tests to add it to?

Not a lot of them but especially for the IF/ELSE/ENDIF stuff:

esp-generate/src/main.rs

Lines 578 to 728 in de38c80

mod test {
use super::*;
#[test]
fn test_nested_if_else1() {
let res = process_file(
r#"
#IF option("opt1")
opt1
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
#ELSE
!opt1
#ENDIF
"#,
&["opt1".to_string(), "opt2".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();
assert_eq!(
r#"
opt1
opt2
"#
.trim(),
res.trim()
);
}
#[test]
fn test_nested_if_else2() {
let res = process_file(
r#"
#IF option("opt1")
opt1
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
#ELSE
!opt1
#ENDIF
"#,
&[],
&[],
&mut String::from("main.rs"),
)
.unwrap();
assert_eq!(
r#"
!opt1
"#
.trim(),
res.trim()
);
}
#[test]
fn test_nested_if_else3() {
let res = process_file(
r#"
#IF option("opt1")
opt1
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
#ELSE
!opt1
#ENDIF
"#,
&["opt1".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();
assert_eq!(
r#"
opt1
!opt2
"#
.trim(),
res.trim()
);
}
#[test]
fn test_nested_if_else4() {
let res = process_file(
r#"
#IF option("opt1")
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
opt1
#ENDIF
"#,
&["opt1".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();
assert_eq!(
r#"
!opt2
opt1
"#
.trim(),
res.trim()
);
}
#[test]
fn test_nested_if_else5() {
let res = process_file(
r#"
#IF option("opt1")
#IF option("opt2")
opt2
#ELSE
!opt2
#ENDIF
opt1
#ENDIF
"#,
&["opt2".to_string()],
&[],
&mut String::from("main.rs"),
)
.unwrap();
assert_eq!(
r#"
"#
.trim(),
res.trim()
);
}
}

There is probably more we could test ofc

@bugadani
Copy link
Contributor Author

Certainly easier to test this than eyeballing the generated code, thanks. Back to fixing, I go :D

@bjoernQ bjoernQ enabled auto-merge February 10, 2025 09:40
@bjoernQ bjoernQ added this pull request to the merge queue Feb 10, 2025
Merged via the queue into main with commit 355dabd Feb 10, 2025
19 checks passed
@bugadani bugadani deleted the elif branch February 10, 2025 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants