Skip to content

Commit

Permalink
test: move transform check away from codegen tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix-ru committed Mar 4, 2024
1 parent 5673a03 commit aeecf3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 26 deletions.
16 changes: 8 additions & 8 deletions crates/fervid_codegen/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,18 +671,18 @@ mod tests {
// @click
test_out(
vec![AttributeOrBinding::VOn(VOnDirective {
event: Some("click".into()),
event: Some("onClick".into()),
handler: None,
modifiers: vec![],
span: DUMMY_SP,
})],
r"{onClick:()=>{}}",
);

// @multi-word-event
// @multi-word-event (gets transformed to `onMultiWordEvent`)
test_out(
vec![AttributeOrBinding::VOn(VOnDirective {
event: Some("multi-word-event".into()),
event: Some("onMultiWordEvent".into()),
handler: None,
modifiers: vec![],
span: DUMMY_SP,
Expand All @@ -692,7 +692,7 @@ mod tests {

// @click="handleClick"
test_out(
vec![v_on_attribute("click", "handleClick")],
vec![v_on_attribute("onClick", "handleClick")],
r"{onClick:handleClick}",
);

Expand All @@ -711,14 +711,14 @@ mod tests {

// @click="() => console.log('hello')"
test_out(
vec![v_on_attribute("click", "() => console.log('hello')")],
vec![v_on_attribute("onClick", "() => console.log('hello')")],
r#"{onClick:()=>console.log("hello")}"#,
);

// @click="$event => handleClick($event, foo, bar)"
test_out(
vec![v_on_attribute(
"click",
"onClick",
"$event => handleClick($event, foo, bar)",
)],
r"{onClick:$event=>handleClick($event,foo,bar)}",
Expand All @@ -727,7 +727,7 @@ mod tests {
// @click.stop.prevent.self
test_out(
vec![AttributeOrBinding::VOn(VOnDirective {
event: Some("click".into()),
event: Some("onClick".into()),
handler: None,
modifiers: vec!["stop".into(), "prevent".into(), "self".into()],
span: DUMMY_SP,
Expand All @@ -738,7 +738,7 @@ mod tests {
// @click.stop="$event => handleClick($event, foo, bar)"
test_out(
vec![AttributeOrBinding::VOn(VOnDirective {
event: Some("click".into()),
event: Some("onClick".into()),
handler: Some(js("$event => handleClick($event, foo, bar)")),
modifiers: vec!["stop".into()],
span: DUMMY_SP,
Expand Down
2 changes: 1 addition & 1 deletion crates/fervid_codegen/src/elements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ mod tests {
regular_attribute("foo", "bar"),
v_bind_attribute("baz", "qux"),
v_bind_attribute("readonly", "true"),
v_on_attribute("click", "handleClick"),
v_on_attribute("onClick", "handleClick"),
],
directives: None,
},
Expand Down
17 changes: 0 additions & 17 deletions crates/fervid_codegen/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,3 @@ pub fn to_camelcase(s: &str, buf: &mut impl Write) -> Result<(), Error> {

Ok(())
}

pub fn to_pascalcase(s: &str, buf: &mut impl Write) -> Result<(), Error> {
for word in s.split('-') {
let first_char = word.chars().next();
if let Some(ch) = first_char {
// Uppercase the first char and append to buf
for ch_component in ch.to_uppercase() {
buf.write_char(ch_component)?;
}

// Push the rest of the word
buf.write_str(&word[ch.len_utf8()..])?;
}
}

Ok(())
}
2 changes: 2 additions & 0 deletions crates/fervid_transform/src/template/v_on.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,7 @@ mod tests {
test!("update:modelValue", "on:update:modelValue");
test!("vue:update", "onVnodeUpdate");
test!("vue:updateFoo", "onVnodeUpdateFoo");
test!("click", "onClick");
test!("multi-word-event", "onMultiWordEvent");
}
}

0 comments on commit aeecf3a

Please sign in to comment.